forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BoxControl
: Update story and refactor to Typescript (WordPress#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
- Loading branch information
Showing
2 changed files
with
82 additions
and
75 deletions.
There are no files selected for viewing
75 changes: 0 additions & 75 deletions
75
packages/components/src/box-control/stories/index.story.js
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
packages/components/src/box-control/stories/index.story.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <BoxControl { ...props } />; | ||
}; | ||
|
||
const TemplateControlled: StoryFn< typeof BoxControl > = ( props ) => { | ||
const [ values, setValues ] = useState< ( typeof props )[ 'values' ] >(); | ||
|
||
return ( | ||
<BoxControl | ||
values={ values } | ||
{ ...props } | ||
onChange={ ( nextValue ) => { | ||
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, | ||
}; |