-
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 3 commits
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,90 @@ | ||||||||||
/** | ||||||||||
* 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: null }, | ||||||||||
}, | ||||||||||
parameters: { | ||||||||||
actions: { argTypesRegex: '^on.*' }, | ||||||||||
controls: { expanded: true }, | ||||||||||
docs: { canvas: { sourceState: 'shown' } }, | ||||||||||
}, | ||||||||||
}; | ||||||||||
export default meta; | ||||||||||
|
||||||||||
const defaultSideValues = { | ||||||||||
top: '10px', | ||||||||||
right: '10px', | ||||||||||
bottom: '10px', | ||||||||||
left: '10px', | ||||||||||
}; | ||||||||||
|
||||||||||
const TemplateUncontrolled: StoryFn< typeof BoxControl > = ( props ) => { | ||||||||||
return <BoxControl { ...props } />; | ||||||||||
}; | ||||||||||
|
||||||||||
const TemplateControlled: StoryFn< typeof BoxControl > = ( props ) => { | ||||||||||
const [ values, setValues ] = | ||||||||||
useState< ( typeof props )[ 'values' ] >( 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. While testing that the For example, interacting with After looking into this, I realised that this is happening because we're initializing the component always with the same Prior to these changes, each example had its own specific default value, which prevented this issue from manifesting. An easy fix for now is to avoid passing any default values
Suggested change
Definitely not in the scope of this PR, although I wonder if the component should somehow "validate" the incoming value, and compare it against the |
||||||||||
|
||||||||||
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, | ||||||||||
}; |
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 } }