Indent

Loading...
Files
components/demo.tsx
'use client';

import React from 'react';

import { Plate } from '@udecode/plate/react';

import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';

import { DEMO_VALUES } from './values/demo-values';

export default function Demo({ id }: { id: string }) {
  const editor = useCreateEditor({
    plugins: [...editorPlugins],
    value: DEMO_VALUES[id],
  });

  return (
    <Plate editor={editor}>
      <EditorContainer variant="demo">
        <Editor />
      </EditorContainer>
    </Plate>
  );
}

Features

  • Core Functionality:

    • Indent/outdent any block element
    • Tab/Shift+Tab keyboard shortcuts
    • Clean DOM structure
  • Customization:

    • Define target block types
    • Set indentation size and units
    • Control maximum depth
    • Custom CSS styling

For list-specific features, see the Indent List plugin.

Installation

npm install @udecode/plate-indent

Usage

import { IndentPlugin } from '@udecode/plate-indent/react';
import { HEADING_KEYS } from '@udecode/plate-heading';
import { HeadingPlugin } from '@udecode/plate-heading/react';
import { ParagraphPlugin } from '@udecode/plate/react';
 
const plugins = [
  // ...otherPlugins,
  HeadingPlugin,
  IndentPlugin.configure({
    inject: {
      targetPlugins: [ParagraphPlugin.key, HEADING_KEYS.h1],
    },
  }),
];

Plugins

IndentPlugin

Options

Collapse all

    Indentation offset used in (offset * element.indent) + unit.

    • Default: 40

    Indentation unit used in (offset * element.indent) + unit.

    • Default: 'px'

    Maximum number of indentations allowed.

API

indent

Parameters

Collapse all

    The editor instance.

    Options for indenting blocks.

outdent

Parameters

Collapse all

    The editor instance.

    Options for outdenting blocks.

setIndent

Parameters

Collapse all

    The editor instance.

    Options for setting indent.

OptionsSetIndentOptions

Collapse all

    Indentation offset.

    • Default: 1

    Options to get nodes to indent.

    Additional props to set on nodes.

    Props to unset when indentation is 0.

    • Default: []

Types

SetIndentOptions

Options

Collapse all

    Change in indentation (1 to indent, -1 to outdent).

    • Default: 1

    Additional getNodes options.

    Additional setNodes options.

    Properties to unset when indentation is 0.

Hooks

useIndentButton

Returnsobject

Collapse all

    Props for the indent button.

    Optionsprops

    Collapse all

      Handler to indent content and focus editor.

useOutdentButton

Returnsobject

Collapse all

    Props for the outdent button.

    Optionsprops

    Collapse all

      Handler to outdent content and focus editor.