-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storybook: Add stories for the editable-text component
- Loading branch information
1 parent
c3ca59b
commit 7ccd739
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
packages/block-editor/src/components/editable-text/stories/index.story.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..." | ||
/> | ||
); | ||
}, | ||
}; |