Compact command palettes
Five command palettes for tight spaces: dense rows, a minimal shell, a narrow column, an inline form field and a bare list with no chrome. Each is a complete palette, self-contained (no cmdk), sized, token-driven, filters as you type and supports arrow keys plus Enter.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/command-compactDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/command-compact.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"
/* Compact command family: 5 SELF-CONTAINED command palettes, all of them DENSE /
low-chrome layouts. NO cmdk, NO radix, NO portal. The difference is in row
height, typography and how much chrome there is: dense (tight rows), minimal
(no chrome, a thin separator), narrow (a narrow column), inline (a field that
sits inside a form), bare (no chrome at all). All of them are complete palettes:
typing filters, the arrow keys move the highlight, Enter selects, Escape clears.
Color comes ONLY from tokens, via alpha color-mix. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const wideWidth: Record<StyledSize, string> = {
sm: "w-64",
md: "w-80",
lg: "w-96",
xl: "w-[28rem]",
}
const narrowWidth: Record<StyledSize, string> = {
sm: "w-48",
md: "w-56",
lg: "w-64",
xl: "w-72",
}
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 { query, setQuery, active, setActive, filtered, select, onKeyDown, listId, optionId }
}
/* One density picture: shell, search row, list and option measurements. */
interface Density {
root: string
widths: Record<StyledSize, string>
inputRow: string
input: string
list: string
option: string
activeOption: string
empty: string
showIcons: boolean
searchIcon: boolean
}
const iconCompat =
"[&_svg]:shrink-0 [&_svg]:text-muted-foreground [&_i]:leading-none [&_i]:text-muted-foreground"
const focusRing = "focus-visible:ring-[3px] focus-visible:ring-ring/50"
/* Shared shell: every density uses this, only Density changes. */
function CompactPalette({ props, d }: { props: CommandProps; d: Density }) {
const {
className,
size = "md",
placeholder = "Search...",
items = defaultItems,
} = props
const p = usePalette(items)
const reduce = useReducedMotion() ?? false
return (
<div data-slot="styled-command" className={cn(d.root, d.widths[size], className)}>
<div className={d.inputRow}>
{d.searchIcon ? (
<Search className="size-3.5 shrink-0 text-muted-foreground" />
) : null}
<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={cn(d.input, focusRing)}
/>
</div>
<div id={p.listId} role="listbox" aria-label="Command palette" className={d.list}>
{p.filtered.length === 0 ? (
<p className={d.empty}>No results</p>
) : (
p.filtered.map((item, i) => (
<motion.div
key={nodeText(item.label) || String(i)}
id={p.optionId(i)}
role="option"
aria-selected={i === p.active}
tabIndex={-1}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={reduce ? { duration: 0 } : { duration: 0.12, ease: "easeOut" }}
onMouseEnter={() => p.setActive(i)}
onClick={() => p.select(i)}
className={cn(d.option, iconCompat, focusRing, i === p.active && d.activeOption)}
>
{d.showIcons ? item.icon : null}
<span className="flex-1 truncate">{item.label}</span>
</motion.div>
))
)}
</div>
</div>
)
}
/* DenseCommand: the full shell, but with the rows and the search field tightened. */
export function DenseCommand(props: CommandProps) {
return (
<CompactPalette
props={props}
d={{
root: "flex flex-col overflow-hidden rounded-lg border border-border bg-popover text-popover-foreground shadow-md outline-none",
widths: wideWidth,
inputRow: "flex items-center gap-1.5 border-b border-border px-2",
input:
"h-8 w-full rounded bg-transparent py-1 text-xs text-popover-foreground outline-none placeholder:text-muted-foreground",
list: "max-h-56 overflow-y-auto p-1",
option:
"flex cursor-pointer select-none items-center gap-1.5 rounded px-1.5 py-1 text-xs outline-none transition-colors [&_svg]:size-3.5 [&_i]:text-xs",
activeOption: "bg-accent text-accent-foreground",
empty: "py-3 text-center text-xs text-muted-foreground",
showIcons: true,
searchIcon: true,
}}
/>
)
}
/* MinimalCommand: no shell, just a thin separator and a plain list. */
export function MinimalCommand(props: CommandProps) {
return (
<CompactPalette
props={props}
d={{
root: "flex flex-col overflow-hidden bg-transparent text-foreground outline-none",
widths: wideWidth,
inputRow: "flex items-center gap-2 border-b border-border px-1",
input:
"h-9 w-full rounded bg-transparent py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground",
list: "max-h-64 overflow-y-auto py-1",
option:
"flex cursor-pointer select-none items-center gap-2 rounded-md px-1.5 py-1.5 text-sm outline-none transition-colors [&_svg]:size-4 [&_i]:text-base",
activeOption: "bg-accent text-accent-foreground",
empty: "py-4 text-center text-sm text-muted-foreground",
showIcons: false,
searchIcon: false,
}}
/>
)
}
/* NarrowCommand: a narrow column; at the width of a side panel or a menu. */
export function NarrowCommand(props: CommandProps) {
return (
<CompactPalette
props={props}
d={{
root: "flex flex-col overflow-hidden rounded-lg border border-border bg-popover text-popover-foreground shadow-md outline-none",
widths: narrowWidth,
inputRow: "flex items-center gap-1.5 border-b border-border px-2",
input:
"h-9 w-full rounded bg-transparent py-2 text-xs text-popover-foreground outline-none placeholder:text-muted-foreground",
list: "max-h-52 overflow-y-auto p-1",
option:
"flex cursor-pointer select-none items-center gap-1.5 rounded px-1.5 py-1.5 text-xs outline-none transition-colors [&_svg]:size-3.5 [&_i]:text-xs",
activeOption: "bg-accent text-accent-foreground",
empty: "py-3 text-center text-xs text-muted-foreground",
showIcons: true,
searchIcon: true,
}}
/>
)
}
/* InlineCommand: form alani gibi gorunen arama kutusu, liste hemen altinda. */
export function InlineCommand(props: CommandProps) {
return (
<CompactPalette
props={props}
d={{
root: "flex flex-col gap-1 bg-transparent text-foreground outline-none",
widths: wideWidth,
inputRow:
"flex items-center gap-2 rounded-md border border-field-border bg-background px-2.5 shadow-xs",
input:
"h-9 w-full rounded bg-transparent py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground",
list: "max-h-56 overflow-y-auto rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-sm",
option:
"flex cursor-pointer select-none items-center gap-2 rounded px-2 py-1.5 text-sm outline-none transition-colors [&_svg]:size-4 [&_i]:text-base",
activeOption: "bg-accent text-accent-foreground",
empty: "py-3 text-center text-sm text-muted-foreground",
showIcons: true,
searchIcon: true,
}}
/>
)
}
/* BareCommand: no chrome at all; the selected row is marked only by text tone. */
export function BareCommand(props: CommandProps) {
return (
<CompactPalette
props={props}
d={{
root: "flex flex-col bg-transparent text-foreground outline-none",
widths: wideWidth,
inputRow: "flex items-center gap-2 px-0",
input:
"h-8 w-full rounded bg-transparent py-1 text-sm font-medium text-foreground outline-none placeholder:text-muted-foreground",
list: "max-h-64 overflow-y-auto py-1",
option:
"flex cursor-pointer select-none items-center gap-2 rounded px-0 py-1 text-sm text-muted-foreground outline-none transition-colors [&_svg]:size-4 [&_i]:text-base",
activeOption: "text-foreground underline underline-offset-4",
empty: "py-3 text-sm text-muted-foreground",
showIcons: false,
searchIcon: false,
}}
/>
)
}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.
Dense
Full chrome, but the rows and the search field are tightened.
import { DenseCommand } from "@/components/ui/command-compact"
<DenseCommand />Minimal
No panel chrome, just a thin divider over a flat list.
import { MinimalCommand } from "@/components/ui/command-compact"
<MinimalCommand />Narrow
A narrow column sized for a side panel or a menu.
import { NarrowCommand } from "@/components/ui/command-compact"
<NarrowCommand />Inline
A form field with the result list right underneath.
import { InlineCommand } from "@/components/ui/command-compact"
<InlineCommand />Bare
No chrome at all; selection reads as a text treatment.
import { BareCommand } from "@/components/ui/command-compact"
<BareCommand />ai2 Compact command palettes: 5 styled variations on the token system
The ai2 Compact command palettes are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around command palettes that reduce row height and shell chrome. 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 fades each row in as the filter changes. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the fade is removed and rows appear instantly.
What is in the ai2 Compact command palettes?
5 exports in one file: Dense, Minimal, Narrow, Inline and Bare. 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 fades each row in as the filter changes.
- Reduced-motion aware: Under prefers-reduced-motion, the fade is removed and rows appear instantly.
- 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 Compact 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.