Toggle
Add toggles to your document.
Toggle
Features
- Add toggles to your document.
- Toggles are closed by default, and can be opened to reveal the content inside.
- Refer to the Indent documentation for more information.
Plugin dependencies
Installation
npm install @udecode/plate-indent @udecode/plate-node-id @udecode/plate-toggle
Usage
// ...
import { createIndentPlugin } from '@udecode/plate-indent';
import { createNodeIdPlugin } from '@udecode/plate-node-id';
import { createTogglePlugin, ELEMENT_TOGGLE } from '@udecode/plate-toggle';
const plugins = [
// ...otherPlugins,
createHeadingPlugin(),
createParagraphPlugin(),
createIndentPlugin({
inject: {
props: {
validTypes: [ELEMENT_TOGGLE, ELEMENT_PARAGRAPH, ELEMENT_H1],
},
},
}),
createNodeIdPlugin(),
createTogglePlugin(),
];
API
createTogglePlugin
openNextToggles
Marks the block at the current selection as an open toggle. Use this function right before inserting a block so that the toggle is expanded upon insertion.
Parameters
The editor instance.
toggleIds
Toggles the open state of toggles.
Parameters
The editor instance.
An array of element ids.
Set to true if you want to expand all toggles regardless of their current state. Set to false if you want to collapse all toggles regardless of their current state.
API Components
useToggleToolbarButtonState
Returns
A boolean indicating whether the button is pressed or not.
useToggleToolbarButton
A behavior hook for the toggle toolbar button.
State
A boolean indicating whether the button is pressed or not.
Returns
useToggleButtonState
Parameters
The id of the toggle element.
Returns
The id of the toggle element.
A boolean indicating whether the toggle is open (expanded) or not (collapsed).
useToggleButton
A behavior hook for the toggle button that expands or collapses a toggle element.
Parameters
The id of the toggle element.
A boolean indicating whether the toggle is open (expanded) or not (collapsed).
Returns
The id of the toggle element.
A boolean indicating whether the toggle is open (expanded) or not (collapsed).