-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ColorPicker: Remove knobs in stories #46772
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { boolean, select } from '@storybook/addon-knobs'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -12,70 +7,35 @@ import { useState } from '@wordpress/element'; | |
* Internal dependencies | ||
*/ | ||
import { ColorPicker } from '..'; | ||
import { Flex } from '../../flex'; | ||
import { Spacer } from '../../spacer'; | ||
import { space } from '../../ui/utils/space'; | ||
|
||
export default { | ||
component: ColorPicker, | ||
title: 'Components/ColorPicker', | ||
parameters: { | ||
knobs: { disable: false }, | ||
argTypes: { | ||
color: { control: { type: null } }, | ||
copyFormat: { | ||
control: { type: 'select' }, | ||
options: [ 'rgb', 'hsl', 'hex', undefined ], | ||
}, | ||
// We can't use a `on*` regex because this component will switch to | ||
// legacy mode when an onChangeComplete prop is passed. | ||
onChange: { action: 'onChange' }, | ||
}, | ||
}; | ||
|
||
const PROP_UNSET = 'unset'; | ||
|
||
const Example = () => { | ||
const [ color, setColor ] = useState( undefined ); | ||
const props = { | ||
enableAlpha: boolean( 'enableAlpha', false ), | ||
copyFormat: select( | ||
'copyFormat', | ||
[ PROP_UNSET, 'rgb', 'hsl', 'hex' ], | ||
PROP_UNSET | ||
), | ||
}; | ||
|
||
if ( props.copyFormat === PROP_UNSET ) { | ||
delete props.copyFormat; | ||
} | ||
|
||
return ( | ||
<Flex | ||
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. I honestly don't remember why we had put two pickers side-by-side 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. I have to assume it was to demonstrate that the values are synced over properly? 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. I guess! |
||
as={ Spacer } | ||
gap={ space( 2 ) } | ||
justify="space-around" | ||
align="flex-start" | ||
marginTop={ space( 10 ) } | ||
> | ||
<ColorPicker { ...props } color={ color } onChange={ setColor } /> | ||
<div style={ { width: 200, textAlign: 'center' } }>{ color }</div> | ||
<ColorPicker { ...props } color={ color } onChange={ setColor } /> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export const _default = () => { | ||
return <Example />; | ||
}; | ||
|
||
const LegacyExample = () => { | ||
const [ legacyColor, setLegacyColor ] = useState( '#fff' ); | ||
const legacyProps = { | ||
color: legacyColor, | ||
onChangeComplete: setLegacyColor, | ||
disableAlpha: boolean( 'disableAlpha', true ), | ||
}; | ||
Comment on lines
-63
to
-69
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. Removing the legacy example because this is/should be covered in the automated tests. |
||
const Template = ( { onChange, ...props } ) => { | ||
const [ color, setColor ] = useState(); | ||
|
||
return ( | ||
<Flex align="flex-start" justify="flex-start"> | ||
<ColorPicker { ...legacyProps } /> | ||
<pre style={ { width: '20em' } }> | ||
{ JSON.stringify( legacyColor, undefined, 4 ) } | ||
</pre> | ||
</Flex> | ||
<ColorPicker | ||
{ ...props } | ||
color={ color } | ||
onChange={ ( ...changeArgs ) => { | ||
onChange( ...changeArgs ); | ||
setColor( ...changeArgs ); | ||
} } | ||
/> | ||
); | ||
}; | ||
|
||
export const legacy = () => <LegacyExample />; | ||
export const Default = Template.bind( {} ); |
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.
Nice catch (and interesting nuance)!