{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"motion-combobox","type":"registry:component","title":"Combobox (Motion)","description":"Combobox with motion: its list is the Motion edition's Command, so one highlight glides from option to option and the height follows what matches; the picked option's tick draws itself and a new value rises into the field.","dependencies":["lucide-react","motion"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-locale.json","https://dashral.com/r/motion-field.json","https://dashral.com/r/motion-reduced.json","https://dashral.com/r/button.json","https://dashral.com/r/combobox.json","https://dashral.com/r/command.json","https://dashral.com/r/field.json","https://dashral.com/r/popover.json","https://dashral.com/r/motion-command.json"],"files":[{"path":"registry/dashral/motion/combobox.tsx","type":"registry:file","target":"components/dashral/motion/combobox.tsx","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronsUpDownIcon } from \"lucide-react\"\nimport { AnimatePresence, motion } from \"motion/react\"\nimport { Button } from \"../button\"\nimport type { ComboboxOption } from \"../combobox\"\nimport { CommandRoot } from \"../command\"\nimport { FieldWrapper, splitFieldProps, useFieldControl, type FieldClassNames, type FieldControlProps, type FieldOwnProps } from \"../field\"\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from \"../popover\"\nimport { useLocale } from \"../lib/locale\"\nimport { cn } from \"../lib/utils\"\n\nimport { motionMessages } from \"../lib/motion-field\"\nimport { useReducedMotion } from \"../lib/motion-reduced\"\nimport { CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from \"./command\"\n\nexport type { ComboboxOption } from \"../combobox\"\n\n/** The smooth curve every move uses: no spring, no overshoot. */\nconst smooth = [0.4, 0, 0.2, 1] as const\n\nexport type ComboboxProps = FieldOwnProps & {\n  options: ComboboxOption[]\n  /** Controlled value. Omit it (and use defaultValue) for an uncontrolled combobox. */\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  placeholder?: string\n  searchPlaceholder?: string\n  emptyText?: string\n  id?: string\n  disabled?: boolean\n  required?: boolean\n  \"aria-invalid\"?: React.AriaAttributes[\"aria-invalid\"]\n  /** The trigger's classes. */\n  className?: string\n  \"aria-label\"?: string\n  classNames?: FieldClassNames & { trigger?: string; content?: string; item?: string }\n}\n\n/**\n * The kit's Combobox with motion: the same options, icons, descriptions and props. Its list is the Motion edition's\n * Command: one highlight glides from option to option, the list's height follows what matches as you type, and the\n * options rise in as it opens. The picked option's tick draws itself, and a new value rises into the field as the old\n * one leaves upward. Its hint and error come and go like the other motion fields. With reduced motion it only fades.\n */\nexport function Combobox(props: ComboboxProps) {\n  const [field, { required: _required, ...control }] = splitFieldProps(props)\n  return (\n    <FieldWrapper {...field} renderMessages={motionMessages}>\n      <ComboboxControl {...control} />\n    </FieldWrapper>\n  )\n}\n\nfunction ComboboxControl({\n  options,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  placeholder: placeholderProp,\n  searchPlaceholder: searchPlaceholderProp,\n  emptyText: emptyTextProp,\n  className,\n  classNames,\n  \"aria-label\": ariaLabel,\n  ...rest\n}: Omit<ComboboxProps, keyof FieldOwnProps | \"required\">) {\n  const { t } = useLocale()\n  const reduced = useReducedMotion()\n  const emptyText = emptyTextProp ?? t(\"noResults\")\n  const searchPlaceholder = searchPlaceholderProp ?? t(\"search\")\n  const placeholder = placeholderProp ?? t(\"selectOption\")\n  const { id, disabled, ...aria } = useFieldControl<FieldControlProps>({ id: rest.id, disabled: rest.disabled, \"aria-invalid\": rest[\"aria-invalid\"] })\n  const [open, setOpen] = React.useState(false)\n  const [internal, setInternal] = React.useState(defaultValue)\n  const current = value ?? internal\n  const selected = options.find((option) => option.value === current)\n\n  function select(next: string) {\n    const newValue = next === current ? \"\" : next\n    if (value === undefined) setInternal(newValue)\n    onValueChange?.(newValue)\n    setOpen(false)\n  }\n\n  return (\n    <PopoverRoot open={open} onOpenChange={setOpen}>\n      <PopoverTrigger asChild>\n        <Button\n          id={id}\n          variant=\"outline\"\n          role=\"combobox\"\n          aria-expanded={open}\n          aria-label={ariaLabel}\n          aria-describedby={aria[\"aria-describedby\"]}\n          aria-invalid={aria[\"aria-invalid\"]}\n          disabled={disabled}\n          className={cn(\n            \"w-full min-w-0 justify-between font-normal aria-invalid:border-destructive\",\n            // Looks like the other fields (Input, Select), not like a button.\n            \"border-input bg-transparent hover:bg-transparent focus-visible:border-ring focus-visible:ring-ring/15 motion-safe:enabled:not-aria-busy:active:scale-100\",\n            selected ? \"hover:text-foreground\" : \"text-muted-foreground hover:text-muted-foreground\",\n            className,\n            classNames?.trigger\n          )}\n        >\n          {/* The value as shown: a new one rises in over the old, which leaves upward, in the same place. */}\n          <span className=\"relative grid min-w-0 flex-1 justify-items-start overflow-hidden\">\n            <AnimatePresence mode=\"popLayout\" initial={false}>\n              <motion.span\n                key={current || \"placeholder\"}\n                className=\"col-start-1 row-start-1 flex min-w-0 items-center gap-2\"\n                initial={reduced ? { opacity: 0 } : { opacity: 0, y: 8 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={reduced ? { opacity: 0 } : { opacity: 0, y: -8, transition: { duration: 0.16, ease: smooth } }}\n                transition={{ duration: 0.26, ease: smooth }}\n              >\n                {selected?.icon}\n                <span className=\"truncate\">{selected?.label ?? placeholder}</span>\n              </motion.span>\n            </AnimatePresence>\n          </span>\n          <ChevronsUpDownIcon className=\"opacity-50\" aria-hidden />\n        </Button>\n      </PopoverTrigger>\n      <PopoverContent className={cn(\"w-(--radix-popover-trigger-width) min-w-48 p-0\", classNames?.content)} align=\"start\">\n        <CommandRoot>\n          <CommandInput placeholder={searchPlaceholder} />\n          <CommandList>\n            <CommandEmpty>{emptyText}</CommandEmpty>\n            <CommandGroup className=\"overflow-visible\">\n              {options.map((option) => (\n                <CommandItem\n                  key={option.value}\n                  value={option.label}\n                  keywords={option.description ? [option.description] : undefined}\n                  disabled={option.disabled}\n                  onSelect={() => select(option.value)}\n                  className={classNames?.item}\n                >\n                  {/* The tick draws itself on the picked option. */}\n                  <svg viewBox=\"0 0 24 24\" aria-hidden className=\"size-4 shrink-0 fill-none stroke-current stroke-2 [stroke-linecap:round] [stroke-linejoin:round]\">\n                    <motion.path\n                      d=\"M4 12l5 5L20 6\"\n                      initial={reduced ? false : { pathLength: 0 }}\n                      animate={{ pathLength: option.value === current ? 1 : 0, opacity: option.value === current ? 1 : 0 }}\n                      transition={{ pathLength: { duration: 0.24, ease: smooth, delay: 0.08 }, opacity: { duration: 0.01 } }}\n                    />\n                  </svg>\n                  {option.icon}\n                  {option.description ? (\n                    <span className=\"grid min-w-0\">\n                      <span className=\"truncate\">{option.label}</span>\n                      <span className=\"truncate text-xs text-muted-foreground\">{option.description}</span>\n                    </span>\n                  ) : (\n                    option.label\n                  )}\n                </CommandItem>\n              ))}\n            </CommandGroup>\n          </CommandList>\n        </CommandRoot>\n      </PopoverContent>\n    </PopoverRoot>\n  )\n}\n"}]}