From ae327b22d6c1fd563290fbc304ea977b1f71480e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Fri, 29 Nov 2019 10:08:18 +0100 Subject: [PATCH] Block Library: Update Columns block to use Patterns API (#18283) * Block library: Refactor Columns block to use Patterns API * Blocks: Add support for the default block pattern * Components: Add size prop to the IconButton component * Change the behavior of the selector which returns the default block pattern * Block editor: Extract BLockPatternPicker component * Abstract columns picker selection with __experimentalBlockPatternPicker * Use Icon component to unify the way icons are handled --- .../components/block-pattern-picker/index.js | 67 ++++++ .../block-pattern-picker/style.scss | 74 +++++++ packages/block-editor/src/components/index.js | 1 + .../src/components/inner-blocks/README.md | 63 ------ .../src/components/inner-blocks/index.js | 25 +-- .../components/inner-blocks/index.native.js | 18 +- .../src/components/inner-blocks/style.scss | 75 ------- .../inner-blocks/template-picker.js | 67 ------ packages/block-editor/src/style.scss | 1 + packages/block-library/src/columns/edit.js | 198 ++++++++---------- packages/block-library/src/columns/index.js | 2 + .../block-library/src/columns/patterns.js | 63 ++++++ .../block-library/src/columns/test/utils.js | 20 -- packages/block-library/src/columns/utils.js | 18 +- packages/blocks/src/store/selectors.js | 29 ++- packages/blocks/src/store/test/selectors.js | 78 ++++++- packages/components/src/icon-button/index.js | 5 +- .../src/icon-button/stories/index.js | 4 +- packages/components/src/placeholder/index.js | 5 +- .../components/src/placeholder/test/index.js | 6 +- 20 files changed, 419 insertions(+), 400 deletions(-) create mode 100644 packages/block-editor/src/components/block-pattern-picker/index.js create mode 100644 packages/block-editor/src/components/block-pattern-picker/style.scss delete mode 100644 packages/block-editor/src/components/inner-blocks/template-picker.js create mode 100644 packages/block-library/src/columns/patterns.js diff --git a/packages/block-editor/src/components/block-pattern-picker/index.js b/packages/block-editor/src/components/block-pattern-picker/index.js new file mode 100644 index 0000000000000..3b2b0a1c05383 --- /dev/null +++ b/packages/block-editor/src/components/block-pattern-picker/index.js @@ -0,0 +1,67 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Button, IconButton, Placeholder } from '@wordpress/components'; + +function BlockPatternPicker( { + icon = 'layout', + label = __( 'Choose pattern' ), + instructions = __( 'Select a pattern to start with.' ), + patterns, + onSelect, + allowSkip, +} ) { + const classes = classnames( 'block-editor-block-pattern-picker', { + 'has-many-patterns': patterns.length > 4, + } ); + + return ( + + { + /* + * Disable reason: The `list` ARIA role is redundant but + * Safari+VoiceOver won't announce the list otherwise. + */ + /* eslint-disable jsx-a11y/no-redundant-roles */ + } + + { /* eslint-enable jsx-a11y/no-redundant-roles */ } + { allowSkip && ( +
+ +
+ ) } +
+ ); +} + +export default BlockPatternPicker; diff --git a/packages/block-editor/src/components/block-pattern-picker/style.scss b/packages/block-editor/src/components/block-pattern-picker/style.scss new file mode 100644 index 0000000000000..ac92faea0848a --- /dev/null +++ b/packages/block-editor/src/components/block-pattern-picker/style.scss @@ -0,0 +1,74 @@ +.block-editor-block-pattern-picker { + .components-placeholder__instructions { + // Defer to vertical margins applied by template picker options. + margin-bottom: 0; + } + + .components-placeholder__fieldset { + // Options will render horizontally, but the immediate children of the + // fieldset are the options and the skip button, oriented vertically. + flex-direction: column; + } + + &.has-many-patterns .components-placeholder__fieldset { + // Allow options to occupy a greater amount of the available space if + // many options exist. + max-width: 90%; + } +} + +.block-editor-block-pattern-picker__patterns.block-editor-block-pattern-picker__patterns { + display: flex; + justify-content: center; + flex-direction: row; + flex-wrap: wrap; + width: 100%; + margin: $grid-size-small 0; + list-style: none; + + > li { + list-style: none; + margin: $grid-size; + flex-shrink: 1; + max-width: 100px; + } + + .block-editor-block-pattern-picker__pattern { + padding: $grid-size; + } +} + +.block-editor-block-pattern-picker__pattern { + width: 100%; + + &.components-icon-button { + // Override default styles inherited from to center + // icon horizontally. + justify-content: center; + + &.is-default { + background-color: $white; + } + } + + &.components-button { + // Override default styles inherited from