From 5d86605316cc339cb8f15264a3fdf395f935618f Mon Sep 17 00:00:00 2001 From: Brooke <35543432+brookewp@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:14:23 -0800 Subject: [PATCH] `BoxControl`: Update story and refactor to Typescript (#56462) * BoxControl: Update story and refactor to Typescript * Cleanup and refine story based on feedback * Add Uncontrolled and Controlled templates and Controlled example * Remove default values and fix values control --- .../src/box-control/stories/index.story.js | 75 ----------------- .../src/box-control/stories/index.story.tsx | 82 +++++++++++++++++++ 2 files changed, 82 insertions(+), 75 deletions(-) delete mode 100644 packages/components/src/box-control/stories/index.story.js create mode 100644 packages/components/src/box-control/stories/index.story.tsx diff --git a/packages/components/src/box-control/stories/index.story.js b/packages/components/src/box-control/stories/index.story.js deleted file mode 100644 index adbd0e15f7c44..0000000000000 --- a/packages/components/src/box-control/stories/index.story.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * WordPress dependencies - */ -import { useState } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import BoxControl from '../'; - -export default { - title: 'Components (Experimental)/BoxControl', - component: BoxControl, -}; - -export const _default = () => { - return ; -}; - -const defaultSideValues = { - top: '10px', - right: '10px', - bottom: '10px', - left: '10px', -}; - -function DemoExample( { - sides, - defaultValues = defaultSideValues, - splitOnAxis = false, -} ) { - const [ values, setValues ] = useState( defaultValues ); - - return ( - - ); -} - -export const ArbitrarySides = () => { - return ( - - ); -}; - -export const SingleSide = () => { - return ( - - ); -}; - -export const AxialControls = () => { - return ; -}; - -export const AxialControlsWithSingleSide = () => { - return ( - - ); -}; diff --git a/packages/components/src/box-control/stories/index.story.tsx b/packages/components/src/box-control/stories/index.story.tsx new file mode 100644 index 0000000000000..1b6604048f6d5 --- /dev/null +++ b/packages/components/src/box-control/stories/index.story.tsx @@ -0,0 +1,82 @@ +/** + * External dependencies + */ +import type { Meta, StoryFn } from '@storybook/react'; + +/** + * WordPress dependencies + */ +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import BoxControl from '../'; + +const meta: Meta< typeof BoxControl > = { + title: 'Components (Experimental)/BoxControl', + component: BoxControl, + argTypes: { + values: { control: { type: null } }, + }, + parameters: { + actions: { argTypesRegex: '^on.*' }, + controls: { expanded: true }, + docs: { canvas: { sourceState: 'shown' } }, + }, +}; +export default meta; + +const TemplateUncontrolled: StoryFn< typeof BoxControl > = ( props ) => { + return ; +}; + +const TemplateControlled: StoryFn< typeof BoxControl > = ( props ) => { + const [ values, setValues ] = useState< ( typeof props )[ 'values' ] >(); + + return ( + { + setValues( nextValue ); + props.onChange?.( nextValue ); + } } + /> + ); +}; + +export const Default = TemplateUncontrolled.bind( {} ); +Default.args = { + label: 'Label', +}; + +export const Controlled = TemplateControlled.bind( {} ); +Controlled.args = { + ...Default.args, +}; + +export const ArbitrarySides = TemplateControlled.bind( {} ); +ArbitrarySides.args = { + ...Default.args, + sides: [ 'top', 'bottom' ], +}; + +export const SingleSide = TemplateControlled.bind( {} ); +SingleSide.args = { + ...Default.args, + sides: [ 'bottom' ], +}; + +export const AxialControls = TemplateControlled.bind( {} ); +AxialControls.args = { + ...Default.args, + splitOnAxis: true, +}; + +export const AxialControlsWithSingleSide = TemplateControlled.bind( {} ); +AxialControlsWithSingleSide.args = { + ...Default.args, + sides: [ 'horizontal' ], + splitOnAxis: true, +};