{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"motion-command","type":"registry:component","title":"Command (Motion)","description":"Command with motion: one highlight glides from item to item after the arrow keys or the pointer, the list's height follows what matches as you type, and the palette grows out of what opened it.","dependencies":["cmdk","lucide-react","motion"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-locale.json","https://dashral.com/r/motion-reduced.json","https://dashral.com/r/command.json","https://dashral.com/r/motion-dialog.json"],"files":[{"path":"registry/dashral/motion/command.tsx","type":"registry:file","target":"components/dashral/motion/command.tsx","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { Command as CommandPrimitive, useCommandState } from \"cmdk\"\nimport { LayoutGroup, motion } from \"motion/react\"\nimport type { CommandDialogProps, CommandProps } from \"../command\"\nimport { CommandRoot, CommandShortcut, CommandSeparator, CommandGroup } from \"../command\"\nimport { useLocale } from \"../lib/locale\"\nimport { cn } from \"../lib/utils\"\nimport { SearchIcon } from \"lucide-react\"\n\nimport { useReducedMotion } from \"../lib/motion-reduced\"\nimport { Dialog } from \"./dialog\"\n\nexport type { CommandAction, CommandDialogProps, CommandProps, CommandSection } from \"../command\"\nexport { CommandRoot, CommandShortcut, CommandSeparator, CommandGroup } from \"../command\"\n\n/** The smooth curve every move uses: no spring, no overshoot. */\nconst smooth = [0.4, 0, 0.2, 1] as const\n\n// Whether the list has just opened: its items rise in one after another then, and only then. An item that comes back\n// as the search changes only fades in, so typing never sets the whole list moving.\nconst OpeningContext = React.createContext<React.RefObject<boolean> | null>(null)\n\n/** The search field, as the kit's. */\nfunction CommandInput({ className, ...props }: React.ComponentProps<typeof CommandPrimitive.Input>) {\n  return (\n    <div data-slot=\"command-input-wrapper\" cmdk-input-wrapper=\"\" className=\"flex h-10 items-center gap-2 border-b px-3\">\n      <SearchIcon className=\"size-4 shrink-0 opacity-50\" aria-hidden />\n      <CommandPrimitive.Input\n        data-slot=\"command-input\"\n        className={cn(\n          \"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n          className\n        )}\n        {...props}\n      />\n    </div>\n  )\n}\n\n/**\n * The list: its height glides to fit what matches as you type (cmdk measures it into --cmdk-list-height). It's also\n * where the highlight lives (one per list) and where items know the list has just opened.\n */\nfunction CommandList({ className, children, ...props }: React.ComponentProps<typeof CommandPrimitive.List>) {\n  // The first moment after the list shows: items there rise in; later ones (the search loosening) only fade.\n  const opening = React.useRef(true)\n  React.useEffect(() => {\n    const timer = setTimeout(() => (opening.current = false), 400)\n    return () => clearTimeout(timer)\n  }, [])\n  const group = React.useId()\n  return (\n    <CommandPrimitive.List\n      data-slot=\"command-list\"\n      className={cn(\n        // isolate: one layer for the whole list, where the highlight sits under every item's text. A layer per item\n        // would put the pill, in the item it's going to, over the text of the one it's leaving: going down, that text\n        // would blink out as the pill passed over it.\n        \"isolate h-[min(var(--cmdk-list-height),20rem)] max-h-80 scroll-py-1 overflow-x-hidden overflow-y-auto overscroll-contain transition-[height] duration-[280ms] ease-[cubic-bezier(0.4,0,0.2,1)] motion-reduce:transition-none\",\n        className\n      )}\n      {...props}\n    >\n      <OpeningContext value={opening}>\n        <LayoutGroup id={group}>{children}</LayoutGroup>\n      </OpeningContext>\n    </CommandPrimitive.List>\n  )\n}\n\n/** Shown when nothing matches; it fades in. */\nfunction CommandEmpty({ className, ...props }: React.ComponentProps<typeof CommandPrimitive.Empty>) {\n  return (\n    <CommandPrimitive.Empty\n      data-slot=\"command-empty\"\n      className={cn(\"animate-in py-6 text-center text-sm text-muted-foreground duration-(--duration-standard) ease-enter fade-in-0\", className)}\n      {...props}\n    />\n  )\n}\n\n/**\n * An item. The highlight is one pill for the whole list, gliding to the item the arrow keys or the pointer are on;\n * the item itself only changes its text color.\n */\nfunction CommandItem({ className, children, ...props }: React.ComponentProps<typeof CommandPrimitive.Item>) {\n  const reduced = useReducedMotion()\n  const opening = React.useContext(OpeningContext)\n  const ref = React.useRef<HTMLDivElement>(null)\n  // cmdk writes the item's value (given, or its text) on it as data-value; the list's current one is in its state.\n  const [own, setOwn] = React.useState<string | null>(null)\n  React.useLayoutEffect(() => setOwn(ref.current?.getAttribute(\"data-value\") ?? null), [props.value, children])\n  const selected = useCommandState((state) => state.value)\n  const [rise] = React.useState(() => !reduced && Boolean(opening?.current))\n  return (\n    <CommandPrimitive.Item\n      ref={ref}\n      data-slot=\"command-item\"\n      className={cn(\n        \"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground\",\n        className\n      )}\n      {...props}\n    >\n      {own !== null && selected === own && (\n        <motion.span\n          layoutId=\"command-highlight\"\n          // No crossfade between the pill it leaves and the one it becomes: the new one would start from nothing and\n          // blink as the pointer passes from item to item. It moves, it never fades.\n          layoutCrossfade={false}\n          aria-hidden\n          className=\"absolute inset-0 -z-10 rounded-sm bg-accent\"\n          style={{ opacity: 1 }}\n          transition={reduced ? { duration: 0 } : { duration: 0.22, ease: smooth }}\n        />\n      )}\n      <motion.span\n        className=\"flex min-w-0 flex-1 items-center gap-2\"\n        initial={reduced ? false : rise ? { opacity: 0, y: 4 } : { opacity: 0 }}\n        animate={{ opacity: 1, y: 0 }}\n        transition={{ duration: rise ? 0.26 : 0.16, ease: smooth }}\n      >\n        {children}\n      </motion.span>\n    </CommandPrimitive.Item>\n  )\n}\n\nfunction CommandBody({ groups, placeholder, emptyText }: Pick<CommandProps, \"groups\" | \"placeholder\" | \"emptyText\">) {\n  return (\n    <>\n      <CommandInput placeholder={placeholder} />\n      <CommandList>\n        <CommandEmpty>{emptyText}</CommandEmpty>\n        {groups.map((section, g) => (\n          <React.Fragment key={g}>\n            {g > 0 && !section.heading && <CommandSeparator />}\n            {/* Not clipped, so the highlight crossing from one group to the next isn't cut at the edge. */}\n            <CommandGroup heading={section.heading} className=\"overflow-visible\">\n              {section.items.map((item, i) => (\n                <CommandItem\n                  key={i}\n                  value={item.value ?? (typeof item.label === \"string\" ? item.label : undefined)}\n                  keywords={item.keywords}\n                  disabled={item.disabled}\n                  onSelect={item.onSelect}\n                >\n                  {item.icon}\n                  {item.label}\n                  {item.badge ? <span className=\"ms-auto\">{item.badge}</span> : item.shortcut ? <CommandShortcut>{item.shortcut}</CommandShortcut> : null}\n                </CommandItem>\n              ))}\n            </CommandGroup>\n          </React.Fragment>\n        ))}\n      </CommandList>\n    </>\n  )\n}\n\n/**\n * The kit's Command with motion: the same groups, items, shortcuts and props. The highlight is one pill gliding from\n * item to item after the arrow keys or the pointer; the list's height glides to fit what matches as you type; when it\n * first shows, the items rise in one after another. With reduced motion nothing moves.\n */\nexport function Command({ groups, placeholder: placeholderProp, emptyText: emptyTextProp, className, ...props }: CommandProps) {\n  const { t } = useLocale()\n  return (\n    <CommandRoot className={cn(\"rounded-lg border shadow-md\", className)} {...props}>\n      <CommandBody groups={groups} placeholder={placeholderProp ?? t(\"search\")} emptyText={emptyTextProp ?? t(\"noResults\")} />\n    </CommandRoot>\n  )\n}\n\n/**\n * The command palette with motion: the Motion edition's Dialog (it grows out of what opened it and swipes down to close\n * on a phone) holding the same list, its pill gliding and its height following the search.\n */\nexport function CommandDialog({\n  groups,\n  placeholder: placeholderProp,\n  emptyText: emptyTextProp,\n  title: titleProp,\n  description: descriptionProp,\n  className,\n  ...props\n}: CommandDialogProps) {\n  const { t } = useLocale()\n  return (\n    <Dialog\n      title={titleProp ?? t(\"commandTitle\")}\n      description={descriptionProp ?? t(\"commandDescription\")}\n      showCloseButton={false}\n      className={cn(\"top-[20%] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-lg\", className)}\n      classNames={{ header: \"sr-only\" }}\n      {...props}\n    >\n      <CommandRoot className=\"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:size-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-2.5\">\n        <CommandBody groups={groups} placeholder={placeholderProp ?? t(\"commandPlaceholder\")} emptyText={emptyTextProp ?? t(\"noResults\")} />\n      </CommandRoot>\n    </Dialog>\n  )\n}\n\nexport { CommandInput, CommandList, CommandEmpty, CommandItem }\n"}],"cssVars":{"theme":{"ease-standard":"var(--ease-standard)","ease-enter":"var(--ease-enter)","ease-exit":"var(--ease-exit)","ease-spring":"var(--ease-spring)"},"light":{"duration-fast":"160ms","duration-standard":"240ms","duration-considered":"480ms","ease-standard":"cubic-bezier(0.2, 0, 0, 1)","ease-enter":"cubic-bezier(0, 0, 0, 1)","ease-exit":"cubic-bezier(0.3, 0, 1, 1)","ease-spring":"linear(0, 0.071 4%, 0.234 8%, 0.433 12%, 0.626 17%, 0.791 21%, 0.917 25%, 1.004 29%, 1.055 33%, 1.079 38%, 1.083 42%, 1.075 46%, 1.06 50%, 1.043 54%, 1.027 58%, 1.015 62%, 1.005 67%, 0.998 71%, 0.995 75%, 0.993 79%, 0.993 83%, 0.994 88%, 0.995 92%, 0.997 96%, 1)"},"dark":{}}}