-
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
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/block-editor/src/components/inserter-draggable-blocks/README.md
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,74 @@ | ||
# InserterDraggableBlocks | ||
|
||
The `InserterDraggableBlocks` component provides functionality to make WordPress blocks or patterns draggable within the editor environment. This component leverages the `Draggable` component from `@wordpress/components` and allows customization of drag-and-drop behavior through props. | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { InserterDraggableBlocks } from '@wordpress/block-editor'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
|
||
const blocks = [ | ||
createBlock( 'core/paragraph', { content: 'This is a paragraph block.' } ), | ||
createBlock( 'core/heading', { | ||
content: 'This is a heading block.', | ||
level: 2, | ||
} ), | ||
]; | ||
|
||
const MyComponent = () => { | ||
return ( | ||
<InserterDraggableBlocks | ||
isEnabled={ true } | ||
blocks={ blocks } | ||
icon={ <span>Drag</span> } | ||
children={ ( { draggable, onDragStart, onDragEnd } ) => ( | ||
<div | ||
draggable={ draggable } | ||
onDragStart={ onDragStart } | ||
onDragEnd={ onDragEnd } | ||
> | ||
Drag Me! | ||
</div> | ||
) } | ||
/> | ||
); | ||
}; | ||
``` | ||
|
||
## Props | ||
|
||
### `isEnabled` | ||
|
||
- **Type:** `boolean` | ||
- **Default:** `false` | ||
|
||
Whether dragging is enabled. | ||
|
||
### `blocks` | ||
|
||
- **Type:** `Array` | ||
- **Default:** `[]` | ||
|
||
Array of blocks to make draggable. | ||
|
||
### `icon` | ||
|
||
- **Type:** `ReactNode` | ||
- **Default:** `null` | ||
|
||
Icon for the draggable chip. | ||
|
||
### `children` | ||
|
||
- **Type:** `Function` | ||
- **Default:** `null` | ||
|
||
Render function for child elements. Receives draggable props (`draggable`, `onDragStart`, `onDragEnd`). | ||
|
||
### `pattern` | ||
|
||
- **Type:** `Object` | ||
- **Default:** `null` | ||
|
||
Optional block pattern for drag-and-drop. Should include `type`, `syncStatus`, and `id` attributes. |
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