diff --git a/packages/block-editor/src/components/block-alignment-control/README.md b/packages/block-editor/src/components/block-alignment-control/README.md index 22b5df9af9bd42..2d0de8df44b784 100644 --- a/packages/block-editor/src/components/block-alignment-control/README.md +++ b/packages/block-editor/src/components/block-alignment-control/README.md @@ -38,6 +38,24 @@ The current value of the alignment setting. You may only choose from the `Option A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie: `left`, `center`, `right`, `wide`, `full`) as the only argument. +### `controls` + +- **Type:** `Array` +- **Default:** + +```js +[ 'none', 'left', 'center', 'right', 'wide', 'full' ]; +``` + +An array of available alignment controls. + +### `isCollapsed` + +- **Type:** `Boolean` +- **Default:** `true` + +Whether the toolbar should be collapsed. Default is true. + ## Related components Block Editor components are components that can be used to compose the UI of your block editor. Thus, they can only be used under a [`BlockEditorProvider`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/provider/README.md) in the components tree. diff --git a/packages/block-editor/src/components/block-alignment-control/stories/block-alignment-toolbar.story.js b/packages/block-editor/src/components/block-alignment-control/stories/block-alignment-toolbar.story.js new file mode 100644 index 00000000000000..f31be4368a5f27 --- /dev/null +++ b/packages/block-editor/src/components/block-alignment-control/stories/block-alignment-toolbar.story.js @@ -0,0 +1,58 @@ +/** + * WordPress dependencies + */ +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import { BlockAlignmentToolbar } from '../'; + +/** + * The `BlockAlignmentToolbar` component is used to render block alignment options in the editor. The different alignment options it provides are `left`, `center`, `right`, `wide` and `full`. + */ +const meta = { + title: 'BlockEditor/BlockAlignmentToolbar', + component: BlockAlignmentToolbar, + parameters: { + docs: { canvas: { sourceState: 'shown' } }, + }, + argTypes: { + value: { + control: { type: null }, + description: 'The current value of the alignment setting.', + }, + onChange: { + action: 'onChange', + control: { type: null }, + description: + "A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie:`left`, `center`, `right`, `wide`, and `full`) as the only argument.", + }, + controls: { + control: { type: null }, + description: 'An array of available alignment controls.', + }, + isCollapsed: { + control: { type: null }, + description: 'Whether the toolbar should be collapsed.', + }, + }, +}; + +export default meta; + +export const Default = { + render: function Template( { onChange, ...args } ) { + const [ value, setValue ] = useState(); + return ( + { + onChange( ...changeArgs ); + setValue( ...changeArgs ); + } } + value={ value } + /> + ); + }, +}; diff --git a/packages/block-editor/src/components/block-alignment-control/stories/index.story.js b/packages/block-editor/src/components/block-alignment-control/stories/index.story.js new file mode 100644 index 00000000000000..f10400290415b9 --- /dev/null +++ b/packages/block-editor/src/components/block-alignment-control/stories/index.story.js @@ -0,0 +1,50 @@ +/** + * WordPress dependencies + */ +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import { BlockAlignmentControl } from '../'; + +/** + * The `BlockAlignmentControl` component is used to render block alignment options in the editor. The different alignment options it provides are `left`, `center`, `right`, `wide` and `full`. + * + * If you want to use the block alignment control in a toolbar, you should use the `BlockAlignmentToolbar` component instead. + */ +const meta = { + title: 'BlockEditor/BlockAlignmentControl', + component: BlockAlignmentControl, + argTypes: { + value: { + control: { type: null }, + defaultValue: 'undefined', + description: 'The current value of the alignment setting.', + }, + onChange: { + action: 'onChange', + control: { type: null }, + description: + "A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie:`left`, `center`, `right`, `wide`, and `full`) as the only argument.", + }, + }, +}; + +export default meta; + +export const Default = { + render: function Template( { onChange, ...args } ) { + const [ value, setValue ] = useState(); + return ( + { + onChange( ...changeArgs ); + setValue( ...changeArgs ); + } } + value={ value } + /> + ); + }, +};