Insert block menu

BlockInsert is a toolbar group that holds insert buttons. Unlike the slash menu, it is always visible.

Installation

This pattern is built from files in @intentui/editor. Install the editor, then copy the code above into a component of your own.

npx shadcn@latest add @intentui/editor

What's included

PieceWhy it is here
RichTextExtensionLexical's rich text behavior. Every pattern needs it.
CodeExtensionCode block node and highlighting, used by the code block button.
LayoutExtensionColumn layout nodes and the command the columns button dispatches.
HorizontalRuleExtensionThe divider node and command.
ImageExtensionThe image node and the insert command.
TableExtensionTable nodes and the insert command.
BlockInsertThe toolbar group, labelled "Insert".
InsertCodeBlockPlugin, InsertColumnsPlugin, InsertHorizontalRulePlugin, InsertImagePlugin, InsertTablePluginOne button per block.
ToolbarThe container that holds toolbar plugins. See Toolbar.

Each button needs the extension of its block. To remove a block, delete its button and its extension. To remove the group, delete BlockInsert. Reorder the lines to reorder the buttons.

Buttons

PluginButtonBehavior
InsertCodeBlockPluginInsert code blockInserts a code block.
InsertColumnsPluginColumnsOpens a menu with 1 column, 2 columns and 3 columns.
InsertHorizontalRulePluginInsert dividerInserts a divider.
InsertImagePluginInsert imageOpens a file picker and inserts the chosen image.
InsertTablePluginInsert tableOpens a grid of up to 10 columns by 8 rows. Click a cell to choose the size.

All buttons are disabled when the editor is read-only. Each block is covered in its own pattern: Code block, Columns, Divider, Image and Table.

Emoji button

The full editor also has an InsertEmojiPlugin button. It only types the : trigger, so it needs EmojiExtension and EmojiPickerPlugin to show anything. See Emoji.

Styling

Buttons are Intent UI outline buttons with size="sq-xs", each with a tooltip. Group spacing and colors come from the toolbar. BlockInsert is a ToolbarGroup and accepts the same props.