-
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 BlockCanvas Component #68589
Open
Rishit30G
wants to merge
2
commits into
WordPress:trunk
Choose a base branch
from
Rishit30G:feat/add-block-canvas-storybook
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/block-editor/src/components/block-canvas/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,59 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { BlockCanvas, BlockList } from '../..'; | ||
|
||
const meta = { | ||
title: 'BlockEditor/BlockCanvas', | ||
component: BlockCanvas, | ||
parameters: { | ||
docs: { | ||
canvas: { sourceState: 'shown' }, | ||
description: { | ||
component: | ||
'The BlockCanvas component is used to render the canvas for the block editor.', | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
children: { | ||
control: false, // Disable direct control for `children` as it defaults to `BlockList` | ||
description: 'The children to render in the canvas.', | ||
table: { | ||
type: { summary: 'node' }, | ||
defaultValue: { summary: 'BlockList' }, | ||
}, | ||
}, | ||
height: { | ||
control: 'text', | ||
description: 'The height of the canvas.', | ||
table: { | ||
type: { summary: 'string' }, | ||
defaultValue: { summary: '300px' }, | ||
}, | ||
}, | ||
styles: { | ||
control: 'object', | ||
description: 'The styles to apply to the canvas.', | ||
table: { | ||
type: { summary: 'object' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default = { | ||
args: { | ||
height: '300px', | ||
styles: { | ||
border: '1px solid #ccc', | ||
backgroundColor: '#f9f9f9', | ||
}, | ||
children: <BlockList />, // Default `children` is `BlockList` | ||
}, | ||
render: function Template( args ) { | ||
return <BlockCanvas { ...args } />; | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
styles
is an array of objects and the actual CSS is astring
. A basic example is the variable used in the playground stories.As for the type, I'm not sure how thoroughly it can/should be documented so maybe for now
Array
suffices. The full type would be something like:{ css?: string; assets?: string; isGlobalStyles?: boolean; __unstableType: string; }[]
. Example usage is here and you can see how it’s consumed inEditorStyles
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 sharing the feedback and resources @stokesman
Here is the updated code snippet:
meta
object:Default
object:Screenshot of the storybook
Let me know if this looks good, I'll update the PR accordingly 🙇🏻
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! The change to
Default
looks good to me.For the
styles
prop’s type summary, I'm not sure because I haven’t see guidance on how specific it should be. Most other examples I have seen are pretty generic. So perhaps justArray
, orArray<{}>
. If it’s better to fully specify the type then the last update you posted isn’t quite right—I’ll take some responsibility—and it should be:or alternatively using the
Array
generic:I’ll ping @WordPress/gutenberg-components and @t-hamano in case they know the guidance around this (and if not maybe we can establish it). One argument in favor of a more general type here would be easier maintenance I think 🤷♂️. It’s also notable
EditorStyles
is where the type is actually important as this component just passes it through.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.
Got it, thanks for sharing the updates and feedback! 🙇🏻
I have updated the PR ✅