Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN: Add Icon Button Block Editor component. #25204

Merged
merged 8 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import {
PanelBody,
BottomSheet,
FooterMessageControl,
IconButton,
} from '@wordpress/components';
import { Icon, close } from '@wordpress/icons';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
import MenuItem from '../inserter/menu-item';
import styles from './style.scss';

const hitSlop = { top: 22, bottom: 22, left: 22, right: 22 };
Expand Down Expand Up @@ -103,7 +103,7 @@ function BlockVariationPicker( { isVisible, onClose, clientId, variations } ) {
>
{ variations.map( ( v ) => {
return (
<MenuItem
<IconButton
item={ v }
key={ v.name }
onSelect={ () => onVariationSelect( v ) }
Expand Down
9 changes: 6 additions & 3 deletions packages/block-editor/src/components/inserter/menu.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import { Component } from '@wordpress/element';
import { createBlock, rawHandler } from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { withInstanceId, compose } from '@wordpress/compose';
import { BottomSheet, BottomSheetConsumer } from '@wordpress/components';
import {
BottomSheet,
BottomSheetConsumer,
IconButton,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import styles from './style.scss';
import MenuItem from './menu-item.native';

const MIN_COL_NUM = 3;

Expand Down Expand Up @@ -112,7 +115,7 @@ export class InserterMenu extends Component {
const { itemWidth, maxWidth } = this.state;
const { onSelect } = this.props;
return (
<MenuItem
<IconButton
item={ item }
itemWidth={ itemWidth }
maxWidth={ maxWidth }
Expand Down
66 changes: 5 additions & 61 deletions packages/block-editor/src/components/inserter/style.native.scss
Original file line number Diff line number Diff line change
@@ -1,63 +1,9 @@
/** @format */

.touchableArea {
border-radius: 8px 8px 8px 8px;
}

.rowSeparator {
height: 12px;
}

.modalItem {
flex-direction: column;
justify-content: flex-start;
align-items: center;
padding-left: $grid-unit-20 / 2;
padding-right: $grid-unit-20 / 2;
padding-top: 0;
padding-bottom: 0;
}

.modalIconWrapper {
width: 104px;
height: 64px;
background-color: $gray-light; //#f3f6f8
border-radius: 8px 8px 8px 8px;
justify-content: center;
align-items: center;
}

.modalIconWrapperDark {
background-color: rgba($white, 0.07);
}

.modalIcon {
width: 32px;
height: 32px;
justify-content: center;
align-items: center;
fill: $gray-dark;
}

.modalIconDark {
fill: $white;
}

.modalItemLabel {
background-color: transparent;
padding-left: 2;
padding-right: 2;
padding-top: 4;
padding-bottom: 0;
justify-content: center;
font-size: 12;
color: $gray-dark;
}

.modalItemLabelDark {
color: $white;
}

.addBlockButton {
color: $blue-wordpress;
}
Expand All @@ -70,12 +16,10 @@
padding: $grid-unit-20;
}

.clipboardBlock {
background-color: transparent;
border-width: 1px;
border-color: $light-gray-400;
.modalItem {
padding-left: $grid-unit-20 / 2;
padding-right: $grid-unit-20 / 2;
}

.clipboardBlockDark {
border-color: $gray-70;
.modalIconWrapper {
width: 104px;
}
2 changes: 1 addition & 1 deletion packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export { default as __experimentalToolbarContext } from './toolbar-context';
export { default as ToolbarGroup } from './toolbar-group';
export { default as ToolbarItem } from './toolbar-item';
export { default as Icon } from './icon';
export { default as IconButton } from './button/deprecated';
export { default as Spinner } from './spinner';
export {
createSlotFill,
Expand Down Expand Up @@ -76,6 +75,7 @@ export { default as ColorSettings } from './mobile/color-settings';
export { default as LinkSettings } from './mobile/link-settings';
export { default as Image, IMAGE_DEFAULT_FOCAL_POINT } from './mobile/image';
export { default as ImageEditingButton } from './mobile/image/image-editing-button';
export { default as IconButton } from './mobile/icon-button';

// Utils
export { colorsUtils } from './mobile/color-settings/utils';
Expand Down
55 changes: 55 additions & 0 deletions packages/components/src/mobile/icon-button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
IconButton
=============================

Proved the IconButton style button for the mobile editor used in the inserter.
enejb marked this conversation as resolved.
Show resolved Hide resolved

## Usage


```jsx
function render() {
return (
<View>
<Text>Some rendered content here</Text>
<IconButton item={ { title: "Short Text", icon: <SVG></SVG> } } onSelect={ function( item ) { console.log( 'selected' ); } } />
</View>
);
}
```

_Note:_

## Props

### `maxWidth`
* **Type:** `String`
* **Default:** `undefined`

The max-width of the button.

### `itemWidth`
* **Type:** `String`
* **Default:** `undefined`

The button width.

### `onSelect`
* **Type:** `Function`
* **Required** `true`

The function that is called once the IconButton has been selected.

### `item`
* **Type:** `Object`
* **Required** `true`

The object that gets selected.

## Examples

<IconButton
item={ item }
itemWidth={ itemWidth }
maxWidth={ maxWidth }
onSelect={ onSelect }
/>
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ class MenuItem extends Component {
);

const isClipboardBlock = item.id === 'clipboard';
const blockTitle = isClipboardBlock ? __( 'Copied block' ) : item.title;

return (
<TouchableHighlight
style={ styles.touchableArea }
underlayColor="transparent"
activeOpacity={ 0.5 }
accessibilityLabel={ item.title }
accessibilityLabel={ blockTitle }
onPress={ this.onPress }
>
<View style={ [ styles.modalItem, { width: maxWidth } ] }>
Expand All @@ -82,9 +83,7 @@ class MenuItem extends Component {
/>
</View>
</View>
<Text style={ modalItemLabelStyle }>
{ isClipboardBlock ? __( 'Copied block' ) : item.title }
</Text>
<Text style={ modalItemLabelStyle }>{ blockTitle }</Text>
</View>
</TouchableHighlight>
);
Expand Down
64 changes: 64 additions & 0 deletions packages/components/src/mobile/icon-button/style.native.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/** @format */
.touchableArea {
border-radius: 8px 8px 8px 8px;
}

.modalIconWrapper {
width: 104px;
height: 64px;
background-color: $gray-light; //#f3f6f8
border-radius: 8px 8px 8px 8px;
justify-content: center;
align-items: center;
}

.modalIconWrapperDark {
background-color: rgba($white, 0.07);
}

.modalIcon {
width: 32px;
height: 32px;
justify-content: center;
align-items: center;
fill: $gray-dark;
}

.modalIconDark {
fill: $white;
}

.modalItemLabel {
background-color: transparent;
padding-left: 2;
padding-right: 2;
padding-top: 4;
padding-bottom: 0;
justify-content: center;
font-size: 12;
color: $gray-dark;
}

.modalItemLabelDark {
color: $white;
}

.clipboardBlock {
background-color: transparent;
border-width: 1px;
border-color: $light-gray-400;
}

.clipboardBlockDark {
border-color: $gray-70;
}

.modalItem {
flex-direction: column;
justify-content: flex-start;
align-items: center;
padding-left: $grid-unit-20 / 2;
padding-right: $grid-unit-20 / 2;
padding-top: 0;
padding-bottom: 0;
}