Skip to content

Commit

Permalink
Storybook: Add stories for the TextAlignmentControl component (#67371)
Browse files Browse the repository at this point in the history
* Storybook: Add stories for the text-alignment-control component

* Storybook: Update TextAlignmentControl story to follow best practices and simplify the structure

* Storybook: Simplify TextAlignmentControl story

* Storybook: Simplify the documentation for TextAlignmentControl story

Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent 6291232 commit 67557ed
Showing 1 changed file with 55 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,69 @@ import { useState } from '@wordpress/element';
*/
import TextAlignmentControl from '../';

export default {
const meta = {
title: 'BlockEditor/TextAlignmentControl',
component: TextAlignmentControl,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component: 'Control to facilitate text alignment selections.',
},
},
},
argTypes: {
onChange: { action: 'onChange' },
className: { control: 'text' },
value: {
control: { type: null },
description: 'Currently selected text alignment value.',
table: {
type: {
summary: 'string',
},
},
},
onChange: {
action: 'onChange',
control: { type: null },
description: 'Handles change in text alignment selection.',
table: {
type: {
summary: 'function',
},
},
},
options: {
control: 'check',
description: 'Array of text alignment options to display.',
options: [ 'left', 'center', 'right', 'justify' ],
table: {
type: { summary: 'array' },
},
},
className: {
control: 'text',
description: 'Class name to add to the control.',
table: {
type: { summary: 'string' },
},
},
value: { control: false },
},
};

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

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

0 comments on commit 67557ed

Please sign in to comment.