Skip to content
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

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 20 additions & 60 deletions packages/components/src/color-picker/stories/index.js
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
*/
Expand All @@ -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' },
Comment on lines +20 to +22
Copy link
Contributor

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)!

},
};

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Member Author

Choose a reason for hiding this comment

The 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( {} );