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 stories for BlockAlignmentControl and BlockAlignmentToolbar components #67233

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ The current value of the alignment setting. You may only choose from the `Option

A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie: `left`, `center`, `right`, `wide`, `full`) as the only argument.

### `controls`

- **Type:** `Array`
- **Default:** [ `none`, `left`, `center`, `right`, `wide`, `full` ]

An array of available alignment controls.

### `isCollapsed`

- **Type:** `Boolean`
- **Default:** `true`

Whether the toolbar should be collapsed. Default is true.

## Related components

Block Editor components are components that can be used to compose the UI of your block editor. Thus, they can only be used under a [`BlockEditorProvider`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/provider/README.md) in the components tree.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

export default {
title: 'BlockEditor/BlockAlignmentToolbar',
component: BlockAlignmentToolbar,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'A control for selecting block alignment options in the toolbar. The different alignment options it provides are `left`, `center`, `right`, `wide` and `full`',
},
},
},
argTypes: {
value: {
control: { type: null },
description: 'The current value of the alignment setting.',
},
onChange: {
action: 'onChange',
control: { type: null },
description:
"A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie:`left`, `center`, `right`, `wide`, and `full`) as the only argument.",
},
controls: {
control: { type: null },
description: 'An array of available alignment controls.',
},
isCollapsed: {
control: 'boolean',
description: 'Whether the toolbar should be collapsed.',
},
},
};

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

Default.args = {
defaultValue: 'undefined',
panelId: 'panel-id',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

const meta = {
title: 'BlockEditor/BlockAlignmentControl',
component: BlockAlignmentControl,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'A control for selecting block alignment options in the editor. The different alignment options it provides are `left`, `center`, `right`, `wide` and `full`',
},
},
},
argTypes: {
value: {
control: { type: null },
defaultValue: 'undefined',
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultValue is deprecated so let's remove it. It should not affect behavior.

description: 'The current value of the alignment setting.',
},
onChange: {
action: 'onChange',
control: { type: null },
description:
"A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie:`left`, `center`, `right`, `wide`, and `full`) as the only argument.",
},
},
};

export default meta;

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