-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BoxControl
: Update story and refactor to Typescript
#56462
Changes from 1 commit
fbcc931
881e973
219c1f5
8b6ba7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,76 @@ | ||||||
/** | ||||||
* External dependencies | ||||||
*/ | ||||||
import type { Meta, StoryFn } from '@storybook/react'; | ||||||
|
||||||
/** | ||||||
* WordPress dependencies | ||||||
*/ | ||||||
import { useState } from '@wordpress/element'; | ||||||
|
||||||
/** | ||||||
* Internal dependencies | ||||||
*/ | ||||||
import BoxControl from '../'; | ||||||
import type { BoxControlValue } from '../types'; | ||||||
|
||||||
const meta: Meta< typeof BoxControl > = { | ||||||
title: 'Components (Experimental)/BoxControl', | ||||||
component: BoxControl, | ||||||
argTypes: { | ||||||
onChange: { action: 'onChange' }, | ||||||
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}, | ||||||
parameters: { | ||||||
controls: { expanded: true }, | ||||||
docs: { canvas: { sourceState: 'shown' } }, | ||||||
}, | ||||||
}; | ||||||
export default meta; | ||||||
|
||||||
const defaultSideValues = { | ||||||
top: '10px', | ||||||
right: '10px', | ||||||
bottom: '10px', | ||||||
left: '10px', | ||||||
}; | ||||||
|
||||||
const Template: StoryFn< typeof BoxControl > = ( props ) => { | ||||||
const [ values, setValues ] = | ||||||
useState< BoxControlValue >( defaultSideValues ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting! I tried There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On the other hand, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expanding on this, an alternative version is also to grab the type of the props by using the
I'm ok with keeping |
||||||
|
||||||
return ( | ||||||
<BoxControl | ||||||
label="Padding" | ||||||
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
values={ values } | ||||||
{ ...props } | ||||||
onChange={ ( nextValue ) => setValues( nextValue ) } | ||||||
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/> | ||||||
); | ||||||
}; | ||||||
|
||||||
export const Default = Template.bind( {} ); | ||||||
Default.args = { | ||||||
label: 'Box Control', | ||||||
values: undefined, | ||||||
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; | ||||||
|
||||||
export const ArbitrarySides = Template.bind( {} ); | ||||||
ArbitrarySides.args = { | ||||||
sides: [ 'top', 'bottom' ], | ||||||
}; | ||||||
|
||||||
export const SingleSide = Template.bind( {} ); | ||||||
SingleSide.args = { | ||||||
sides: [ 'bottom' ], | ||||||
}; | ||||||
|
||||||
export const AxialControls = Template.bind( {} ); | ||||||
AxialControls.args = { | ||||||
splitOnAxis: true, | ||||||
}; | ||||||
|
||||||
export const AxialControlsWithSingleSide = Template.bind( {} ); | ||||||
AxialControlsWithSingleSide.args = { | ||||||
sides: [ 'horizontal' ], | ||||||
splitOnAxis: true, | ||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the example Template below controls the
BoxControl
by passing it thevalue
prop, we should disable controls for thevalue
propThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The controls for the
values
prop are still enabledI believe that the right setting is
values: { control: { type: null } }