-
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.
- Loading branch information
1 parent
e5dca54
commit 8d42503
Showing
1 changed file
with
175 additions
and
0 deletions.
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
packages/block-editor/src/components/inner-blocks/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,175 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
useBlockProps, | ||
store as blockEditorStore, | ||
BlockEditorProvider, | ||
} from '@wordpress/block-editor'; | ||
import { SlotFillProvider } from '@wordpress/components'; | ||
import { createRegistry, RegistryProvider } from '@wordpress/data'; | ||
import { store as blocksStore } from '@wordpress/blocks'; | ||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; | ||
import { store as preferencesStore } from '@wordpress/preferences'; | ||
import { store as interfaceStore } from '@wordpress/interface'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InnerBlocks, { useInnerBlocksProps } from '../'; | ||
|
||
const registry = createRegistry(); | ||
|
||
// Register all required stores | ||
[ | ||
blockEditorStore, | ||
blocksStore, | ||
keyboardShortcutsStore, | ||
interfaceStore, | ||
preferencesStore, | ||
].forEach( ( store ) => registry.register( store ) ); | ||
|
||
registry.dispatch( blockEditorStore ).updateSettings( { | ||
hasFixedToolbar: true, | ||
focusMode: false, | ||
hasInlineToolbar: false, | ||
} ); | ||
|
||
const meta = { | ||
title: 'BlockEditor/InnerBlocks', | ||
component: InnerBlocks, | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: | ||
'InnerBlocks is a component which allows a single block to have multiple blocks as children.', | ||
}, | ||
canvas: { sourceState: 'shown' }, | ||
}, | ||
layout: 'centered', | ||
}, | ||
argTypes: { | ||
allowedBlocks: { | ||
control: 'object', | ||
description: | ||
'Array of allowed block types or true/false for all/none', | ||
table: { | ||
type: { summary: 'Array<String> | Boolean' }, | ||
defaultValue: { summary: 'true' }, | ||
}, | ||
}, | ||
template: { | ||
control: 'object', | ||
description: 'Template for initial blocks', | ||
table: { | ||
type: { summary: 'Array<Array>' }, | ||
}, | ||
}, | ||
templateLock: { | ||
control: 'select', | ||
options: [ false, 'all', 'insert', 'contentOnly' ], | ||
description: 'Lock level for the template', | ||
table: { | ||
type: { summary: 'String | Boolean' }, | ||
}, | ||
}, | ||
orientation: { | ||
control: 'select', | ||
options: [ 'horizontal', 'vertical', 'none' ], | ||
description: 'Orientation of inner blocks', | ||
table: { | ||
type: { summary: 'String' }, | ||
defaultValue: { summary: 'vertical' }, | ||
}, | ||
}, | ||
renderAppender: { | ||
control: 'select', | ||
options: [ 'default', 'button', 'none' ], | ||
description: 'Type of appender to render', | ||
mapping: { | ||
default: undefined, | ||
button: InnerBlocks.ButtonBlockAppender, | ||
none: false, | ||
}, | ||
}, | ||
}, | ||
decorators: [ | ||
( Story ) => ( | ||
<RegistryProvider value={ registry }> | ||
<SlotFillProvider> | ||
<BlockEditorProvider | ||
value={ [] } | ||
settings={ { | ||
hasFixedToolbar: true, | ||
templateLock: false, | ||
} } | ||
onInput={ () => {} } | ||
onChange={ () => {} } | ||
> | ||
<div | ||
style={ { | ||
maxWidth: '720px', | ||
margin: '20px auto', | ||
minHeight: '150px', | ||
} } | ||
> | ||
<Story /> | ||
</div> | ||
</BlockEditorProvider> | ||
</SlotFillProvider> | ||
</RegistryProvider> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
const InnerBlocksWrapper = ( { ...props } ) => { | ||
const blockProps = useBlockProps(); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, props ); | ||
return <div { ...innerBlocksProps } />; | ||
}; | ||
|
||
export const Default = { | ||
args: {}, | ||
render: ( args ) => <InnerBlocksWrapper { ...args } />, | ||
}; | ||
|
||
export const WithAllowedBlocks = { | ||
args: { | ||
allowedBlocks: [ 'core/paragraph', 'core/image' ], | ||
}, | ||
render: ( args ) => <InnerBlocksWrapper { ...args } />, | ||
}; | ||
|
||
export const WithTemplate = { | ||
args: { | ||
template: [ [ 'core/paragraph', { placeholder: 'Add content...' } ] ], | ||
}, | ||
render: ( args ) => <InnerBlocksWrapper { ...args } />, | ||
}; | ||
|
||
export const WithTemplateLock = { | ||
args: { | ||
template: [ | ||
[ 'core/paragraph', { placeholder: 'Locked content...' } ], | ||
], | ||
templateLock: 'all', | ||
}, | ||
render: ( args ) => <InnerBlocksWrapper { ...args } />, | ||
}; | ||
|
||
export const HorizontalOrientation = { | ||
args: { | ||
orientation: 'horizontal', | ||
allowedBlocks: [ 'core/paragraph', 'core/image' ], | ||
}, | ||
render: ( args ) => <InnerBlocksWrapper { ...args } />, | ||
}; | ||
|
||
export const WithButtonAppender = { | ||
args: { | ||
renderAppender: InnerBlocks.ButtonBlockAppender, | ||
}, | ||
render: ( args ) => <InnerBlocksWrapper { ...args } />, | ||
}; |