-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storybook: Add stories for BlockInspector component.
- Loading branch information
1 parent
5af740f
commit ece5667
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/block-editor/src/components/block-inspector/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,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> | ||
), | ||
], | ||
}; |