'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 indent functionality is with the IndentKit
, which includes pre-configured IndentPlugin
targeting paragraph, heading, blockquote, code block, and toggle elements.
'use client';
import { IndentPlugin } from '@platejs/indent/react';
import { KEYS } from 'platejs';
export const IndentKit = [
IndentPlugin.configure({
inject: {
targetPlugins: [
...KEYS.heading,
KEYS.p,
KEYS.blockquote,
KEYS.codeBlock,
KEYS.toggle,
],
},
options: {
offset: 24,
},
}),
];
- Configures
Paragraph
,Heading
,Blockquote
,CodeBlock
, andToggle
elements to support theindent
property. - Sets a custom offset of
24px
for indentation spacing. - Provides Tab/Shift+Tab keyboard shortcuts for indenting and outdenting.
Add Kit
Add the kit to your plugins:
import { createPlateEditor } from 'platejs/react';
import { IndentKit } from '@/components/editor/plugins/indent-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...IndentKit,
],
});
Manual Usage
Installation
pnpm add @platejs/indent
Add Plugin
Include IndentPlugin
in your Plate plugins array when creating the editor.
import { IndentPlugin } from '@platejs/indent/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin,
],
});
Configure Plugin
You can configure the IndentPlugin
to target specific elements and customize indentation behavior.
import { IndentPlugin } from '@platejs/indent/react';
import { KEYS } from 'platejs';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin.configure({
inject: {
nodeProps: {
styleKey: 'marginLeft',
},
targetPlugins: [...KEYS.heading, KEYS.p, KEYS.blockquote],
},
options: {
offset: 24,
unit: 'px',
indentMax: 10,
},
}),
],
});
inject.nodeProps.styleKey
: Maps the injected prop to the CSSmarginLeft
property.inject.targetPlugins
: An array of plugin keys indicating which element types can be indented.options.offset
: Indentation offset in pixels (default:24
).options.unit
: Unit for indentation values (default:'px'
).options.indentMax
: Maximum number of indentations allowed.
Add Toolbar Button
You can add IndentToolbarButton
to your Toolbar to control indentation.
Plugins
IndentPlugin
Plugin for indenting block elements. It injects an indent
prop into the elements specified by inject.targetPlugins
and applies marginLeft
styling.
- Default:
'indent'
- Default:
'marginLeft'
- Default:
['p']
- Default:
24
- Default:
'px'
The property name injected into target elements.
CSS property name for styling.
Array of plugin keys to target for indent injection.
Indentation offset used in (offset * element.indent) + unit
.
Indentation unit used in (offset * element.indent) + unit
.
Maximum number of indentations allowed.
API
indent
Indents the selected block(s) in the editor.
outdent
Decrease the indentation of the selected blocks.
setIndent
Add offset to the indentation of the selected blocks.
Types
SetIndentOptions
Used to provide options for setting the indentation of a block of text.
Hooks
useIndentButton
A behavior hook for the indent button component.
useOutdentButton
A behavior hook for the outdent button component.