Motion command palettes
Five command palettes with one shared skeleton and five enter and filter flavors: slide, pop, fade, spring and morph. Each is self-contained (no cmdk), sized, token-driven, filters as you type and supports arrow keys plus Enter. Type in the input to watch rows leave and arrive.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/command-motionDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/command-motion.tsx"use client"
import * as React from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import {
Calculator,
Calendar,
CreditCard,
FileText,
Search,
Settings,
Smile,
User,
} from "lucide-react"
import { cn } from "@/lib/utils"
/* Motion command family: 5 SELF-CONTAINED command palettes. NO cmdk, NO radix, NO
portal. They all share the same skeleton (a search input + a filtered list) and
differ ONLY in the enter/exit motion of the rows: slide, pop, fade, spring,
morph. The list filters as the user types; AnimatePresence matching removes the
row that no longer matches and animates the new one in. The arrow keys move the
highlight, Enter selects, Escape clears. Color comes ONLY from tokens, via alpha
color-mix. No transform under reduced motion, only a short fade. */
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 { 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 =
"flex cursor-pointer select-none items-center gap-2 rounded-lg px-2.5 py-2 text-sm outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground [&_i]:text-base [&_i]:leading-none [&_i]:text-muted-foreground"
const emptyBase = "py-6 text-center text-sm text-muted-foreground"
/* Bir hareket lezzeti: giris/cikis transformu + zamanlama. */
interface Flavor {
initial: Record<string, number>
animate: Record<string, number>
exit: Record<string, number>
duration: number
stagger: number
spring?: { stiffness: number; damping: number }
layout?: boolean
}
/* Row transition. A short fade under reduced motion, no transform. */
function rowTransition(f: Flavor, index: number, reduce: boolean) {
if (reduce) return { duration: 0.12, ease: "easeOut" as const }
const delay = Math.min(index * f.stagger, 0.12)
if (f.spring) {
return {
type: "spring" as const,
stiffness: f.spring.stiffness,
damping: f.spring.damping,
delay,
}
}
return { duration: f.duration, ease: "easeOut" as const, delay }
}
const fadeOnly = { opacity: 0 }
/* Shared shell: every flavour uses this, only Flavor changes. */
function MotionPalette({ props, flavor }: { props: CommandProps; flavor: Flavor }) {
const {
className,
size = "md",
placeholder = "Type a command...",
items = defaultItems,
} = props
const p = usePalette(items)
const reduce = useReducedMotion() ?? false
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}>
<AnimatePresence initial={false}>
{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}
layout={flavor.layout && !reduce ? true : undefined}
initial={reduce ? fadeOnly : flavor.initial}
animate={reduce ? { opacity: 1 } : flavor.animate}
exit={reduce ? fadeOnly : flavor.exit}
transition={rowTransition(flavor, i, reduce)}
onMouseEnter={() => p.setActive(i)}
onClick={() => p.select(i)}
className={cn(
optionBase,
"transition-colors",
i === p.active && "bg-accent text-accent-foreground"
)}
>
{item.icon}
<span className="flex-1 truncate">{item.label}</span>
</motion.div>
))}
</AnimatePresence>
{p.filtered.length === 0 ? <p className={emptyBase}>No results found.</p> : null}
</div>
</div>
)
}
/* SlideCommand: satirlar soldan kayarak girer, saga kayarak cikar. */
export function SlideCommand(props: CommandProps) {
return (
<MotionPalette
props={props}
flavor={{
initial: { opacity: 0, x: -12 },
animate: { opacity: 1, x: 0 },
exit: { opacity: 0, x: 12 },
duration: 0.18,
stagger: 0.02,
}}
/>
)
}
/* PopCommand: satirlar kucukten buyuyerek patlar. */
export function PopCommand(props: CommandProps) {
return (
<MotionPalette
props={props}
flavor={{
initial: { opacity: 0, scale: 0.9 },
animate: { opacity: 1, scale: 1 },
exit: { opacity: 0, scale: 0.9 },
duration: 0.16,
stagger: 0.015,
}}
/>
)
}
/* FadeCommand: opacity only; the calmest flavor. */
export function FadeCommand(props: CommandProps) {
return (
<MotionPalette
props={props}
flavor={{
initial: { opacity: 0 },
animate: { opacity: 1 },
exit: { opacity: 0 },
duration: 0.22,
stagger: 0.03,
}}
/>
)
}
/* SpringCommand: yay zamanlamasi ile asagidan gelir. */
export function SpringCommand(props: CommandProps) {
return (
<MotionPalette
props={props}
flavor={{
initial: { opacity: 0, y: 10 },
animate: { opacity: 1, y: 0 },
exit: { opacity: 0, y: -10 },
duration: 0.2,
stagger: 0.02,
spring: { stiffness: 420, damping: 30 },
}}
/>
)
}
/* MorphCommand: layout animasyonu ile kalan satirlar bosluga akar. */
export function MorphCommand(props: CommandProps) {
return (
<MotionPalette
props={props}
flavor={{
initial: { opacity: 0, scaleX: 0.94, y: 8 },
animate: { opacity: 1, scaleX: 1, y: 0 },
exit: { opacity: 0, scaleX: 0.94, y: -8 },
duration: 0.2,
stagger: 0.02,
layout: true,
}}
/>
)
}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.
Slide
Rows slide in from the left and leave to the right.
import { SlideCommand } from "@/components/ui/command-motion"
<SlideCommand />Pop
Rows pop in from a smaller scale.
import { PopCommand } from "@/components/ui/command-motion"
<PopCommand />Fade
Opacity only, the calmest flavor.
import { FadeCommand } from "@/components/ui/command-motion"
<FadeCommand />Spring
Rows rise into place on a spring.
import { SpringCommand } from "@/components/ui/command-motion"
<SpringCommand />Morph
Layout animation lets the remaining rows flow into the gap.
import { MorphCommand } from "@/components/ui/command-motion"
<MorphCommand />ai2 Motion command palettes: 5 styled variations on the token system
The ai2 Motion command palettes are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around command palettes that differ only in the motion of their rows. 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 animates every row in and out as the filter changes, with AnimatePresence handling the exit. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the transforms are skipped and rows only fade.
What is in the ai2 Motion command palettes?
5 exports in one file: Slide, Pop, Fade, Spring and Morph. 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 animates every row in and out as the filter changes, with AnimatePresence handling the exit.
- Reduced-motion aware: Under prefers-reduced-motion, the transforms are skipped and rows only fade.
- 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 Motion 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.