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
01.Good interfaces feel carved, not printed. Light falls from above, and every edge says which way it faces.
Setup
Install with the shadcn CLI
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
Run in your terminal:
$npm install clsx tailwind-merge framer-motion lucide-react - 2
Copy
lib/utils.tsfrom the Code tab. Skip if you already havecn(). - 3
Copy
styles/tokens.cssfrom the Code tab and import it in your global CSS after Tailwind:@import "./styles/tokens.css"; - 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
Import and render:
Exampleimport { 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.
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
| Component | Prop | Type | Notes |
|---|---|---|---|
Toolbar | label | string | Accessible name. Defaults to "Toolbar". |
ToolbarGroup | — | div props | A shaded well for related keys. |
ToolbarToggleGroup | value / onValueChange | string | The pressed option. The raised key slides between options. |
ToolbarButton | label | string | Required. Accessible name and tooltip. |
ToolbarButton | pressed / onPressedChange | boolean | Makes the key a toggle. |
ToolbarButton | value | string | Option to select inside a ToolbarToggleGroup. |
ToolbarSeparator | — | div props | A carved groove between keys inside a well. |
ToolbarSelect | label | string | Required. Accessible name, e.g. "Text style". |
ToolbarSelect | value / onValueChange | string | The chosen option. |
ToolbarSelect | options | { value; label; className? }[] | className previews the style in the menu. |
ToolbarSelect | align | "start" | "end" | Which edge the menu lines up with. Defaults to start. |
Accessibility
- Renders a
toolbarwith 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 aradiogroupofradiokeys witharia-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