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

Storybook: Add UnitControl story #67346

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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,124 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import UnitControl from '../';

const meta = {
title: 'BlockEditor/UnitControl',
component: UnitControl,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'UnitControl allows the user to set a numeric quantity as well as a unit.',
},
},
},
argTypes: {
onChange: {
action: 'onChange',
description: 'Callback function when the value changes.',
table: {
type: { summary: 'function' },
},
},
onUnitChange: {
action: 'onUnitChange',
description: 'Callback function when the unit changes.',
table: {
type: { summary: 'function' },
},
},
labelPosition: {
control: 'radio',
options: [ 'top', 'side', 'bottom', 'edge' ],
description: 'The position of the label.',
table: {
type: { summary: 'string' },
},
},
label: {
control: 'text',
description: 'The label for the control.',
table: {
type: { summary: 'string' },
},
},
value: {
control: { type: null },
description: 'The value of the control.',
table: {
type: { summary: 'string' },
},
},
size: {
control: 'radio',
options: [ 'default', 'small' ],
description: 'The size of the control.',
table: {
type: { summary: 'string' },
defaultValue: { summary: 'default' },
},
},
disabled: {
control: 'boolean',
description: 'Whether the control is disabled.',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: false },
},
},
disabledUnits: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
disabledUnits: {
disableUnits: {

Sorry, I made a mistake with the prop name 😅 It would be nice if we could fix this together too.

control: 'boolean',
description: 'If true, the unit select is hidden.',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: false },
},
},
isPressEnterToChange: {
control: 'boolean',
description:
'If true, the ENTER key press is required to trigger onChange. Change is also triggered on blur.',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: false },
},
},
isUnitSelectTabbable: {
control: 'boolean',
description: 'Determines if the unit select is tabbable.',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: true },
},
},
},
};

export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState();
return (
<UnitControl
{ ...args }
value={ value }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
/>
);
},
args: {
label: 'Label',
},
};
Loading