Skip to content

Commit

Permalink
Update block-canvas component with BlockToolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishit30G committed Feb 11, 2025
1 parent 7179821 commit fcfabd9
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import { registerCoreBlocks } from '@wordpress/block-library';
/**
* Internal dependencies
*/
import { BlockCanvas, BlockEditorProvider } from '../..';

registerCoreBlocks();
import {
BlockCanvas,
BlockEditorProvider,
BlockToolbar,
} from '@wordpress/block-editor';

const meta = {
title: 'BlockEditor/BlockCanvas',
Expand All @@ -22,6 +21,26 @@ const meta = {
},
},
},
decorators: [
( Story ) => {
const [ blocks, updateBlocks ] = useState( [] );

useEffect( () => {
registerCoreBlocks();
}, [] );

return (
<BlockEditorProvider
value={ blocks }
onInput={ ( newBlocks ) => updateBlocks( newBlocks ) }
onChange={ ( newBlocks ) => updateBlocks( newBlocks ) }
>
<BlockToolbar hideDragHandle />
<Story />
</BlockEditorProvider>
);
},
],
argTypes: {
children: {
control: false,
Expand All @@ -43,10 +62,7 @@ const meta = {
control: 'object',
description: 'The styles to apply to the canvas.',
table: {
type: {
summary:
'{ css?: string; assets?: string; isGlobalStyles?: boolean; __unstableType: string; }[]',
},
type: { summary: 'Array' },
},
},
},
Expand All @@ -55,17 +71,5 @@ const meta = {
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>
);
},
render: ( args ) => <BlockCanvas { ...args } />,
};

0 comments on commit fcfabd9

Please sign in to comment.