From 3e5554e10947130ece69a0ce9906742770ffe3c4 Mon Sep 17 00:00:00 2001 From: akasunil Date: Fri, 22 Nov 2024 18:04:53 +0530 Subject: [PATCH] Add stories for BlockAlignmentControl and BlockAlignmentToolbar components --- .../stories/block-alignment-toolbar.story.js | 48 ++++++++++++++++++ .../stories/index.story.js | 50 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 packages/block-editor/src/components/block-alignment-control/stories/block-alignment-toolbar.story.js create mode 100644 packages/block-editor/src/components/block-alignment-control/stories/index.story.js 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..f91e117cc991a5 --- /dev/null +++ b/packages/block-editor/src/components/block-alignment-control/stories/block-alignment-toolbar.story.js @@ -0,0 +1,48 @@ +/** + * 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, + 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; + +const Template = ( { onChange, ...args } ) => { + const [ value, setValue ] = useState(); + return ( + { + onChange( ...changeArgs ); + setValue( ...changeArgs ); + } } + value={ value } + /> + ); +}; + +export const Default = Template.bind(); 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..49c8ff4b99ec8f --- /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; + +const Template = ( { onChange, ...args } ) => { + const [ value, setValue ] = useState(); + return ( + { + onChange( ...changeArgs ); + setValue( ...changeArgs ); + } } + value={ value } + /> + ); +}; + +export const Default = Template.bind();