Skip to content
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
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { registerCoreBlocks } from '@wordpress/block-library';
/**
* Internal dependencies
*/
import { BlockCanvas, BlockEditorProvider } from '../..';

registerCoreBlocks();

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,
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:
'{ css?: string; assets?: string; isGlobalStyles?: boolean; __unstableType: string; }[]',
},
},
},
},
};

export default meta;

export const Default = {
render: function Template( args ) {
const [ blocks, updateBlocks ] = useState( [] );

return (
<BlockEditorProvider
value={ blocks }
onInput={ ( newBlocks ) => updateBlocks( newBlocks ) }
onChange={ ( newBlocks ) => updateBlocks( newBlocks ) }
>
<BlockCanvas { ...args } />
</BlockEditorProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the provider seems necessary yet I believe it would be considered more appropriate to do so by way of a decorator in order to keep the story itself focused on BlockCanvas. For example, how it was done is in the PR for the BlockTitle story.

);
},
};
Loading