From 1f95de5c3be7b924a7e8a29520d985e405f290c3 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Tue, 26 Nov 2024 11:59:34 +0530 Subject: [PATCH] Storybook: Add HeadingLevelDropdown Stories --- .../stories/index.story.js | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 packages/block-editor/src/components/block-heading-level-dropdown/stories/index.story.js diff --git a/packages/block-editor/src/components/block-heading-level-dropdown/stories/index.story.js b/packages/block-editor/src/components/block-heading-level-dropdown/stories/index.story.js new file mode 100644 index 0000000000000..5e2bf678379b8 --- /dev/null +++ b/packages/block-editor/src/components/block-heading-level-dropdown/stories/index.story.js @@ -0,0 +1,94 @@ +/** + * WordPress dependencies + */ +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import HeadingLevelDropdown from '../'; + +export default { + title: 'BlockEditor/HeadingLevelDropdown', + component: HeadingLevelDropdown, + argTypes: { + value: { + control: { type: 'number', min: 0, max: 6, step: 1 }, + description: 'The currently selected heading level.', + }, + options: { + control: 'array', + description: + 'An array of supported heading levels, e.g., [1, 2, 3, 4, 5, 6].', + }, + onChange: { + action: 'onChange', + description: + 'Callback triggered when a new heading level is selected.', + }, + }, + decorators: [ + ( Story ) => ( +
+ +
+ ), + ], +}; + +const Template = ( args ) => { + const [ value, setValue ] = useState( args.value ); + + return ( + { + setValue( newLevel ); + args.onChange( newLevel ); + } } + /> + ); +}; + +export const Default = Template.bind( {} ); +Default.args = { + value: 2, + options: [ 1, 2, 3, 4, 5, 6 ], +}; + +export const WithParagraphOption = Template.bind( {} ); +WithParagraphOption.args = { + value: 0, + options: [ 0, 1, 2, 3, 4 ], +}; + +export const LimitedOptions = Template.bind( {} ); +LimitedOptions.args = { + value: 3, + options: [ 2, 3, 4 ], +}; + +export const StartingAsParagraph = Template.bind( {} ); +StartingAsParagraph.args = { + value: 0, + options: [ 0, 1, 2, 3 ], +}; + +export const InteractiveDropdown = () => { + const [ selectedLevel, setSelectedLevel ] = useState( 2 ); + + return ( +
+

+ Selected Level:{ ' ' } + { selectedLevel === 0 ? 'Paragraph' : `H${ selectedLevel }` } +

+ setSelectedLevel( newLevel ) } + /> +
+ ); +};