forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
910c38f
commit da9cedf
Showing
1 changed file
with
136 additions
and
0 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
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,136 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import UnitControl from '../'; | ||
|
||
const CUSTOM_UNITS = [ | ||
{ value: 'px', label: 'px', default: 0 }, | ||
{ value: 'em', label: 'em', default: 0 }, | ||
{ value: 'rem', label: 'rem', default: 0 }, | ||
]; | ||
|
||
/** | ||
* UnitControl Properties | ||
*/ | ||
export default { | ||
title: 'BlockEditor/UnitControl', | ||
component: UnitControl, | ||
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: 'select', | ||
options: [ 'top', 'side', 'bottom' ], | ||
description: 'The position of the label.', | ||
table: { | ||
type: { summary: 'string' }, | ||
defaultValue: { summary: 'top' }, | ||
}, | ||
}, | ||
label: { | ||
control: 'text', | ||
description: 'The label for the control.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
value: { | ||
control: 'text', | ||
description: 'The value of the control.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
size: { | ||
control: 'select', | ||
options: [ 'small', 'medium' ], | ||
description: 'The size of the control.', | ||
table: { | ||
type: { summary: 'string' }, | ||
defaultValue: { summary: 'medium' }, | ||
}, | ||
}, | ||
disabled: { | ||
control: 'boolean', | ||
description: 'Whether the control is disabled.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: false }, | ||
}, | ||
}, | ||
}, | ||
render: function Render( { onChange, onUnitChange, value, ...args } ) { | ||
const [ componentValue, setComponentValue ] = useState( value || '' ); | ||
|
||
useEffect( () => { | ||
setComponentValue( value ); | ||
}, [ value ] ); | ||
|
||
const handleValueChange = ( newValue ) => { | ||
setComponentValue( newValue ); | ||
if ( onChange ) { | ||
onChange( newValue ); | ||
} | ||
}; | ||
|
||
return ( | ||
<UnitControl | ||
{ ...args } | ||
value={ componentValue } | ||
onChange={ handleValueChange } | ||
onUnitChange={ onUnitChange } | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
/** | ||
* Story demonstrating UnitControl with default settings | ||
*/ | ||
export const Default = { | ||
args: { | ||
label: 'Default Unit Control', | ||
value: '10', | ||
size: 'medium', | ||
labelPosition: 'top', | ||
}, | ||
}; | ||
|
||
/** | ||
* Story demonstrating UnitControl with custom units | ||
*/ | ||
export const CustomUnits = { | ||
args: { | ||
...Default.args, | ||
label: 'Custom Units', | ||
units: CUSTOM_UNITS, | ||
}, | ||
}; | ||
|
||
/** | ||
* Story demonstrating UnitControl in disabled state | ||
*/ | ||
export const Disabled = { | ||
args: { | ||
...Default.args, | ||
label: 'Disabled Unit Control', | ||
disabled: true, | ||
}, | ||
}; |