Skip to content

Commit

Permalink
Storybook: Add stories for BlockInspector component.
Browse files Browse the repository at this point in the history
  • Loading branch information
SainathPoojary committed Dec 27, 2024
1 parent 5af740f commit ece5667
Showing 1 changed file with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* WordPress dependencies
*/
import { registerCoreBlocks } from '@wordpress/block-library';
import { createBlock } from '@wordpress/blocks';
import { useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { ExperimentalBlockEditorProvider } from '../../provider';
import BlockInspector from '../';

registerCoreBlocks();

const blocks = [ createBlock( 'core/paragraph' ) ];

const BlockSelector = ( { children, clientId } ) => {
const { selectBlock } = useDispatch( blockEditorStore );

useEffect( () => {
if ( clientId ) {
selectBlock( clientId );
}
}, [ clientId, selectBlock ] );

return children;
};

const meta = {
title: 'BlockEditor/BlockInspector',
component: BlockInspector,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'The Block inspector is one of the panels that is displayed in the editor; it is mainly used to view and modify the settings of the selected block.',
},
},
},
decorators: [
( Story ) => (
<ExperimentalBlockEditorProvider value={ blocks }>
<Story />
</ExperimentalBlockEditorProvider>
),
],
argTypes: {
showNoBlockSelectedMessage: {
control: 'boolean',
description:
'Determines whether the Block Inspector displays a "No block selected" message or not when no block is selected.',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'true' },
},
},
},
};

export default meta;

export const Default = {};

export const WithSelectedBlock = {
decorators: [
( Story ) => (
<ExperimentalBlockEditorProvider value={ blocks }>
<BlockSelector clientId={ blocks[ 0 ].clientId }>
<Story />
</BlockSelector>
</ExperimentalBlockEditorProvider>
),
],
};

0 comments on commit ece5667

Please sign in to comment.