List plugin for Plate rich-text editor providing indent-based list functionality with comprehensive transforms, queries, and React hooks.
—
React hooks for building list UI components and toolbar buttons. These hooks provide the state management and event handling needed for list-related UI components.
State hook for list toolbar button that tracks whether the current selection contains lists of a specific type.
/**
* State hook for list toolbar button
* @param options - Configuration including node type
* @returns State object with nodeType and pressed status
*/
function useListToolbarButtonState(options?: {
nodeType?: string;
}): {
nodeType: string;
pressed: boolean;
};Usage Example:
import { useListToolbarButtonState, ListStyleType } from "@udecode/plate-list/react";
function BulletListButton() {
const state = useListToolbarButtonState({
nodeType: ListStyleType.Disc
});
// state.pressed will be true if selection contains bullet lists
return <button className={state.pressed ? 'active' : ''}>{/* ... */}</button>;
}Behavior hook for list toolbar button that provides click handlers and props for toggling list formatting.
/**
* Behavior hook for list toolbar button
* @param state - State from useListToolbarButtonState
* @returns Props object with event handlers
*/
function useListToolbarButton(
state: ReturnType<typeof useListToolbarButtonState>
): {
props: {
pressed: boolean;
onClick: () => void;
onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => void;
};
};Complete Usage Example:
import {
useListToolbarButtonState,
useListToolbarButton,
ListStyleType
} from "@udecode/plate-list/react";
function BulletListToolbarButton() {
const state = useListToolbarButtonState({
nodeType: ListStyleType.Disc
});
const { props } = useListToolbarButton(state);
return (
<button {...props}>
Bullet List
</button>
);
}
function NumberedListToolbarButton() {
const state = useListToolbarButtonState({
nodeType: ListStyleType.Decimal
});
const { props } = useListToolbarButton(state);
return (
<button {...props}>
Numbered List
</button>
);
}State hook for todo list element that manages checkbox state and editor context.
/**
* State hook for todo list element
* @param options - Configuration including element
* @returns State object with checkbox status and editor context
*/
function useTodoListElementState(options: {
element: TElement;
}): {
checked: boolean;
editor: PlateEditor;
element: TElement;
readOnly: boolean;
};Behavior hook for todo list element that provides checkbox props and change handlers.
/**
* Behavior hook for todo list element
* @param state - State from useTodoListElementState
* @returns Checkbox props object with event handlers
*/
function useTodoListElement(
state: ReturnType<typeof useTodoListElementState>
): {
checkboxProps: {
checked: boolean;
onCheckedChange: (value: boolean) => void;
onMouseDown: (e: any) => void;
};
};Complete Usage Example:
import {
useTodoListElementState,
useTodoListElement
} from "@udecode/plate-list/react";
import { PlateRenderElementProps } from "@udecode/plate/react";
function TodoListElement({ element, children }: PlateRenderElementProps) {
const state = useTodoListElementState({ element });
const { checkboxProps } = useTodoListElement(state);
return (
<div className="todo-list-item">
<input
type="checkbox"
{...checkboxProps}
/>
<span className={checkboxProps.checked ? 'completed' : ''}>
{children}
</span>
</div>
);
}State hook for todo list toolbar button that tracks todo list presence in selection.
/**
* State hook for todo list toolbar button
* @param options - Configuration including node type
* @returns State object with nodeType and pressed status
*/
function useIndentTodoToolBarButtonState(options?: {
nodeType?: string;
}): {
nodeType: string;
pressed: boolean;
};Behavior hook for todo list toolbar button that provides click handlers for toggling todo list formatting.
/**
* Behavior hook for todo list toolbar button
* @param state - State from useIndentTodoToolBarButtonState
* @returns Props object with event handlers
*/
function useIndentTodoToolBarButton(
state: ReturnType<typeof useIndentTodoToolBarButtonState>
): {
props: {
pressed: boolean;
onClick: () => void;
onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => void;
};
};Usage Example:
import {
useIndentTodoToolBarButtonState,
useIndentTodoToolBarButton,
ListStyleType
} from "@udecode/plate-list/react";
function TodoListToolbarButton() {
const state = useIndentTodoToolBarButtonState({
nodeType: ListStyleType.Disc
});
const { props } = useIndentTodoToolBarButton(state);
return (
<button {...props}>
Todo List
</button>
);
}import {
useListToolbarButtonState,
useListToolbarButton,
useIndentTodoToolBarButtonState,
useIndentTodoToolBarButton,
ListStyleType
} from "@udecode/plate-list/react";
function ListToolbar() {
// Bullet list button
const bulletState = useListToolbarButtonState({
nodeType: ListStyleType.Disc
});
const { props: bulletProps } = useListToolbarButton(bulletState);
// Numbered list button
const numberedState = useListToolbarButtonState({
nodeType: ListStyleType.Decimal
});
const { props: numberedProps } = useListToolbarButton(numberedState);
// Todo list button
const todoState = useIndentTodoToolBarButtonState();
const { props: todoProps } = useIndentTodoToolBarButton(todoState);
return (
<div className="list-toolbar">
<button {...bulletProps}>• Bullets</button>
<button {...numberedProps}>1. Numbers</button>
<button {...todoProps}>☐ Todo</button>
</div>
);
}import {
useTodoListElementState,
useTodoListElement
} from "@udecode/plate-list/react";
import { PlateRenderElementProps } from "@udecode/plate/react";
function CustomTodoListElement({ element, children }: PlateRenderElementProps) {
const state = useTodoListElementState({ element });
const { checkboxProps } = useTodoListElement(state);
return (
<div className={`todo-item ${state.readOnly ? 'readonly' : ''}`}>
<label className="todo-checkbox-container">
<input
type="checkbox"
className="todo-checkbox"
{...checkboxProps}
disabled={state.readOnly}
/>
<span className="checkmark"></span>
</label>
<div className={`todo-content ${checkboxProps.checked ? 'completed' : ''}`}>
{children}
</div>
</div>
);
}import { useListToolbarButtonState, ListStyleType } from "@udecode/plate-list/react";
function SmartListControls() {
const bulletState = useListToolbarButtonState({
nodeType: ListStyleType.Disc
});
const numberedState = useListToolbarButtonState({
nodeType: ListStyleType.Decimal
});
const hasAnyList = bulletState.pressed || numberedState.pressed;
return (
<div>
{/* Always show list creation buttons */}
<ListCreationButtons />
{/* Only show indentation controls when in a list */}
{hasAnyList && <IndentationControls />}
</div>
);
}useListToolbarButtonState, useTodoListElementState) query the editor and return current stateuseListToolbarButton, useTodoListElement) provide event handlers that modify editor stateAll hooks integrate with the Plate editor through:
useEditorRef() - Gets current editor instanceuseEditorSelector() - Subscribes to editor state changesuseReadOnly() - Respects editor read-only stateuseEditorSelector for efficient re-renderingInstall with Tessl CLI
npx tessl i tessl/npm-udecode--plate-list