Skip to content

Commit

Permalink
Add stories for BlockAlignmentControl and BlockAlignmentToolbar compo…
Browse files Browse the repository at this point in the history
…nents
  • Loading branch information
akasunil committed Nov 22, 2024
1 parent b4c614f commit 3e5554e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

/**
* The `BlockAlignmentToolbar` component is used to render block alignment options in the editor. The different alignment options it provides are `left`, `center`, `right`, `wide` and `full`.
*/
const meta = {
title: 'BlockEditor/BlockAlignmentToolbar',
component: BlockAlignmentToolbar,
argTypes: {
value: {
control: { type: null },
defaultValue: 'undefined',
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;

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

export const Default = Template.bind();
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

/**
* The `BlockAlignmentControl` component is used to render block alignment options in the editor. The different alignment options it provides are `left`, `center`, `right`, `wide` and `full`.
*
* If you want to use the block alignment control in a toolbar, you should use the `BlockAlignmentToolbar` component instead.
*/
const meta = {
title: 'BlockEditor/BlockAlignmentControl',
component: BlockAlignmentControl,
argTypes: {
value: {
control: { type: null },
defaultValue: 'undefined',
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;

const Template = ( { onChange, ...args } ) => {
const [ value, setValue ] = useState();
return (
<BlockAlignmentControl
{ ...args }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
value={ value }
/>
);
};

export const Default = Template.bind();

0 comments on commit 3e5554e

Please sign in to comment.