Skip to content

Commit

Permalink
Storybook: Add stories for the editable-text component
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshupathak95 committed Dec 24, 2024
1 parent c3ca59b commit 7ccd739
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import EditableText from '../';

const meta = {
title: 'BlockEditor/EditableText',
component: EditableText,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'Renders an editable text input in which text formatting is not allowed.',
},
},
},
argTypes: {
value: {
control: { type: null },
description: 'Text content to make editable.',
table: {
type: { summary: 'string' },
},
},
onChange: {
action: 'onChange',
control: { type: null },
description: 'Called when the text content changes.',
table: {
type: { summary: 'function' },
},
},
tagName: {
control: 'text',
description: 'The HTML tag name of the editable element.',
table: {
type: { summary: 'string' },
defaultValue: { summary: 'div' },
},
},
placeholder: {
control: 'text',
description: 'Placeholder text to show when the field is empty.',
table: {
type: { summary: 'string' },
},
},
disableLineBreaks: {
control: 'boolean',
description: 'Prevents insertion of line breaks on Enter.',
table: {
type: { summary: 'boolean' },
},
},
},
};

export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState( '' );
return (
<EditableText
{ ...args }
value={ value }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
placeholder="Type some text..."
/>
);
},
};

0 comments on commit 7ccd739

Please sign in to comment.