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

DuotonePicker/DuotoneSwatch: Add stories #43225

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { DuotonePicker } from '../';

export default {
title: 'Components/DuotonePicker',
component: DuotonePicker,
argTypes: {
clearable: { control: { type: 'boolean' } },
onChange: { action: 'onChange' },
unsetable: { control: { type: 'boolean' } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a curious propname, wonder why this was preferred over more standard prop names like readonly or disabled 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it's the prop that dictates whether to add this Unset option in the options:

The Unset option in the DuotonePicker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed it 😅

},
parameters: {
controls: { expanded: true },
docs: { source: { state: 'open' } },
},
};

const DUOTONE_PALETTE = [
{
colors: [ '#8c00b7', '#fcff41' ],
name: 'Purple and yellow',
slug: 'purple-yellow',
},
{
colors: [ '#000097', '#ff4747' ],
name: 'Blue and red',
slug: 'blue-red',
},
];

const COLOR_PALETTE = [
{ color: '#ff4747', name: 'Red', slug: 'red' },
{ color: '#fcff41', name: 'Yellow', slug: 'yellow' },
{ color: '#000097', name: 'Blue', slug: 'blue' },
{ color: '#8c00b7', name: 'Purple', slug: 'purple' },
];

const Template = ( { onChange, ...args } ) => {
const [ value, setValue ] = useState();

return (
<DuotonePicker
{ ...args }
onChange={ ( ...changeArgs ) => {
setValue( ...changeArgs );
onChange( ...changeArgs );
} }
value={ value }
/>
);
};

export const Default = Template.bind( {} );
Default.args = {
colorPalette: COLOR_PALETTE,
duotonePalette: DUOTONE_PALETTE,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Internal dependencies
*/
import { DuotoneSwatch } from '../';

export default {
title: 'Components/DuotoneSwatch',
component: DuotoneSwatch,
parameters: {
controls: { expanded: true },
docs: { source: { state: 'open' } },
},
};

const Template = ( args ) => {
return <DuotoneSwatch { ...args } />;
};

export const Default = Template.bind( {} );
Default.args = {
values: [ '#000', '#fff' ],
};

export const SingleColor = Template.bind( {} );
SingleColor.args = {
values: [ 'pink' ],
};

export const Null = Template.bind( {} );
Null.args = {
values: null,
};