Skip to content

Commit

Permalink
Storybook: Add stories for AlignmentToolbar and AlignmentControl comp…
Browse files Browse the repository at this point in the history
…onents (#67046)

* Add stories for AlignmentToolbar and AlignmentControl components

* Remove unneccesery args

* package.json: remove packageManager entry

* Rename the story file and remove unnecessary args from AlignmentControl story

* Update packages/block-editor/src/components/alignment-control/stories/aliginment-toolbar.story.js

Co-authored-by: Lena Morita <[email protected]>

* Add render function

---------

Co-authored-by: miminari <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mirka <[email protected]>
  • Loading branch information
4 people authored Nov 27, 2024
1 parent b20ac37 commit fedbea3
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,47 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

/**
* The `AlignmentToolbar` component renders a dropdown menu that displays alignment options for the selected block in `Toolbar`.
*/
const meta = {
title: 'BlockEditor/AlignmentToolbar',
component: AlignmentToolbar,
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`, `undefined`) as the only argument.",
},
},
};
export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState();
return (
<AlignmentToolbar
{ ...args }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
value={ value }
/>
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

/**
* The `AlignmentControl` component renders a dropdown menu that displays alignment options for the selected block.
*
* This component is mostly used for blocks that display text, such as Heading, Paragraph, Post Author, Post Comments, Verse, Quote, Post Title, etc... And the available alignment options are `left`, `center` or `right` alignment.
*
* If you want to use the alignment control in a toolbar, you should use the `AlignmentToolbar` component instead.
*/
const meta = {
title: 'BlockEditor/AlignmentControl',
component: AlignmentControl,
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`, `undefined`) as the only argument.",
},
},
};
export default meta;

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

1 comment on commit fedbea3

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in fedbea3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12059573563
📝 Reported issues:

Please sign in to comment.