forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
124 additions
and
0 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
packages/block-editor/src/components/unit-control/stories/index.story.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}, | ||
}, | ||
disableUnits: { | ||
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', | ||
}, | ||
}; |