diff --git a/packages/block-editor/src/components/inserter-draggable-blocks/stories/index.story.js b/packages/block-editor/src/components/inserter-draggable-blocks/stories/index.story.js new file mode 100644 index 00000000000000..1b87489de60568 --- /dev/null +++ b/packages/block-editor/src/components/inserter-draggable-blocks/stories/index.story.js @@ -0,0 +1,130 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { createBlock } from '@wordpress/blocks'; +import { registerCoreBlocks } from '@wordpress/block-library'; +import { paragraph, heading, image } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import InserterDraggableBlocks from '../'; +import { useState } from '@wordpress/element'; + +// Register core blocks to make them available for use +registerCoreBlocks(); + +const meta = { + title: 'BlockEditor/InserterDraggableBlocks', + component: InserterDraggableBlocks, + parameters: { + docs: { + description: { + component: + 'The `InserterDraggableBlocks` component allows users to drag and drop blocks from the inserter.', + }, + }, + }, + argTypes: { + isEnabled: { + description: 'Whether dragging is enabled for the component.', + control: 'boolean', + defaultValue: true, + }, + blocks: { + description: 'Array of blocks to make draggable.', + control: 'object', + defaultValue: undefined, + }, + + icon: { + control: 'select', + options: { + Paragraph: paragraph, + Heading: heading, + Image: image, + }, + default: 'undefined', + description: 'Optional icon for the draggable component.', + }, + + children: { + description: 'Render function for child elements.', + control: false, + }, + pattern: { + description: + 'Optional block pattern for the drag-and-drop functionality.', + control: 'object', + }, + }, +}; +export default meta; + +const Template = ( args ) => { + const [ dragged, setDragged ] = useState( false ); + + return ( +
+

{ __( 'Drag the blocks below:' ) }

+ { + return ( +
{ + onDragEnd( e ); + setDragged( true ); + } } + draggable={ draggable } + > +
{ `${ __( 'Number of Draggable blocks:' ) } ${ + args.blocks.length + }` }
+
+ { dragged + ? __( 'Blocks dragged!' ) + : __( + 'Drag me to test the functionality.' + ) } +
+
+ ); + } } + /> +
+ ); +}; + +export const Default = { + render: Template, + args: { + isEnabled: true, + blocks: [ + createBlock( 'core/paragraph', { + content: 'Draggable paragraph block', + } ), + createBlock( 'core/heading', { + content: 'Draggable heading block', + } ), + ], + icon: paragraph, + pattern: null, + }, +};