Command bar
Floating lit-key bulk-action bar that springs up when items are selected, with a rolling count, single-key action shortcuts, an overflow menu and clear, plus a quick-actions ⌘K pill.
Preview
Shared files
Select files to see the bar.
- Launch checklist.mdInes12 KB2m ago
- Walkthrough v4.mp4Malik184 MB1h ago
- Pricing table.csvTomás8 KBYesterday
- Press kit.zipInes42 MBMon
- Pebble notes 12.pdfPriya2.1 MBOct 28
2files
Install
Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.
npx shadcn@latest add https://pebbleui.com/r/command-bar.jsonProps
| Prop | Type | Default | Description |
|---|---|---|---|
| count | number | — | CommandBar: selected item count; the bar rises while it is above 0. |
| onClear | () => void | — | CommandBar: clears the selection (× button and Escape). |
| noun | string | "selected" | CommandBar: text after the count. |
| label / icon / onSelect | string / ReactNode / () => void | — | CommandBarAction: the action button. |
| shortcut | string | — | CommandBarAction: single key that runs it while the bar is open. CommandBarPill: ⌘ letter (default K). |
| variant | "default" | "danger" | "default" | CommandBarAction: danger tints the icon and hover. |
| bindShortcut | boolean | true | CommandBarPill: listen for ⌘/Ctrl + shortcut globally. |
Build notes
- Surface: the lit-key recipe (`from-key-top to-key-bottom`, `ring-key-edge`,
`--key-shine` + `--elevation-lg`) so it inverts with the theme; inner
controls use `primary-foreground` at 10% for hover and 15% for dividers.
- Enter `{ opacity 0, y 24, scale 0.96 }` → rest on spring 420/32/0.8; exit
`y 16, scale 0.98` in 140 ms on the exit curve. `AnimatePresence` owns it,
driven by `count > 0`.
- Count roll: `AnimatePresence mode="popLayout"` keyed by count; ±8 px with a
2 px blur, 180 ms.
- Shortcuts: each action adds a `keydown` listener only while the bar is open;
it skips modified keys, typing targets
(`input, textarea, select, [contenteditable]`) and open menus/modal dialogs.
- Pill: frosted card pill with an ember dot and `⌘ K` keys; its global
listener is optional (`bindShortcut`) because many apps already own ⌘K. The
docs demo turns it off.View source
registry/nav/command-bar/command-bar.tsx
"use client";
/* PEBBLE-LICENSE
Built by Pebble. Component: command-bar.
First-party license: MIT
The following first-party terms apply only to original Pebble material.
MIT License
Copyright (c) 2026 Praxys Solutions LLC (Pebble)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */
import * as React from "react";
import { AnimatePresence, MotionConfig, motion } from "motion/react";
import { cn } from "@/lib/utils";
import { Kbd } from "@/registry/text/kbd/kbd";
import { Menu, MenuContent, MenuTrigger } from "@/registry/overlay/menu/menu";
// Hydration-safe reduced motion: the server (and the hydration pass) render
// "no preference", then the real preference applies right after hydration.
const subscribeReduce = (onChange: () => void) => {
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
mq.addEventListener("change", onChange);
return () => mq.removeEventListener("change", onChange);
};
const getReduce = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const useReduceMotion = () => React.useSyncExternalStore(subscribeReduce, getReduce, () => false);
// Pebble: the bar is the lit key stretched into a strip: dark in light mode,
// paper in dark mode, so it reads as the one thing to act on. It rises from
// below on a spring when something is selected and sinks away when cleared.
// The count rolls when it changes. Each action can carry a single-key
// shortcut, live only while the bar is showing and never while typing.
const spring = { type: "spring", stiffness: 420, damping: 32, mass: 0.8 } as const;
type BarContextValue = { open: boolean };
const BarContext = React.createContext<BarContextValue>({ open: false });
function isTyping(target: EventTarget | null) {
const el = target as HTMLElement | null;
return !!el?.closest?.(
'input, textarea, select, [contenteditable]:not([contenteditable="false"])',
);
}
export type CommandBarProps = Omit<
React.ComponentProps<typeof motion.div>,
"children" | "initial" | "animate" | "exit" | "transition"
> & {
/** Number of selected items; the bar shows while it is above 0. */
count: number;
/** Clears the selection (× button and Escape). */
onClear: () => void;
/** Text after the count. */
noun?: string;
/** CommandBarAction and CommandBarOverflow children. */
children: React.ReactNode;
/** Toolbar name. */
label?: string;
};
export function CommandBar({
count,
onClear,
noun = "selected",
label = "Selection actions",
className,
children,
...props
}: CommandBarProps) {
const reduced = useReduceMotion();
const open = count > 0;
const ref = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (!open) return;
const onKey = (event: KeyboardEvent) => {
if (event.key !== "Escape" || event.defaultPrevented || isTyping(event.target)) return;
// Leave Escape to open menus and dialogs.
if (document.querySelector('[role="menu"], [role="dialog"][aria-modal="true"]')) return;
onClear();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [open, onClear]);
return (
<BarContext.Provider value={{ open }}>
<MotionConfig reducedMotion={reduced ? "always" : "never"}>
<AnimatePresence>
{open && (
<motion.div
ref={ref}
key="bar"
role="toolbar"
aria-label={label}
data-slot="command-bar"
initial={reduced ? { opacity: 0 } : { opacity: 0, y: 24, scale: 0.96 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={
reduced
? { opacity: 0, transition: { duration: 0.12 } }
: {
opacity: 0,
y: 16,
scale: 0.98,
transition: { duration: 0.14, ease: [0.55, 0, 1, 0.45] },
}
}
transition={spring}
onKeyDown={(event) => {
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
const items = Array.from(
ref.current?.querySelectorAll<HTMLElement>(
"[data-command-bar-item]:not(:disabled)",
) ?? [],
);
const i = items.indexOf(document.activeElement as HTMLElement);
if (i === -1) return;
event.preventDefault();
const last = items.length - 1;
const next =
event.key === "Home"
? 0
: event.key === "End"
? last
: event.key === "ArrowRight"
? (i + 1) % items.length
: (i - 1 + items.length) % items.length;
items[next].focus();
}}
className={cn(
"flex min-h-12 w-fit max-w-full flex-wrap items-center gap-1 rounded-2xl py-1.5 pr-1.5 pl-3 text-primary-foreground",
"bg-linear-to-b from-key-top to-key-bottom shadow-[var(--key-shine),var(--elevation-lg)] ring-1 ring-key-edge",
className,
)}
{...props}
>
<p
className="flex items-center gap-1.5 pr-2 text-[13px] font-medium whitespace-nowrap"
aria-live="polite"
>
<span className="relative inline-flex min-w-[1ch] justify-center overflow-hidden tabular-nums">
<AnimatePresence mode="popLayout" initial={false}>
<motion.span
key={count}
initial={reduced ? { opacity: 0 } : { opacity: 0, y: 8, filter: "blur(2px)" }}
animate={{ opacity: 1, y: 0, filter: "blur(0px)" }}
exit={reduced ? { opacity: 0 } : { opacity: 0, y: -8, filter: "blur(2px)" }}
transition={{ duration: 0.18, ease: [0.22, 1, 0.36, 1] }}
>
{count}
</motion.span>
</AnimatePresence>
</span>
<span className="text-primary-foreground/70">{noun}</span>
</p>
<span aria-hidden className="h-5 w-px bg-primary-foreground/15" />
{children}
<span aria-hidden className="h-5 w-px bg-primary-foreground/15" />
<button
type="button"
data-command-bar-item
aria-label="Clear selection"
aria-keyshortcuts="Escape"
onClick={onClear}
className={cn(itemStyle, "w-9 justify-center px-0")}
>
<svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
aria-hidden
className="size-4"
>
<path d="M4.5 4.5l7 7M11.5 4.5l-7 7" />
</svg>
</button>
</motion.div>
)}
</AnimatePresence>
</MotionConfig>
</BarContext.Provider>
);
}
const itemStyle = cn(
"inline-flex h-9 shrink-0 cursor-pointer items-center gap-2 rounded-xl px-2.5 text-[13px] font-medium text-primary-foreground outline-none",
"transition-[background-color,transform] duration-(--motion-fast) ease-enter motion-reduce:transition-none",
"hover:bg-primary-foreground/10 active:scale-[0.96] motion-reduce:active:scale-100",
"focus-visible:ring-2 focus-visible:ring-ring",
"disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0",
);
export type CommandBarActionProps = Omit<React.ComponentProps<"button">, "onSelect"> & {
icon?: React.ReactNode;
label: string;
/** Single key that runs the action while the bar is open, e.g. "E". */
shortcut?: string;
onSelect: () => void;
variant?: "default" | "danger";
};
export function CommandBarAction({
icon,
label,
shortcut,
onSelect,
variant = "default",
disabled,
className,
...props
}: CommandBarActionProps) {
const { open } = React.useContext(BarContext);
React.useEffect(() => {
if (!open || !shortcut || disabled) return;
const onKey = (event: KeyboardEvent) => {
if (event.metaKey || event.ctrlKey || event.altKey || event.defaultPrevented) return;
if (isTyping(event.target) || event.key.toLowerCase() !== shortcut.toLowerCase()) return;
if (document.querySelector('[role="menu"], [role="dialog"][aria-modal="true"]')) return;
event.preventDefault();
onSelect();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [open, shortcut, disabled, onSelect]);
return (
<button
type="button"
data-command-bar-item
data-variant={variant}
aria-keyshortcuts={shortcut}
disabled={disabled}
onClick={onSelect}
className={cn(
itemStyle,
variant === "danger" && "hover:bg-danger/25 [&_svg]:text-danger",
className,
)}
{...props}
>
{icon}
<span>{label}</span>
{shortcut && (
<Kbd variant="flat" className="bg-primary-foreground/12 text-primary-foreground/75">
{shortcut.toUpperCase()}
</Kbd>
)}
</button>
);
}
/** "More" button opening a Menu; pass MenuItem children. */
export function CommandBarOverflow({
label = "More actions",
children,
}: {
label?: string;
children: React.ReactNode;
}) {
return (
<Menu>
<MenuTrigger asChild>
<button
type="button"
data-command-bar-item
aria-label={label}
className={cn(
itemStyle,
"w-9 justify-center px-0 data-[state=open]:bg-primary-foreground/10",
)}
>
<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden className="size-4">
<circle cx="3.5" cy="8" r="1.25" />
<circle cx="8" cy="8" r="1.25" />
<circle cx="12.5" cy="8" r="1.25" />
</svg>
</button>
</MenuTrigger>
<MenuContent side="top" align="end" sideOffset={10} className="min-w-44">
{children}
</MenuContent>
</Menu>
);
}
export type CommandBarPillProps = React.ComponentProps<"button"> & {
/** Letter shown with ⌘ and, when `bindShortcut`, used with ⌘/Ctrl to press the pill. */
shortcut?: string;
/** Listen for ⌘/Ctrl + shortcut globally. Turn off if the page already owns that key. */
bindShortcut?: boolean;
};
/** The resting "Quick actions ⌘K" pill. */
export function CommandBarPill({
shortcut = "K",
bindShortcut = true,
className,
children = "Quick actions",
onClick,
...props
}: CommandBarPillProps) {
const ref = React.useRef<HTMLButtonElement>(null);
React.useEffect(() => {
if (!shortcut || !bindShortcut) return;
const onKey = (event: KeyboardEvent) => {
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== shortcut.toLowerCase())
return;
event.preventDefault();
ref.current?.click();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [shortcut, bindShortcut]);
return (
<button
ref={ref}
type="button"
data-slot="command-bar-pill"
aria-keyshortcuts={
shortcut && bindShortcut ? `Meta+${shortcut} Control+${shortcut}` : undefined
}
onClick={onClick}
className={cn(
"inline-flex h-10 cursor-pointer items-center gap-2.5 rounded-full bg-card/90 pr-2 pl-4 text-[13px] font-medium text-foreground outline-none",
"shadow-raised-lg ring-1 inset-shadow-highlight ring-hairline backdrop-blur-md",
"transition-[transform,box-shadow] duration-(--motion-fast) ease-enter motion-reduce:transition-none",
"hover:-translate-y-px active:translate-y-0 active:scale-[0.97] motion-reduce:hover:translate-y-0",
"focus-visible:ring-2 focus-visible:ring-ring",
className,
)}
{...props}
>
<span aria-hidden className="size-1.5 rounded-full bg-accent" />
{children}
{shortcut && (
<span className="flex gap-0.5">
<Kbd>⌘</Kbd>
<Kbd>{shortcut}</Kbd>
</span>
)}
</button>
);
}
