'use client';
import * as React from 'react';
import { Plate, usePlateEditor } from 'platejs/react';
import { EditorKit } from '@/components/editor/editor-kit';
import { Editor, EditorContainer } from '@/components/ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = usePlateEditor({
plugins: EditorKit,
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
Features
- Flexible Block Indentation: Transform any block type (paragraphs, headings, etc.) into list items through indentation.
- Simplified Structure: Flat DOM structure where each indented block is independent, unlike List Classic plugin.
- List Types: Support for bulleted lists (unordered) and numbered lists (ordered).
- Markdown Shortcuts: Combined with autoformat plugin, use markdown shortcuts (
-
,*
,1.
) to create lists.
For more information about the underlying indentation system, see the Indent plugin.
Kit Usage
Installation
The fastest way to add list functionality is with the ListKit
, which includes pre-configured ListPlugin
along with the required Indent plugin targeting paragraph, heading, blockquote, code block, and toggle elements.
'use client';
import { ListPlugin } from '@platejs/list/react';
import { KEYS } from 'platejs';
import { IndentKit } from '@/components/editor/plugins/indent-kit';
import { BlockList } from '@/components/ui/block-list';
export const ListKit = [
...IndentKit,
ListPlugin.configure({
inject: {
targetPlugins: [
...KEYS.heading,
KEYS.p,
KEYS.blockquote,
KEYS.codeBlock,
KEYS.toggle,
],
},
render: {
belowNodes: BlockList,
},
}),
];
BlockList
: Renders list wrapper elements with support for todo lists.- Includes
IndentKit
for the underlying indentation system. - Configures
Paragraph
,Heading
,Blockquote
,CodeBlock
, andToggle
elements to support list functionality.
Add Kit
Add the kit to your plugins:
import { createPlateEditor } from 'platejs/react';
import { ListKit } from '@/components/editor/plugins/list-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...ListKit,
],
});
Add Toolbar Button
You can add ListToolbarButton
to your Toolbar to create and manage lists.
Turn Into Toolbar Button
You can add these items to the Turn Into Toolbar Button to convert blocks into lists:
{
icon: <ListIcon />,
label: 'Bulleted list',
value: KEYS.ul,
}
{
icon: <ListOrderedIcon />,
label: 'Numbered list',
value: KEYS.ol,
}
{
icon: <SquareIcon />,
label: 'To-do list',
value: KEYS.listTodo,
}
Manual Usage
Installation
pnpm add @platejs/list @platejs/indent
Add Plugins
Include both IndentPlugin
and ListPlugin
in your Plate plugins array when creating the editor. The List plugin depends on the Indent plugin.
import { IndentPlugin } from '@platejs/indent/react';
import { ListPlugin } from '@platejs/list/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin,
ListPlugin,
],
});
Configure Plugins
You can configure both plugins to target specific elements and customize list behavior.
import { IndentPlugin } from '@platejs/indent/react';
import { ListPlugin } from '@platejs/list/react';
import { KEYS } from 'platejs';
import { createPlateEditor } from 'platejs/react';
import { BlockList } from '@/components/ui/block-list';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin.configure({
inject: {
targetPlugins: [...KEYS.heading, KEYS.p, KEYS.blockquote, KEYS.codeBlock],
},
}),
ListPlugin.configure({
inject: {
targetPlugins: [...KEYS.heading, KEYS.p, KEYS.blockquote, KEYS.codeBlock],
},
render: {
belowNodes: BlockList,
},
}),
],
});
inject.targetPlugins
: An array of plugin keys indicating which element types can become list items.render.belowNodes
: AssignsBlockList
to render list wrapper elements.
Plugins
ListPlugin
Plugin for creating and managing lists. It works with the Indent plugin to provide flexible list functionality where any block can be transformed into a list item through indentation.
API
getNextList
Gets the next sibling entry with an indent list.
getPreviousList
Gets the previous sibling entry with an indent list.
indentList
Increases the indentation of the selected blocks.
outdentList
Decreases the indentation of the selected blocks.
someList
Checks if some of the selected blocks have a specific list style type.
toggleList
Toggles the indent list.
Types
GetSiblingListOptions
Used to provide options for getting the sibling indent list in a block of text.
This function is used to get the previous sibling entry from a given entry.
This function is used to get the next sibling entry from a given entry.
This function is used to validate a sibling node during the lookup process. If it returns false, the next sibling is checked.
Indicates whether to break the lookup when the sibling node has an indent level equal to the current node. If true, the lookup stops when a sibling node with the same indent level is found.
A function that takes a TNode
and returns a boolean value or undefined.
This function is used to specify a condition under which the lookup process
should be stopped.
Indicates whether to break the lookup when a sibling node with a lower indent level is found. If true, the lookup stops when a sibling node with a lower indent level is found.
Indicates whether to break the lookup when a sibling node with the same indent level but a different list style type is found. If true, the lookup stops when such a sibling node is found.
Hooks
useListToolbarButton
A behavior hook for the indent list toolbar button.