-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Update BlockMover Stories and README #66519
Update BlockMover Stories and README #66519
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thanks for improving our Block Editor stories!
I would like to use the automatic citation from the README to the Storybook, but it did not work
We currently don't have any systems to extract README data into Storybook. I think you're referring to how @wordpress/components
stories extract TypeScript/TSDoc data into Storybook 🙂 I don't think we'll be able to automate this part until Block Editor components are annotated with TypeScript.
packages/block-editor/src/components/block-mover/stories/index.story.tsx
Outdated
Show resolved
Hide resolved
); | ||
}; | ||
|
||
export const Default: StoryFn< typeof BlockMover > = Template.bind( {} ); |
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.
It might be nice to use CSF 3 format, since we're overhauling anyway.
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.
I just removed the types, is it OK?
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.
I do recommend it in this case, as we can eliminate a lot of unnecessary code.
The main points of this suggested diff being:
- The
Template
component is unnecessary because it's just the plain component, and we only use it once. Plus, the implementation is incorrect because theclientIds
prop cannot be overridden by the stories. - The
useEffect
in the Horizontal story can also be moved to a decorator. - The conditionals that check for
blocks.length
seem unnecessary because we are assigning theblocks
variable statically.
diff --git a/packages/block-editor/src/components/block-mover/stories/index.story.js b/packages/block-editor/src/components/block-mover/stories/index.story.js
index 97d8fce96a..241c62c878 100644
--- a/packages/block-editor/src/components/block-mover/stories/index.story.js
+++ b/packages/block-editor/src/components/block-mover/stories/index.story.js
@@ -31,29 +31,6 @@ const blocks = [
] ),
];
-function BlockMoverStoryHorizontal() {
- const { updateBlockListSettings } = useDispatch( blockEditorStore );
-
- useEffect( () => {
- /**
- * This shouldn't be needed but unfortunately
- * the layout orientation is not declarative, we need
- * to render the blocks to update the block settings in the state.
- */
- updateBlockListSettings( blocks[ 1 ].clientId, {
- orientation: 'horizontal',
- } );
- }, [] );
-
- return (
- <BlockMover
- clientIds={
- blocks.length ? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ] : []
- }
- />
- );
-}
-
/**
* BlockMover component allows moving blocks inside the editor using up and down buttons.
*/
@@ -89,55 +66,49 @@ const meta = {
};
export default meta;
-const Template = ( props ) => {
- return (
- <BlockMover
- { ...props }
- clientIds={
- blocks.length ? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ] : []
- }
- />
- );
-};
-
-export const Default = Template.bind( {} );
-Default.args = {
- clientIds: [
- blocks.length ? [ blocks[ 0 ].innerBlocks[ 1 ].clientId ] : [],
- ],
+export const Default = {
+ args: {
+ clientIds: [ blocks[ 0 ].innerBlocks[ 1 ].clientId ],
+ },
};
/**
* This story shows the block mover with horizontal orientation.
* It is necessary to render the blocks to update the block settings in the state.
*/
-export const Horizontal = ( props ) => {
- return <BlockMoverStoryHorizontal { ...props } />;
-};
-Horizontal.args = {
- clientIds: [
- blocks.length ? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ] : [],
+export const Horizontal = {
+ decorators: [
+ ( Story ) => {
+ const { updateBlockListSettings } = useDispatch( blockEditorStore );
+
+ useEffect( () => {
+ /**
+ * This shouldn't be needed but unfortunately
+ * the layout orientation is not declarative, we need
+ * to render the blocks to update the block settings in the state.
+ */
+ updateBlockListSettings( blocks[ 1 ].clientId, {
+ orientation: 'horizontal',
+ } );
+ }, [] );
+
+ return <Story />;
+ },
],
-};
-Horizontal.parameters = {
- docs: { canvas: { sourceState: 'hidden' } },
+ args: {
+ clientIds: [ blocks[ 1 ].innerBlocks[ 1 ].clientId ],
+ },
+ parameters: {
+ docs: { canvas: { sourceState: 'hidden' } },
+ },
};
/**
* You can hide the drag handle by `hideDragHandle` attribute.
*/
-export const HideDragHandle = ( props ) => {
- return (
- <BlockMover
- { ...props }
- clientIds={
- blocks.length ? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ] : []
- }
- hideDragHandle
- />
- );
-};
-HideDragHandle.args = {
- ...Default.args,
- hideDragHandle: true,
+export const HideDragHandle = {
+ args: {
+ ...Default.args,
+ hideDragHandle: true,
+ },
};
packages/block-editor/src/components/block-mover/stories/index.story.tsx
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/block-mover/stories/index.story.tsx
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/block-mover/stories/index.story.tsx
Outdated
Show resolved
Hide resolved
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.
Thanks for the PR!
Each story is working as expected, but I think one thing we need to address is making the hideDragHandle
prop controllable:
672766caf0147a73c5f9aa049172bbf2.mp4
We'll probably need to run updateBlockListSettings
in response to changes in the control.
Co-authored-by: Aki Hamano <[email protected]>
….story.tsx Co-authored-by: Lena Morita <[email protected]>
I see, thanks for letting me know. I think I updated all. Could you please review again? |
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.
I suggested some additional cleanup and bug fixes in #66519 (comment), but all the other tweaks look good!
clientIds: [ | ||
blocks.length ? [ blocks[ 0 ].innerBlocks[ 1 ].clientId ] : [], | ||
], |
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.
Noting that this would result in a nested array, not a flat one as it should be. (These are also fixed in the suggested diff in #66519 (comment))
clientIds={ | ||
blocks.length ? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ] : [] | ||
} | ||
hideDragHandle |
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.
Noting that these hardcoded props would override any of the prop values passed from args
or the Storybook controls.
@mirka I appreciate you taking the time to tell me. One point, I was wondering if we should pass the clientIds directly for the Horizontal story because BlockMover can't be rendered horizontally view by passing clientIds via args. |
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.
Thanks for the update.
Finally, in order for the "Horizontal" story to work properly (to get the hideDragHandle
controls to work), it looks like the following changes are necessary:
diff --git a/packages/block-editor/src/components/block-mover/stories/index.story.js b/packages/block-editor/src/components/block-mover/stories/index.story.js
index 5b2fdd4ee6..fd56a4cded 100644
--- a/packages/block-editor/src/components/block-mover/stories/index.story.js
+++ b/packages/block-editor/src/components/block-mover/stories/index.story.js
@@ -80,7 +80,7 @@ export const Default = {
*/
export const Horizontal = {
decorators: [
- () => {
+ ( Story ) => {
const { updateBlockListSettings } = useDispatch( blockEditorStore );
useEffect( () => {
/**
@@ -92,13 +92,12 @@ export const Horizontal = {
orientation: 'horizontal',
} );
}, [] );
- return (
- <BlockMover
- clientIds={ [ blocks[ 1 ].innerBlocks[ 1 ].clientId ] }
- />
- );
+ return <Story />;
},
],
+ args: {
+ clientIds: [ blocks[ 1 ].innerBlocks[ 1 ].clientId ],
+ },
parameters: {
docs: { canvas: { sourceState: 'hidden' } },
},
packages/block-editor/src/components/block-mover/stories/index.story.js
Outdated
Show resolved
Hide resolved
….story.js Co-authored-by: Aki Hamano <[email protected]>
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.
LGTM!
What?
Update the BlockMover component's Storybook and README
Why?
I feel Block Editor components's Storybook should also be updated.
We should also have all component's stories, but I started to update the component having stories.
related #22891
How?
Almost Component's stories already have been updated, and use Storybook 7's features.
I changed the Stories based on them, and added and changed the minimum README.
And, I would like to use the automatic citation from the README to the Storybook, but it did not work...
Testing Instructions
npm run storybook:dev
and check the BlockMover stories.Testing Instructions for Keyboard
Screenshots or screencast