Accent command palettes
Five command palettes with one shared skeleton and five ways to mark the selected row: a left bar, a glow, a solid fill, an inner ring and an edge marker. The accent flows from row to row as you move with the arrow keys. Each is self-contained (no cmdk), sized and token-driven.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/command-accentDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/command-accent.tsx"use client"
import * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import {
Calculator,
Calendar,
CreditCard,
FileText,
Search,
Settings,
Smile,
User,
} from "lucide-react"
import { cn } from "@/lib/utils"
/* Accent command family: 5 SELF-CONTAINED command palettes. NO cmdk, NO radix, NO
portal. The skeleton is the same (a search input + a filtered list); the only
difference is the highlight language of the selected row: a left bar, an
overflowing glow, a filled background, an inner ring and a right-edge marker.
The highlight marker flows from row to row with motion layoutId. The arrow keys
move the highlight, Enter selects, Escape clears. Color comes ONLY from tokens,
via alpha color-mix; the primary shades are derived with color-mix. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const paletteWidth: Record<StyledSize, string> = {
sm: "w-64",
md: "w-80",
lg: "w-96",
xl: "w-[28rem]",
}
export interface CommandItem {
label: React.ReactNode
group?: string
icon?: React.ReactNode
onSelect?: () => void
}
interface CommandProps {
className?: string
size?: StyledSize
placeholder?: string
items?: CommandItem[]
}
/* The label can be a ReactNode; flatten it to plain text for filtering. */
function nodeText(node: React.ReactNode): string {
if (node === null || node === undefined || typeof node === "boolean") return ""
if (typeof node === "string" || typeof node === "number") return String(node)
if (Array.isArray(node)) return node.map(nodeText).join("")
if (React.isValidElement(node)) {
return nodeText((node.props as { children?: React.ReactNode }).children)
}
return ""
}
/* Varsayilan liste: prop'suz render eder. */
const defaultItems: CommandItem[] = [
{ label: "Calendar", group: "Suggestions", icon: <Calendar /> },
{ label: "Search Emoji", group: "Suggestions", icon: <Smile /> },
{ label: "Calculator", group: "Suggestions", icon: <Calculator /> },
{ label: "Profile", group: "Settings", icon: <User /> },
{ label: "Billing", group: "Settings", icon: <CreditCard /> },
{ label: "Settings", group: "Settings", icon: <Settings /> },
{ label: "New Document", group: "Actions", icon: <FileText /> },
]
/* Shared state plus combobox/listbox ids. useId keeps several instances on
the same page from colliding. */
function usePalette(source: CommandItem[]) {
const uid = React.useId()
const [query, setQuery] = React.useState("")
const [active, setActive] = React.useState(0)
const filtered = React.useMemo(() => {
const q = query.trim().toLowerCase()
if (q.length === 0) return source
return source.filter((item) => nodeText(item.label).toLowerCase().includes(q))
}, [query, source])
React.useEffect(() => {
setActive((prev) => (prev >= filtered.length ? 0 : prev))
}, [filtered.length])
const select = React.useCallback(
(index: number) => {
const item = filtered[index]
if (item) item.onSelect?.()
},
[filtered]
)
const onKeyDown = React.useCallback(
(e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "ArrowDown") {
e.preventDefault()
setActive((prev) => (filtered.length === 0 ? 0 : (prev + 1) % filtered.length))
} else if (e.key === "ArrowUp") {
e.preventDefault()
setActive((prev) =>
filtered.length === 0 ? 0 : (prev - 1 + filtered.length) % filtered.length
)
} else if (e.key === "Enter") {
e.preventDefault()
select(active)
} else if (e.key === "Escape") {
e.preventDefault()
setQuery("")
setActive(0)
}
},
[filtered.length, active, select]
)
const listId = `${uid}-list`
const optionId = React.useCallback((i: number) => `${uid}-option-${i}`, [uid])
return {
uid,
query,
setQuery,
active,
setActive,
filtered,
select,
onKeyDown,
listId,
optionId,
}
}
const rootBase =
"flex flex-col overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-lg outline-none"
const inputRowBase = "flex items-center gap-2 border-b border-border px-3"
const inputBase =
"h-11 w-full rounded-md bg-transparent py-3 text-sm text-popover-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50"
const listBase = "max-h-72 overflow-y-auto p-1.5"
const optionBase =
"relative flex cursor-pointer select-none items-center gap-2 rounded-lg px-2.5 py-2 text-sm outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
const emptyBase = "py-6 text-center text-sm text-muted-foreground"
/* Bir vurgu dili: aktif satirin sinifi + istege bagli isaret dugumu. */
interface Accent {
/** The classes added to the active row. */
activeClassName: string
/** Extra class for the icon and text tone of a disabled row. */
idleClassName?: string
/** Aktif satirda render edilen isaret (layoutId ile akar). */
marker?: (layoutId: string, reduce: boolean) => React.ReactNode
}
/* Shared shell: every accent uses this, only Accent changes. */
function AccentPalette({ props, accent }: { props: CommandProps; accent: Accent }) {
const {
className,
size = "md",
placeholder = "Type a command...",
items = defaultItems,
} = props
const p = usePalette(items)
const reduce = useReducedMotion() ?? false
const layoutId = `${p.uid}-accent`
return (
<div data-slot="styled-command" className={cn(rootBase, paletteWidth[size], className)}>
<div className={inputRowBase}>
<Search className="size-4 shrink-0 text-muted-foreground" />
<input
role="combobox"
aria-expanded={true}
aria-controls={p.listId}
aria-autocomplete="list"
aria-activedescendant={p.filtered.length > 0 ? p.optionId(p.active) : undefined}
value={p.query}
placeholder={placeholder}
onChange={(e) => p.setQuery(e.target.value)}
onKeyDown={p.onKeyDown}
className={inputBase}
/>
</div>
<div id={p.listId} role="listbox" aria-label="Command palette" className={listBase}>
{p.filtered.length === 0 ? (
<p className={emptyBase}>No results found.</p>
) : (
p.filtered.map((item, i) => {
const isActive = i === p.active
return (
<div
key={nodeText(item.label) || String(i)}
id={p.optionId(i)}
role="option"
aria-selected={isActive}
tabIndex={-1}
onMouseEnter={() => p.setActive(i)}
onClick={() => p.select(i)}
className={cn(
optionBase,
isActive ? accent.activeClassName : accent.idleClassName
)}
>
{isActive && accent.marker ? accent.marker(layoutId, reduce) : null}
<span className="relative flex min-w-0 flex-1 items-center gap-2">
{item.icon}
<span className="flex-1 truncate">{item.label}</span>
</span>
</div>
)
})
)}
</div>
</div>
)
}
const markerSpring = { type: "spring" as const, stiffness: 480, damping: 36 }
/* BarCommand: secili satirin solunda primary bir bar. */
export function BarCommand(props: CommandProps) {
return (
<AccentPalette
props={props}
accent={{
activeClassName:
"bg-[color-mix(in_oklab,var(--color-primary)_10%,transparent)] text-foreground [&_svg]:text-primary [&_i]:text-primary",
idleClassName:
"text-muted-foreground [&_svg]:text-muted-foreground [&_i]:text-muted-foreground",
marker: (layoutId, reduce) => (
<motion.span
layoutId={reduce ? undefined : layoutId}
transition={reduce ? { duration: 0 } : markerSpring}
className="absolute inset-y-1 left-0 w-0.5 rounded-full bg-primary"
/>
),
}}
/>
)
}
/* GlowCommand: the selected row carries a primary glow halo. */
export function GlowCommand(props: CommandProps) {
return (
<AccentPalette
props={props}
accent={{
activeClassName:
"bg-[color-mix(in_oklab,var(--color-primary)_14%,transparent)] text-foreground shadow-[0_0_18px_color-mix(in_oklab,var(--color-primary)_35%,transparent)] [&_svg]:text-primary [&_i]:text-primary",
idleClassName:
"text-muted-foreground [&_svg]:text-muted-foreground [&_i]:text-muted-foreground",
}}
/>
)
}
/* FillCommand: the selected row sits on a fully primary ground. */
export function FillCommand(props: CommandProps) {
return (
<AccentPalette
props={props}
accent={{
activeClassName:
"text-primary-foreground [&_svg]:text-primary-foreground [&_i]:text-primary-foreground",
idleClassName:
"text-muted-foreground [&_svg]:text-muted-foreground [&_i]:text-muted-foreground",
marker: (layoutId, reduce) => (
<motion.span
layoutId={reduce ? undefined : layoutId}
transition={reduce ? { duration: 0 } : markerSpring}
className="absolute inset-0 z-0 rounded-lg bg-primary"
/>
),
}}
/>
)
}
/* RingCommand: the selected row is framed by an inner primary ring. */
export function RingCommand(props: CommandProps) {
return (
<AccentPalette
props={props}
accent={{
activeClassName:
"bg-[color-mix(in_oklab,var(--color-primary)_6%,transparent)] text-foreground ring-1 ring-[color-mix(in_oklab,var(--color-primary)_55%,transparent)] [&_svg]:text-primary [&_i]:text-primary",
idleClassName:
"text-muted-foreground [&_svg]:text-muted-foreground [&_i]:text-muted-foreground",
}}
/>
)
}
/* EdgeCommand: soldan saga sonen bir kenar gradyani + sag kenar isareti. */
export function EdgeCommand(props: CommandProps) {
return (
<AccentPalette
props={props}
accent={{
activeClassName:
"bg-gradient-to-r from-[color-mix(in_oklab,var(--color-primary)_18%,transparent)] to-transparent text-foreground [&_svg]:text-primary [&_i]:text-primary",
idleClassName:
"text-muted-foreground [&_svg]:text-muted-foreground [&_i]:text-muted-foreground",
marker: (layoutId, reduce) => (
<motion.span
layoutId={reduce ? undefined : layoutId}
transition={reduce ? { duration: 0 } : markerSpring}
className="absolute inset-y-1.5 right-1.5 w-1 rounded-full bg-[color-mix(in_oklab,var(--color-primary)_70%,transparent)]"
/>
),
}}
/>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Bar
A primary bar on the left of the selected row.
import { BarCommand } from "@/components/ui/command-accent"
<BarCommand />Glow
The selected row carries a primary glow.
import { GlowCommand } from "@/components/ui/command-accent"
<GlowCommand />Fill
The selected row sits on a solid primary fill.
import { FillCommand } from "@/components/ui/command-accent"
<FillCommand />Ring
An inner primary ring frames the selected row.
import { RingCommand } from "@/components/ui/command-accent"
<RingCommand />Edge
A fading gradient plus a marker on the right edge.
import { EdgeCommand } from "@/components/ui/command-accent"
<EdgeCommand />ai2 Accent command palettes: 5 styled variations on the token system
The ai2 Accent command palettes are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around command palettes that vary the accent treatment of the selected row. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion moves the accent marker between rows with a shared layout animation. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the marker jumps straight to the selected row with no transform.
What is in the ai2 Accent command palettes?
5 exports in one file: Bar, Glow, Fill, Ring and Edge. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion moves the accent marker between rows with a shared layout animation.
- Reduced-motion aware: Under prefers-reduced-motion, the marker jumps straight to the selected row with no transform.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Accent command palettes sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.