Toolbar

A compact formatting toolbar with real depth, keys sunk into shaded wells, pressed keys that rise out of them and a text style dropdown.

Preview

Setup

Install with the shadcn CLI

$npx shadcn@latest add https://kinetikui.singhgourav.site/r/toolbar.json

One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.

Or install manually

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge framer-motion lucide-react
  2. 2

    Copy lib/utils.ts from the Code tab. Skip if you already have cn().

  3. 3

    Copy styles/tokens.css from the Code tab and import it in your global CSS after Tailwind: @import "./styles/tokens.css";

  4. 4

    Create a components/ui/toolbar/ folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest.

  5. 5

    Import and render:

    Example
    import { Toolbar, ToolbarGroup, ToolbarButton } from "@/components/ui/toolbar"
    
    <Toolbar>
      <ToolbarGroup>
        <ToolbarButton label="Bold" pressed={bold} onPressedChange={setBold}>B</ToolbarButton>
      </ToolbarGroup>
    </Toolbar>

Needs framer-motion and lucide-react.

Usage

Every surface is lit from above. The bar sits in a gradient bezel, each group is carved into a shaded well with a light lip on its lower edge, and a pressed key rises out of the well. In a toggle group the raised key slides to the new choice.

Example
import { AlignCenter, AlignLeft, Bold, Italic, Undo2 } from "lucide-react"
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSelect, ToolbarToggleGroup } from "@/components/ui/toolbar"

export function Formatting() {
  const [bold, setBold] = useState(false)
  const [italic, setItalic] = useState(false)
  const [align, setAlign] = useState("left")
  const [style, setStyle] = useState("body")

  return (
    <Toolbar label="Text formatting">
      <ToolbarGroup>
        <ToolbarButton label="Undo" onClick={undo}><Undo2 /></ToolbarButton>
      </ToolbarGroup>

      <ToolbarGroup>
        <ToolbarButton label="Bold" pressed={bold} onPressedChange={setBold}><Bold /></ToolbarButton>
        <ToolbarButton label="Italic" pressed={italic} onPressedChange={setItalic}><Italic /></ToolbarButton>
      </ToolbarGroup>

      <ToolbarToggleGroup label="Alignment" value={align} onValueChange={setAlign}>
        <ToolbarButton label="Align left" value="left"><AlignLeft /></ToolbarButton>
        <ToolbarButton label="Align center" value="center"><AlignCenter /></ToolbarButton>
      </ToolbarToggleGroup>

      <ToolbarSelect
        label="Text style"
        align="end"
        value={style}
        onValueChange={setStyle}
        options={[
          { value: "h1", label: "Heading 1", className: "text-base font-semibold" },
          { value: "body", label: "Body" },
          { value: "caption", label: "Caption", className: "text-xs" },
        ]}
      />
    </Toolbar>
  )
}

Keys

A ToolbarButton is a plain action by default. Give it pressed and it becomes a toggle. Inside a ToolbarToggleGroup, give it a value instead and the group keeps exactly one pressed. Put a ToolbarSeparator between keys in a well to cut a groove between them.

Text style dropdown

ToolbarSelect sits in its own well and opens a raised menu. Give each option a className and its label previews that style in the menu, so Heading 1 reads like a heading. Set align="end" when it is the last item, so the menu lines up with the bar's right edge.

Props

ComponentPropTypeNotes
ToolbarlabelstringAccessible name. Defaults to "Toolbar".
ToolbarGroup—div propsA shaded well for related keys.
ToolbarToggleGroupvalue / onValueChangestringThe pressed option. The raised key slides between options.
ToolbarButtonlabelstringRequired. Accessible name and tooltip.
ToolbarButtonpressed / onPressedChangebooleanMakes the key a toggle.
ToolbarButtonvaluestringOption to select inside a ToolbarToggleGroup.
ToolbarSeparator—div propsA carved groove between keys inside a well.
ToolbarSelectlabelstringRequired. Accessible name, e.g. "Text style".
ToolbarSelectvalue / onValueChangestringThe chosen option.
ToolbarSelectoptions{ value; label; className? }[]className previews the style in the menu.
ToolbarSelectalign"start" | "end"Which edge the menu lines up with. Defaults to start.

Accessibility

  • Renders a toolbar with a single Tab stop; Left and Right arrows, Home and End move between keys
  • Disabled keys are skipped, and the Tab stop moves off a key that becomes disabled
  • Toggles use aria-pressed; a toggle group is a radiogroup of radio keys with aria-checked
  • Every key has an accessible name and a matching tooltip, even when it only shows an icon
  • The dropdown trigger opens with Down, Up, Enter or Space; in the menu, Up and Down move, Enter picks, Escape closes and returns focus
  • Clicking outside closes the menu
  • With reduced motion, the raised key snaps instead of sliding and the menu appears without scaling