Font Color Toolbar Button

A toolbar dropdown button for Plate that opens a color picker to apply or clear a text or background color mark on the current selection. It offers default swatches, recently used and editor-derived colors, and a native custom color input.

Font Color Toolbar Button
LIVE · running in a sandboxed iframe
Installed with shadcn add · 2 workarounds · theme from registry.json
  • applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
  • installed base item https://platejs.org/r/plate-ui.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add https://platejs.org/r/font-color-toolbar-button.json

Usage

usage.tsx
import { FontColorToolbarButton } from '@/components/ui/font-color-toolbar-button'; import { PaintBucketIcon } from 'lucide-react'; export default function Toolbar() { return <FontColorToolbarButton nodeType='color'><PaintBucketIcon /></FontColorToolbarButton>; }
  • Use in a rich text editor toolbar to let users change text color or highlight (background) color of selected text.
  • Use when you need a preset palette plus custom hex color input and a clear-color action for Plate marks.
  • Use when the color mark key differs per button, for example 'color' for text and 'backgroundColor' for highlight, via the nodeType prop.
  • Avoid when you only need a fixed list of colors without editor mark integration; a plain dropdown is simpler.

Examples

Text color button

Applies the 'color' mark to the selected text using the default palette.

text-color-button.tsx
import { FontColorToolbarButton } from '@/components/ui/font-color-toolbar-button'; import { BaselineIcon } from 'lucide-react'; export function TextColorButton() { return <FontColorToolbarButton nodeType='color' tooltip='Text color'><BaselineIcon /></FontColorToolbarButton>; }

Background (highlight) color button

Applies the 'backgroundColor' mark so selected text gets a highlight color.

background-(highlight)-color-button.tsx
import { FontColorToolbarButton } from '@/components/ui/font-color-toolbar-button'; import { PaintBucketIcon } from 'lucide-react'; export function HighlightColorButton() { return <FontColorToolbarButton nodeType='backgroundColor' tooltip='Highlight color'><PaintBucketIcon /></FontColorToolbarButton>; }

Controlled open state in a toolbar group

Places both color buttons in a toolbar row and passes dropdown props through to the underlying menu.

controlled-open-state-in-a-toolbar-group.tsx
import { FontColorToolbarButton } from '@/components/ui/font-color-toolbar-button'; import { BaselineIcon, PaintBucketIcon } from 'lucide-react'; export function ColorToolbar() { return <div className='flex gap-1'><FontColorToolbarButton nodeType='color' tooltip='Text color' modal={false}><BaselineIcon /></FontColorToolbarButton><FontColorToolbarButton nodeType='backgroundColor' tooltip='Highlight color' modal={false}><PaintBucketIcon /></FontColorToolbarButton></div>; }

API reference

PropTypeDefaultDescription
nodeTypestring—The Plate mark key to read and write (for example 'color' or 'backgroundColor'). Required.
tooltipstring—Tooltip text shown on the trigger toolbar button.
childrenReact.ReactNode—Trigger content, usually an icon, rendered inside the toolbar button.
openbooleanfalseControlled open state of the dropdown menu, inherited from DropdownMenuProps. Internally managed state is used by the component.
onOpenChange(open: boolean) => void—Callback when the menu opens or closes, inherited from DropdownMenuProps. Internally the component's toggle handler is wired to this on the root menu.
modalbooleantrueWhether the dropdown is modal, inherited from DropdownMenuProps. The component sets modal on the root DropdownMenu.
defaultOpenbooleanfalseInitial open state for uncontrolled use, inherited from DropdownMenuProps.
dir'ltr' | 'rtl'—Reading direction of the dropdown, inherited from DropdownMenuProps.

Accessibility

  • The trigger is a Radix DropdownMenuTrigger with asChild, so keyboard activation with Enter or Space and the menu's arrow-key navigation are preserved.
  • Provide a tooltip prop so the icon-only trigger has a visible label on hover and focus.
  • Each swatch is a DropdownMenuItem with a tooltip showing its color name; keep color names meaningful.
  • The Custom button includes sr-only text 'Custom' so screen readers announce its purpose; the hidden native color input is triggered programmatically.
  • The Clear item has visible text 'Clear' and is only rendered when a color is currently applied.
  • Focus returns to the editor after the menu closes when a selection exists, so typing can continue immediately.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Font Color Toolbar Button" component (plate/font-color-toolbar-button) from its shadcn registry.1. Install it with: npx shadcn@latest add https://platejs.org/r/font-color-toolbar-button.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: nodeType, tooltip, children, open, onOpenChange, modal, defaultOpen, dir.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { FontColorToolbarButton } from '@/components/ui/font-color-toolbar-button'; import { PaintBucketIcon } from 'lucide-react'; export default function Toolbar() { return <FontColorToolbarButton nodeType='color'><PaintBucketIcon /></FontColorToolbarButton>; }```

Files & dependencies

  • src/registry/ui/font-color-toolbar-button.tsx
dependencies@udecode/cn@platejs/basic-styleslodash
registryDependenciesdropdown-menuseparatorbuttontooltiphttps://platejs.org/r/toolbar.json

Looks similar, elsewhere