{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "autocomplete",
  "title": "Autocomplete",
  "description": "A text field that suggests as you type: the text is the value, and a suggestion only fills it in. The list grows out of the field and moves to the height of what still matches, while one highlight glides between the rows.",
  "dependencies": [
    "@ui-sdk/react"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/popup.json",
    "https://kinoui.com/r/label.json",
    "https://kinoui.com/r/input.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/filter-list.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/autocomplete.tsx",
      "content": "'use client'\n\nimport { buttonVariants } from '@/registry/components/kino/button'\nimport { fieldClearClassName } from '@/registry/components/kino/input'\nimport { labelClassName } from '@/registry/components/kino/label'\nimport {\n  FilterListBody,\n  FilterListChevron,\n  FilterListClearIcon,\n  FilterListInputGroup,\n  FilterListRows,\n  filterListButtonClassName,\n  filterListContentClassName,\n  filterListGroupLabelClassName,\n  filterListInputClassName,\n  filterListItemClassName,\n  filterListMatchClassName,\n  filterListNoticeClassName,\n  filterListScrollerClassName,\n  filterListSeparatorClassName,\n} from '@/registry/lib/filter-list'\nimport { POPUP_COLLISION_PADDING, usePopupPresentation } from '@/registry/lib/popup'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport { useEdgeFades } from '@/registry/lib/scroll'\nimport {\n  Autocomplete as AutocompletePrimitive,\n  AutocompleteClear as AutocompleteClearPrimitive,\n  AutocompleteContent as AutocompleteContentPrimitive,\n  AutocompleteEmpty as AutocompleteEmptyPrimitive,\n  AutocompleteGroup as AutocompleteGroupPrimitive,\n  AutocompleteGroupLabel as AutocompleteGroupLabelPrimitive,\n  AutocompleteInput as AutocompleteInputPrimitive,\n  AutocompleteItem as AutocompleteItemPrimitive,\n  AutocompleteItemIcon as AutocompleteItemIconPrimitive,\n  AutocompleteItemText as AutocompleteItemTextPrimitive,\n  AutocompleteLabel as AutocompleteLabelPrimitive,\n  AutocompleteList as AutocompleteListPrimitive,\n  type AutocompleteProps,\n  AutocompleteSeparator as AutocompleteSeparatorPrimitive,\n  AutocompleteStatus as AutocompleteStatusPrimitive,\n  AutocompleteTrigger as AutocompleteTriggerPrimitive,\n} from '@ui-sdk/react/autocomplete'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  use,\n  useMemo,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * ui-sdk's Autocomplete, whose value is the text itself, with the look the\n * lists with an input share (`registry/lib/filter-list`), as the Combobox\n * has it. The box grows out of the field, and as you type it moves to the\n * height of what still matches while one highlight glides between the rows.\n */\n\ntype AutocompleteContextValue = {\n  /** Where the motion preference is read, for `presentation='auto'`. */\n  setControl: (element: HTMLElement | null) => void\n  /** The field's box, which the suggestions open under and are as wide as. */\n  group: HTMLElement | null\n  setGroup: (element: HTMLElement | null) => void\n}\n\nconst AutocompleteContext = createContext<AutocompleteContextValue | null>(null)\n\n/**\n * The root. With `presentation='auto'`, a small touch screen opens the\n * suggestions as a sheet, unless motion is reduced (`popupPresentation`).\n */\nfunction Autocomplete(props: AutocompleteProps) {\n  const [shown, setControl] = usePopupPresentation(props.presentation ?? 'popover')\n  const [group, setGroup] = useState<HTMLElement | null>(null)\n  const context = useMemo(() => ({ setControl, group, setGroup }), [setControl, group])\n  return (\n    <AutocompleteContext value={context}>\n      <AutocompletePrimitive {...props} presentation={shown} />\n    </AutocompleteContext>\n  )\n}\n\nfunction AutocompleteLabel({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteLabelPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteLabelPrimitive className={cn(labelClassName, className)} {...props} />\n  )\n}\n\n/**\n * The field: the input and the buttons beside it, in the box every text\n * control has. The suggestions open under it.\n */\nfunction AutocompleteInputGroup({\n  ref,\n  ...props\n}: ComponentProps<typeof FilterListInputGroup>) {\n  const context = use(AutocompleteContext)\n  const refs = useMemo(() => mergeRefs(ref, context?.setGroup), [ref, context])\n  return <FilterListInputGroup ref={refs} data-autocomplete-input-group='' {...props} />\n}\n\n/** The text you type, which is the value. */\nfunction AutocompleteInput({\n  className,\n  ref,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteInputPrimitive>, 'className'> & {\n  className?: string\n}) {\n  const setControl = use(AutocompleteContext)?.setControl\n  const refs = useMemo(() => mergeRefs(ref, setControl), [ref, setControl])\n  return (\n    <AutocompleteInputPrimitive\n      ref={refs}\n      className={cn(filterListInputClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/** Empties the field; it shows only while there is text. */\nfunction AutocompleteClear({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteClearPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteClearPrimitive\n      data-field-clear=''\n      aria-label='Clear'\n      className={cn(\n        buttonVariants({ variant: 'ghost', size: 'icon-xs' }),\n        filterListButtonClassName,\n        fieldClearClassName,\n        className,\n      )}\n      {...props}\n    >\n      {children ?? <FilterListClearIcon />}\n    </AutocompleteClearPrimitive>\n  )\n}\n\n/** The chevron at the end of the field: opens the suggestions that match its text. */\nfunction AutocompleteTrigger({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteTriggerPrimitive>, 'className' | 'children'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteTriggerPrimitive\n      aria-label='Show suggestions'\n      className={cn(\n        buttonVariants({ variant: 'ghost', size: 'icon-xs' }),\n        filterListButtonClassName,\n        className,\n      )}\n      {...props}\n    >\n      <FilterListChevron />\n    </AutocompleteTriggerPrimitive>\n  )\n}\n\n/**\n * The box under the field. `className` goes on the box's content; every\n * other prop goes to ui-sdk's content.\n */\nfunction AutocompleteContent({\n  className,\n  children,\n  side = 'bottom',\n  align = 'start',\n  sideOffset = 6,\n  anchor,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteContentPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const group = use(AutocompleteContext)?.group\n  return (\n    <AutocompleteContentPrimitive\n      data-filter-list-content=''\n      side={side}\n      align={align}\n      sideOffset={sideOffset}\n      collisionPadding={POPUP_COLLISION_PADDING}\n      arrowPadding={0}\n      anchor={anchor ?? group ?? undefined}\n      className={filterListContentClassName}\n      {...props}\n    >\n      {({ presentation }) => (\n        <FilterListBody presentation={presentation} className={className}>\n          {children}\n        </FilterListBody>\n      )}\n    </AutocompleteContentPrimitive>\n  )\n}\n\n/**\n * The suggestions, with the highlight that glides between them: rows and\n * groups of your own, or a function of `{ items }`, the ones that still\n * match, when the autocomplete takes `items`.\n */\nfunction AutocompleteList({\n  className,\n  children,\n  ref,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteListPrimitive>, 'className'> & {\n  className?: string\n}) {\n  const fades = useEdgeFades<HTMLDivElement>()\n  const refs = useMemo(() => mergeRefs(ref, fades), [ref, fades])\n  return (\n    <AutocompleteListPrimitive\n      ref={refs}\n      className={filterListScrollerClassName}\n      {...props}\n    >\n      {(state) => (\n        <FilterListRows className={className}>\n          {typeof children === 'function' ? children(state) : children}\n        </FilterListRows>\n      )}\n    </AutocompleteListPrimitive>\n  )\n}\n\n/**\n * A suggestion: the menus' row. Picking it puts its text in the field, or\n * its `label` where it holds more than text.\n */\nfunction AutocompleteItem({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteItemPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteItemPrimitive\n      data-menu-row=''\n      className={cn(filterListItemClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/**\n * A suggestion's text with the part that matches what was typed in bold, so\n * the eye finds why it matched. Without children, its `label` or value.\n */\nfunction AutocompleteItemText({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteItemTextPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteItemTextPrimitive\n      className={cn(filterListMatchClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/** A suggestion's icon, before its text. */\nfunction AutocompleteItemIcon({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteItemIconPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteItemIconPrimitive\n      className={cn(\n        \"flex shrink-0 items-center [&_svg:not([class*='text-'])]:text-muted-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction AutocompleteGroup(props: ComponentProps<typeof AutocompleteGroupPrimitive>) {\n  return <AutocompleteGroupPrimitive {...props} />\n}\n\nfunction AutocompleteGroupLabel({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteGroupLabelPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteGroupLabelPrimitive\n      className={cn(filterListGroupLabelClassName, className)}\n      {...props}\n    />\n  )\n}\n\nfunction AutocompleteSeparator({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteSeparatorPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteSeparatorPrimitive\n      className={cn(filterListSeparatorClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/** What shows when nothing matches, announced as it appears: say what was looked for. */\nfunction AutocompleteEmpty({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteEmptyPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteEmptyPrimitive\n      className={cn(filterListNoticeClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/** Announces a search that is running, or how many suggestions it found. */\nfunction AutocompleteStatus({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AutocompleteStatusPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AutocompleteStatusPrimitive\n      className={cn(filterListNoticeClassName, className)}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Autocomplete,\n  AutocompleteClear,\n  AutocompleteContent,\n  AutocompleteEmpty,\n  AutocompleteGroup,\n  AutocompleteGroupLabel,\n  AutocompleteInput,\n  AutocompleteInputGroup,\n  AutocompleteItem,\n  AutocompleteItemIcon,\n  AutocompleteItemText,\n  AutocompleteLabel,\n  AutocompleteList,\n  AutocompleteSeparator,\n  AutocompleteStatus,\n  AutocompleteTrigger,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/autocomplete.tsx"
    }
  ],
  "type": "registry:component"
}