Toolbar

A container for grouping a set of buttons and controls with keyboard navigation support.

toolbar-demo.tsx
"use client";

import { Toolbar, ToolbarSeparator, ToolbarLink } from "@/components/ui/toolbar/toolbar";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group/toggle-group";

function BoldIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
      <path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
    </svg>
  );
}

function ItalicIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <line x1="19" y1="4" x2="10" y2="4" />
      <line x1="14" y1="20" x2="5" y2="20" />
      <line x1="15" y1="4" x2="9" y2="20" />
    </svg>
  );
}

function UnderlineIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3" />
      <line x1="4" y1="21" x2="20" y2="21" />
    </svg>
  );
}

function AlignLeftIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <line x1="21" y1="6" x2="3" y2="6" />
      <line x1="15" y1="12" x2="3" y2="12" />
      <line x1="17" y1="18" x2="3" y2="18" />
    </svg>
  );
}

function AlignCenterIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <line x1="18" y1="6" x2="6" y2="6" />
      <line x1="21" y1="12" x2="3" y2="12" />
      <line x1="18" y1="18" x2="6" y2="18" />
    </svg>
  );
}

function AlignRightIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
      <line x1="21" y1="6" x2="9" y2="6" />
      <line x1="21" y1="12" x2="3" y2="12" />
      <line x1="21" y1="18" x2="7" y2="18" />
    </svg>
  );
}

export default function ToolbarDemo() {
  return (
    <Toolbar>
      <ToggleGroup toggleMultiple aria-label="Text formatting">
        <ToggleGroupItem value="bold" aria-label="Bold">
          <BoldIcon />
        </ToggleGroupItem>
        <ToggleGroupItem value="italic" aria-label="Italic">
          <ItalicIcon />
        </ToggleGroupItem>
        <ToggleGroupItem value="underline" aria-label="Underline">
          <UnderlineIcon />
        </ToggleGroupItem>
      </ToggleGroup>

      <ToolbarSeparator />

      <ToggleGroup aria-label="Text alignment">
        <ToggleGroupItem value="left" aria-label="Align left">
          <AlignLeftIcon />
        </ToggleGroupItem>
        <ToggleGroupItem value="center" aria-label="Align center">
          <AlignCenterIcon />
        </ToggleGroupItem>
        <ToggleGroupItem value="right" aria-label="Align right">
          <AlignRightIcon />
        </ToggleGroupItem>
      </ToggleGroup>

      <ToolbarSeparator />

      <ToolbarLink href="#" aria-label="Help">
        Help
      </ToolbarLink>
    </Toolbar>
  );
}

Installation

npx shadcn@latest add https://roiui.com/r/toolbar.json

Anatomy

anatomy
import { 
Toolbar, 
ToolbarButton, 
ToolbarLink, 
ToolbarInput,
ToolbarGroup,
ToolbarSeparator 
} from '../ui/toolbar'
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group'
import { Toggle } from '../ui/toggle'
import { Select } from '../ui/select'

<Toolbar>
  <ToggleGroup>
      <ToggleGroupItem value="item1">Item 1</ToggleGroupItem>
      <ToggleGroupItem value="item2">Item 2</ToggleGroupItem>
  </ToggleGroup>
  <ToolbarSeparator />
  <Toggle>Toggle</Toggle>
  <Select>...</Select>
  <ToolbarInput placeholder="Search..." />
  <ToolbarLink href="#">Link</ToolbarLink>
</Toolbar>