-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storybook: Add stories for BlockAlignmentControl and BlockAlignmentToolbar components #67233
base: trunk
Are you sure you want to change the base?
Changes from all commits
3e5554e
14ae57f
4e48acb
1bb38e6
93c499a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,58 @@ | ||||||
/** | ||||||
* 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`. | ||||||
*/ | ||||||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this comment to |
||||||
const meta = { | ||||||
title: 'BlockEditor/BlockAlignmentToolbar', | ||||||
component: BlockAlignmentToolbar, | ||||||
t-hamano marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
parameters: { | ||||||
docs: { canvas: { sourceState: 'shown' } }, | ||||||
}, | ||||||
argTypes: { | ||||||
value: { | ||||||
control: { type: null }, | ||||||
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.", | ||||||
}, | ||||||
controls: { | ||||||
control: { type: null }, | ||||||
description: 'An array of available alignment controls.', | ||||||
}, | ||||||
isCollapsed: { | ||||||
control: { type: null }, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's make this parameter controllable. aef25885501c2a0fed0ba5ef131b7d98.mp4 |
||||||
description: 'Whether the toolbar should be collapsed.', | ||||||
}, | ||||||
}, | ||||||
}; | ||||||
|
||||||
export default meta; | ||||||
|
||||||
export const Default = { | ||||||
render: function Template( { onChange, ...args } ) { | ||||||
const [ value, setValue ] = useState(); | ||||||
return ( | ||||||
<BlockAlignmentToolbar | ||||||
{ ...args } | ||||||
onChange={ ( ...changeArgs ) => { | ||||||
onChange( ...changeArgs ); | ||||||
setValue( ...changeArgs ); | ||||||
} } | ||||||
value={ value } | ||||||
/> | ||||||
); | ||||||
}, | ||||||
}; |
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. | ||
*/ | ||
Comment on lines
+11
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this comment to |
||
const meta = { | ||
title: 'BlockEditor/BlockAlignmentControl', | ||
component: BlockAlignmentControl, | ||
argTypes: { | ||
value: { | ||
control: { type: null }, | ||
defaultValue: 'undefined', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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; | ||
|
||
export const Default = { | ||
render: function Template( { onChange, ...args } ) { | ||
const [ value, setValue ] = useState(); | ||
return ( | ||
<BlockAlignmentControl | ||
{ ...args } | ||
onChange={ ( ...changeArgs ) => { | ||
onChange( ...changeArgs ); | ||
setValue( ...changeArgs ); | ||
} } | ||
value={ value } | ||
/> | ||
); | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.