Color

Two toolbar buttons, one for text color and one for background color. Each opens a popover with a color area, a hue slider and a hex field.

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.
InitialStateExtensionApplies the seeded content immediately, so the server and the client render the same. Leave it out if your editor starts empty. See Seeding initial content.
FormatStateExtensionReports the color at the selection, so the swatch under each icon matches it. Remove it and the buttons throw, because they read from it.
ColorToolbarPluginBoth color buttons. It takes no props.
ToolbarThe container that holds toolbar plugins. See Toolbar.

Behavior

  • The color is applied while the user drags or types, not when the popover closes.
  • Colors are stored as inline hex styles, color and background-color.
  • When the selection has no explicit color, the swatch falls back to #000000 for text and #ffffff for background. Nothing is applied until the user changes the value.
  • An eye dropper button appears next to the hex field in browsers that support the EyeDropper API.

Styling

The pickers are built from the Intent UI color components (color-area, color-slider, color-field, color-swatch, color-picker) in components/ui/. The popover follows your overlay and border tokens. Edit color-toolbar-plugin.tsx to change the icons or the fallback colors.

  • Text format includes a highlight format that uses a theme color.
  • Font for font family and size.
  • Clear to remove colors from the selection.