'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>
);
}
Kit Usage
Installation
The fastest way to add toggle functionality is with the ToggleKit
, which includes pre-configured TogglePlugin
with indent support and their Plate UI components.
'use client';
import { TogglePlugin } from '@platejs/toggle/react';
import { IndentKit } from '@/components/editor/plugins/indent-kit';
import { ToggleElement } from '@/components/ui/toggle-node';
export const ToggleKit = [
...IndentKit,
TogglePlugin.withComponent(ToggleElement),
];
IndentKit
: Provides indent support for toggle elements.ToggleElement
: Renders toggle elements.
Add Kit
Add the kit to your plugins:
import { createPlateEditor } from 'platejs/react';
import { ToggleKit } from '@/components/editor/plugins/toggle-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...ToggleKit,
],
});
Manual Usage
Installation
pnpm add @platejs/indent @platejs/toggle
Add Plugins
Include TogglePlugin
and IndentPlugin
in your Plate plugins array when creating the editor.
import { IndentPlugin } from '@platejs/indent/react';
import { TogglePlugin } from '@platejs/toggle/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin,
TogglePlugin,
],
});
Configure Plugins
Configure the IndentPlugin
and TogglePlugin
with proper targeting and component assignment.
import { IndentPlugin } from '@platejs/indent/react';
import { TogglePlugin } from '@platejs/toggle/react';
import { createPlateEditor } from 'platejs/react';
import { ToggleElement } from '@/components/ui/toggle-node';
import { KEYS } from 'platejs';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin.configure({
inject: {
targetPlugins: [...KEYS.heading, KEYS.p, KEYS.toggle],
},
}),
TogglePlugin.withComponent(ToggleElement),
],
});
withComponent
: AssignsToggleElement
to render toggle elements.IndentPlugin.inject.targetPlugins
: Configures which element types support indentation, including toggles.
Add Toolbar Button
You can add ToggleToolbarButton
to your Toolbar to insert toggle elements.
Turn Into Toolbar Button
You can add this item to the Turn Into Toolbar Button to convert blocks into toggles:
{
icon: <ChevronRightIcon />,
label: 'Toggle list',
value: KEYS.toggle,
}
Insert Toolbar Button
You can add this item to the Insert Toolbar Button to insert toggle elements:
{
icon: <ChevronRightIcon />,
label: 'Toggle list',
value: KEYS.toggle,
}
Plugins
TogglePlugin
Plugin for managing toggle functionality.
API
api.toggle.toggleIds
Toggles the open state of specified toggles.
openNextToggles
Mark block at current selection as open toggle.
Hooks
useToggleToolbarButtonState
Hook for getting toggle toolbar button state.
useToggleToolbarButton
Hook for handling toggle toolbar button behavior.
useToggleButtonState
Hook for getting toggle button state.
useToggleButton
Hook for handling toggle button behavior.
On This Page
FeaturesKit UsageInstallationAdd KitManual UsageInstallationAdd PluginsConfigure PluginsAdd Toolbar ButtonTurn Into Toolbar ButtonInsert Toolbar ButtonPluginsTogglePluginAPIapi.toggle.toggleIdsopenNextTogglesHooksuseToggleToolbarButtonStateuseToggleToolbarButtonuseToggleButtonStateuseToggleButton