Skip to content

Commit

Permalink
UnitControl: Fixed documentation for units attribute (#31901)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsmio authored Jun 2, 2021
1 parent 4793303 commit b61a2d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/components/src/unit-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,23 @@ Collection of available units.
Example:

```jsx
import { __experimentalUnitControl as UnitControl } from '@wordpress/block-editor/';
import { __experimentalUnitControl as UnitControl } from '@wordpress/components';
import { useState } from '@wordpress/element';

const Example = () => {
const [ value, setValue ] = useState( '10px' );

const units = [
{ value: 'px', label: 'px', default: 0 },
{ value: '%', label: '%', default: 10 },
{ value: 'em', label: 'em', default: 0 },
];

return <UnitControl onChange={ setValue } value={ value } />;
return <UnitControl onChange={ setValue } value={ value } units={units} />;
};
```

A `default` value for (in the example above, `10` for `%`), if defined, is set as the new `value` when a unit changes. This is helpful in scenarios where changing a unit may cause drastic results, such as changing from `px` to `vh`.
A `default` value (in the example above, `10` for `%`), if defined, is set as the new `value` when a unit changes. This is helpful in scenarios where changing a unit may cause drastic results, such as changing from `px` to `vh`.

### value

Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/unit-control/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { boolean, number, select, text } from '@storybook/addon-knobs';
import { boolean, number, select, text, object } from '@storybook/addon-knobs';
import styled from '@emotion/styled';

/**
Expand All @@ -13,6 +13,7 @@ import { useState } from '@wordpress/element';
* Internal dependencies
*/
import UnitControl from '../';
import { CSS_UNITS } from '../utils';

export default {
title: 'Components/UnitControl',
Expand Down Expand Up @@ -41,6 +42,7 @@ function Example() {
'default'
),
step: number( 'step', 1 ),
units: object( 'units', CSS_UNITS ),
};

return (
Expand Down

0 comments on commit b61a2d8

Please sign in to comment.