{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search-dialog",
  "title": "Search dialog",
  "description": "The search dialog's parts (SearchDialog, SearchDialogContent, SearchDialogInput, SearchDialogList, TagsList, ...) for building a search dialog for any Fumadocs search client, with highlighted matches and keyboard navigation.",
  "dependencies": [
    "@base-ui/react",
    "class-variance-authority",
    "cn",
    "@fuma-translate/react@^1.0.2",
    "fumadocs-core@^16.17.8",
    "lucide-react",
    "scroll-into-view-if-needed"
  ],
  "registryDependencies": [
    "kbd",
    "@docscn/search-context",
    "@docscn/docs-utils"
  ],
  "files": [
    {
      "path": "registry/base/docs/components/dialog/search.tsx",
      "content": "// Adapted from Fumadocs UI (https://github.com/fuma-nama/fumadocs)\n// Copyright (c) 2023 Fuma, MIT License\n\"use client\";\n\nimport { T, useTranslations } from \"@fuma-translate/react\";\nimport { ChevronRight, CircleAlert, Hash, SearchIcon } from \"lucide-react\";\nimport {\n  type ComponentProps,\n  createContext,\n  Fragment,\n  type ReactNode,\n  use,\n  useCallback,\n  useEffect,\n  useEffectEvent,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n  useSyncExternalStore,\n} from \"react\";\nimport { cn } from \"cn\";\nimport { Dialog } from \"@base-ui/react/dialog\";\nimport type { ReactSortedResult } from \"fumadocs-core/search\";\nimport {\n  useHighlightQuery,\n  type SearchResult,\n  type SearchResultItem,\n  type SearchResultRecord,\n  type SearchResultTable,\n} from \"fumadocs-core/search/client\";\nimport { toJsx, type ToJsxOptions } from \"fumadocs-core/utils/hast-to-jsx\";\nimport { cva } from \"class-variance-authority\";\nimport { useRouter } from \"fumadocs-core/framework\";\nimport type { SharedProps } from \"../../contexts/search\";\nimport scrollIntoView from \"scroll-into-view-if-needed\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport { mergeRefs } from \"../../utils/merge-refs\";\n\nexport type SearchItemType =\n  | ((ReactSortedResult | SearchResultRecord) & {\n      external?: boolean;\n    })\n  | {\n      id: string;\n      type: \"action\";\n      node: ReactNode;\n      onSelect: () => void;\n    };\n\ntype ItemRenderer = (props: {\n  item: SearchItemType;\n  table?: SearchResultTable;\n  onClick: () => void;\n}) => ReactNode;\n\ninterface TableProps {\n  table: SearchResultTable;\n  Item: ItemRenderer;\n  onSelect: (item: SearchItemType) => void;\n}\n\nexport type { SharedProps };\n\nexport interface SearchDialogProps extends SharedProps {\n  search: string;\n  onSearchChange: (v: string) => void;\n  onSelect?: (item: SearchItemType) => void;\n  isLoading?: boolean;\n  /** the last successful search, `<SearchDialogList />` shows its results */\n  data?: SearchResult;\n  /** the last search failed, `<SearchDialogList />` shows it above the results of `data` */\n  error?: Error;\n\n  children: ReactNode;\n}\n\nconst RootContext = createContext<{\n  open: boolean;\n  onOpenChange: (open: boolean) => void;\n  search: string;\n  onSearchChange: (v: string) => void;\n  onSelect: (item: SearchItemType) => void;\n  isLoading: boolean;\n  data?: SearchResult;\n  error?: Error;\n  /** the query to highlight */\n  query: string;\n  /** the id of the active item */\n  getActive: () => string | null;\n  setActive: (id: string | null) => void;\n  subscribeActive: (listener: () => void) => () => void;\n} | null>(null);\n\nconst TagsListContext = createContext<{\n  value?: string;\n  onValueChange: (value: string | undefined) => void;\n  allowClear: boolean;\n} | null>(null);\n\nconst mdComponents = {\n  // from the deprecated `highlightMarkdown()` of custom search clients\n  mark(props: ComponentProps<\"mark\">) {\n    return <span {...props} className=\"text-primary underline\" />;\n  },\n  a: \"span\" as const,\n  p(props: ComponentProps<\"p\">) {\n    return <p {...props} className=\"min-w-0\" />;\n  },\n  custom({\n    tagName,\n    children,\n    ...rest\n  }: Record<string, unknown> & { tagName: string; children?: ReactNode }) {\n    return (\n      <span className=\"inline-flex max-w-full items-center divide-x divide-border rounded-md border bg-card p-0.5 text-card-foreground\">\n        <code\n          data-highlight-ignore=\"\"\n          className=\"not-docs-typeset me-1 rounded-sm border-none bg-primary px-0.5 text-xs font-medium text-primary-foreground\"\n        >\n          {tagName}\n        </code>\n        {Object.entries(rest).map(([k, v]) => {\n          if (typeof v !== \"string\") return;\n\n          return (\n            <code\n              key={k}\n              data-highlight-ignore=\"\"\n              className=\"not-docs-typeset truncate px-1 text-xs text-muted-foreground\"\n            >\n              <span className=\"text-card-foreground\">{k}: </span>\n              {v}\n            </code>\n          );\n        })}\n        {children && <span className=\"ps-1\">{children}</span>}\n      </span>\n    );\n  },\n  pre(props: ComponentProps<\"pre\">) {\n    return (\n      <pre\n        {...props}\n        className={cn(\n          \"not-docs-typeset my-0.5 flex max-h-20 flex-col overflow-hidden rounded-md border bg-secondary p-2 text-secondary-foreground *:mask-[linear-gradient(to_bottom,white,white_30px,transparent_80px)]\",\n          props.className,\n        )}\n      />\n    );\n  },\n};\n\nconst renderOptions: ToJsxOptions = { components: mdComponents };\n\nfunction Children({ children }: { children?: ReactNode }) {\n  return children;\n}\n\nfunction TableCell(props: ComponentProps<\"div\">) {\n  return (\n    <div {...props} className=\"min-w-0 not-last:truncate last:line-clamp-2\" />\n  );\n}\n\n// tables of cards render their cells only, the grid of `<SearchDialogListTable />` lays them out\nconst tableRenderOptions: ToJsxOptions = {\n  components: {\n    ...mdComponents,\n    table: Children,\n    thead: Children,\n    tbody: Children,\n    tr: Children,\n    th: TableCell,\n    td: TableCell,\n  },\n};\n\n// rows of tables with header, `<SearchDialogListTable />` shows the header once\nconst rowRenderOptions: ToJsxOptions = {\n  components: { ...tableRenderOptions.components, thead: () => null },\n};\n\n/** A ref to the latest value, for callbacks that shouldn't change identity */\nfunction useLatest<T>(value: T) {\n  const ref = useRef(value);\n  useLayoutEffect(() => {\n    ref.current = value;\n  });\n  return ref;\n}\n\nfunction createActiveItem() {\n  let active: string | null = null;\n  const listeners = new Set<() => void>();\n\n  return {\n    getActive: () => active,\n    setActive(id: string | null) {\n      active = id;\n      for (const listener of listeners) listener();\n    },\n    subscribeActive(listener: () => void) {\n      listeners.add(listener);\n      return () => void listeners.delete(listener);\n    },\n  };\n}\n\nexport function SearchDialog({\n  open,\n  onOpenChange,\n  search,\n  onSearchChange,\n  isLoading = false,\n  data,\n  error,\n  onSelect: onSelectProp,\n  children,\n  dialogHandle,\n}: SearchDialogProps) {\n  const router = useRouter();\n  const onOpenChangeCallback = useLatest(onOpenChange);\n  const onSearchChangeCallback = useLatest(onSearchChange);\n  const onSelect = (item: SearchItemType) => {\n    if (item.type === \"action\") {\n      item.onSelect();\n    } else if (item.external) {\n      window.open(item.url, \"_blank\")?.focus();\n    } else {\n      router.push(item.url);\n    }\n\n    onOpenChange(false);\n    onSelectProp?.(item);\n  };\n  const onSelectCallback = useLatest(onSelect);\n  // the input and items subscribe to the active item, so only they re-render when it changes\n  const [activeItem] = useState(createActiveItem);\n\n  return (\n    <Dialog.Root open={open} onOpenChange={onOpenChange} handle={dialogHandle}>\n      <RootContext\n        value={useMemo(\n          () => ({\n            ...activeItem,\n            open,\n            search,\n            isLoading,\n            data,\n            error,\n            query: data ? data.query : search,\n            onOpenChange: (v) => onOpenChangeCallback.current(v),\n            onSearchChange: (v) => onSearchChangeCallback.current(v),\n            onSelect: (v) => onSelectCallback.current(v),\n          }),\n          [\n            activeItem,\n            isLoading,\n            open,\n            search,\n            data,\n            error,\n            onOpenChangeCallback,\n            onSearchChangeCallback,\n            onSelectCallback,\n          ],\n        )}\n      >\n        {children}\n      </RootContext>\n    </Dialog.Root>\n  );\n}\n\nexport function SearchDialogHeader(props: ComponentProps<\"div\">) {\n  return (\n    <div\n      {...props}\n      className={cn(\"flex flex-row items-center gap-2 p-3\", props.className)}\n    />\n  );\n}\n\nexport function SearchDialogInput(props: ComponentProps<\"input\">) {\n  const { search, onSearchChange, getActive, subscribeActive } = useSearch();\n  const active = useSyncExternalStore(subscribeActive, getActive, getActive);\n  const t = useTranslations({ note: \"search dialog\" });\n\n  return (\n    <input\n      data-fd-search-dialog-input=\"\"\n      role=\"combobox\"\n      aria-expanded={active !== null}\n      aria-activedescendant={\n        active !== null ? `fd-search-option-${active}` : undefined\n      }\n      aria-label={t(\"Search\")}\n      aria-autocomplete=\"list\"\n      aria-controls=\"fd-search-list\"\n      value={search}\n      onChange={(e) => onSearchChange(e.target.value)}\n      placeholder={t(\"Search\")}\n      {...props}\n      className={cn(\n        \"w-0 flex-1 bg-transparent text-lg placeholder:text-muted-foreground focus-visible:outline-none\",\n        props.className,\n      )}\n    />\n  );\n}\n\nexport function SearchDialogClose({\n  children = \"ESC\",\n  className,\n  ...props\n}: ComponentProps<\"button\">) {\n  const { onOpenChange } = useSearch();\n  const t = useTranslations({ note: \"search dialog\" });\n\n  return (\n    <button\n      type=\"button\"\n      aria-label={t(\"Close Search\", { note: \"aria-label\" })}\n      onClick={() => onOpenChange(false)}\n      className={cn(\n        \"rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n        className,\n      )}\n      {...props}\n    >\n      <Kbd className=\"font-mono\">{children}</Kbd>\n    </button>\n  );\n}\n\nexport function SearchDialogFooter(props: ComponentProps<\"div\">) {\n  return (\n    <div\n      {...props}\n      className={cn(\"bg-muted/50 p-3 empty:hidden\", props.className)}\n    />\n  );\n}\n\nexport function SearchDialogOverlay({\n  className,\n  ...props\n}: ComponentProps<typeof Dialog.Backdrop>) {\n  return (\n    <Dialog.Backdrop\n      {...props}\n      className={(s) =>\n        cn(\n          \"fixed inset-0 z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0\",\n          typeof className === \"function\" ? className(s) : className,\n        )\n      }\n    />\n  );\n}\n\nexport function SearchDialogContent({\n  ref,\n  children,\n  className,\n  ...props\n}: ComponentProps<typeof Dialog.Popup>) {\n  const t = useTranslations({ note: \"search dialog\" });\n  const localRef = useRef<HTMLDivElement>(null);\n\n  return (\n    <Dialog.Portal>\n      <Dialog.Popup\n        id=\"fd-search-dialog-content\"\n        ref={mergeRefs(ref, localRef)}\n        aria-describedby={undefined}\n        initialFocus={(s) => {\n          const input = localRef.current?.querySelector<HTMLInputElement>(\n            \"input[data-fd-search-dialog-input]\",\n          );\n          if (s === \"touch\") {\n            input?.focus({ preventScroll: true });\n            return false;\n          }\n          return input;\n        }}\n        className={(s) =>\n          cn(\n            \"fixed top-4 left-1/2 z-50 w-[calc(100%-1rem)] max-w-screen-sm -translate-x-1/2 overflow-hidden rounded-xl bg-popover text-popover-foreground shadow-2xl ring-1 ring-foreground/10 duration-100 focus-visible:outline-none md:top-[calc(50%-250px)] data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95\",\n            \"*:border-b *:last:border-b-0 *:has-[+:last-child[data-empty=true]]:border-b-0 *:data-[empty=true]:border-b-0\",\n            typeof className === \"function\" ? className(s) : className,\n          )\n        }\n        {...props}\n      >\n        <Dialog.Title className=\"hidden\">{t(\"Search\")}</Dialog.Title>\n        {children}\n      </Dialog.Popup>\n    </Dialog.Portal>\n  );\n}\n\nexport function SearchDialogList({\n  items: itemsProp,\n  defaultItems = null,\n  Empty = () => (\n    <div\n      role=\"status\"\n      className=\"py-12 text-center text-sm text-muted-foreground\"\n    >\n      <T text=\"No results found\" note=\"search dialog\" />\n    </div>\n  ),\n  Item = (props) => <SearchDialogListItem {...props} />,\n  Table = (props) => <SearchDialogListTable {...props} />,\n  ...props\n}: Omit<ComponentProps<\"div\">, \"children\"> & {\n  /** @defaultValue the results of `data` from `<SearchDialog />` */\n  items?: (SearchItemType | SearchResultItem)[] | null;\n  /** shown without results */\n  defaultItems?: (SearchItemType | SearchResultItem)[] | null;\n  /**\n   * Renderer for empty list UI\n   */\n  Empty?: () => ReactNode;\n  /**\n   * Renderer for items\n   */\n  Item?: ItemRenderer;\n  /**\n   * Renderer for tables, `Item` and `onSelect` render their rows\n   */\n  Table?: (props: TableProps) => ReactNode;\n}) {\n  const ref = useRef<HTMLDivElement>(null);\n  const t = useTranslations({ note: \"search dialog\" });\n  const { onSelect, data, error, getActive, setActive } = useSearch();\n  const items =\n    itemsProp === undefined ? (data?.items ?? defaultItems) : itemsProp;\n\n  useLayoutEffect(\n    () => setActive(error ? null : (items?.[0]?.id ?? null)),\n    [setActive, items, error],\n  );\n\n  const onKey = useEffectEvent((e: KeyboardEvent) => {\n    if (!items || e.isComposing || e.keyCode === 229) return;\n    const list = flattenItems(items);\n\n    if (e.key === \"ArrowDown\" || e.key == \"ArrowUp\") {\n      let idx = list.findIndex((item) => item.id === getActive());\n      if (idx === -1) idx = 0;\n      else if (e.key === \"ArrowDown\") idx++;\n      else idx--;\n\n      setActive(list.at(idx % list.length)?.id ?? null);\n      e.preventDefault();\n    }\n\n    if (e.key === \"Enter\") {\n      const selected = list.find((item) => item.id === getActive());\n\n      if (selected) onSelect(selected);\n      e.preventDefault();\n    }\n  });\n\n  useEffect(() => {\n    const element = ref.current;\n    if (!element) return;\n\n    const observer = new ResizeObserver(() => {\n      let height = 0;\n      for (const child of element.children)\n        height += (child as HTMLElement).offsetHeight;\n\n      element.style.setProperty(\"--fd-animated-height\", `${height}px`);\n    });\n\n    for (const child of element.children) observer.observe(child);\n\n    const content: Pick<Window, \"addEventListener\" | \"removeEventListener\"> =\n      document.getElementById(\"fd-search-dialog-content\") ?? window;\n    content.addEventListener(\"keydown\", onKey);\n    return () => {\n      observer.disconnect();\n      content.removeEventListener(\"keydown\", onKey);\n    };\n  }, []);\n\n  return (\n    <div\n      {...props}\n      ref={ref}\n      data-empty={items === null && !error}\n      className={cn(\n        \"h-(--fd-animated-height) overflow-hidden transition-[height] [&_::highlight(fd-search)]:text-primary [&_::highlight(fd-search)]:underline\",\n        props.className,\n      )}\n    >\n      <p\n        role=\"status\"\n        className={cn(\n          \"truncate text-sm not-empty:p-3\",\n          items && \"not-empty:border-b\",\n        )}\n      >\n        {error && (\n          <>\n            <CircleAlert className=\"me-2 inline size-5 align-top text-destructive\" />\n            {data ? (\n              <T\n                text=\"Search failed, showing results for {query}\"\n                note=\"search dialog\"\n                variables={{\n                  query: <span className=\"font-medium\">{data.query}</span>,\n                }}\n              />\n            ) : (\n              <T text=\"Search failed\" note=\"search dialog\" />\n            )}\n          </>\n        )}\n      </p>\n      <div\n        id=\"fd-search-list\"\n        // an empty listbox is invalid, expose it only with options\n        role={items?.length ? \"listbox\" : undefined}\n        aria-label={items?.length ? t(\"Search\") : undefined}\n        className={cn(\n          \"flex max-h-[460px] w-full flex-col overflow-y-auto p-1\",\n          !items && \"hidden\",\n        )}\n      >\n        {items?.length === 0 && Empty()}\n\n        {items?.map((item) => (\n          <Fragment key={item.id}>\n            {item.type === \"table\"\n              ? Table({ table: item, Item, onSelect })\n              : Item({ item, onClick: () => onSelect(item) })}\n          </Fragment>\n        ))}\n      </div>\n    </div>\n  );\n}\n\nfunction flattenItems(\n  items: (SearchItemType | SearchResultItem)[],\n): SearchItemType[] {\n  const out: SearchItemType[] = [];\n  for (const item of items) {\n    if (item.type === \"table\") out.push(...item.rows);\n    else out.push(item);\n  }\n\n  return out;\n}\n\nexport function SearchDialogListTable({ table, Item, onSelect }: TableProps) {\n  const { query } = useSearch();\n  const highlightRef = useHighlightQuery(query);\n  const headerId = `fd-search-table-${table.id}`;\n  const header = useMemo(\n    () => table.header && toJsx(table.header, tableRenderOptions),\n    [table.header],\n  );\n\n  return (\n    <div\n      // the header names the rows\n      role={table.header ? \"group\" : undefined}\n      aria-labelledby={table.header ? headerId : undefined}\n      className=\"ms-3 shrink-0 border-s py-2 ps-3.25 pe-2.5\"\n    >\n      <div\n        className=\"grid gap-x-3 overflow-hidden rounded-lg border bg-card text-sm\"\n        style={{\n          gridTemplateColumns: `${\"fit-content(30%) \".repeat(table.columns - 1)}minmax(30%, 1fr)`,\n        }}\n      >\n        {header && (\n          <div\n            id={headerId}\n            ref={highlightRef}\n            aria-hidden\n            className=\"col-span-full grid grid-cols-subgrid bg-secondary px-3 py-1 text-xs text-muted-foreground\"\n          >\n            {header}\n          </div>\n        )}\n        {table.rows.map((row) => (\n          <Fragment key={row.id}>\n            {Item({ item: row, table, onClick: () => onSelect(row) })}\n          </Fragment>\n        ))}\n      </div>\n    </div>\n  );\n}\n\nexport function SearchDialogListItem({\n  item,\n  table,\n  className,\n  children,\n  renderMarkdown,\n  ...props\n}: ComponentProps<\"div\"> & {\n  /** the table of a row */\n  table?: SearchResultTable;\n  /** render the Markdown `content` of items, instead of their `hastContent` */\n  renderMarkdown?: (v: string) => ReactNode;\n  item: SearchItemType;\n}) {\n  const { query, getActive, setActive, subscribeActive } = useSearch();\n  const isActive = () => getActive() === item.id;\n  const active = useSyncExternalStore(subscribeActive, isActive, isActive);\n  const highlightRef = useHighlightQuery(query);\n  const content = useMemo(() => {\n    if (item.type === \"action\") return item.node;\n    if (renderMarkdown && typeof item.content === \"string\")\n      return renderMarkdown(item.content);\n    if (!(\"hastContent\" in item)) return item.content;\n    if (!table) return toJsx(item.hastContent, renderOptions);\n    return toJsx(\n      item.hastContent,\n      table.header ? rowRenderOptions : tableRenderOptions,\n    );\n  }, [item, renderMarkdown, table]);\n\n  if (item.type === \"action\") {\n    children ??= content;\n  } else if (table) {\n    children ??= (\n      <div\n        ref={highlightRef}\n        className={cn(\n          \"contents\",\n          // rows without header, like the props of type tables\n          !table.header &&\n            \"*:not-first:text-muted-foreground *:first:font-medium *:first:text-primary *:nth-2:text-xs\",\n        )}\n      >\n        {content}\n      </div>\n    );\n  } else {\n    children ??= (\n      <>\n        <div className=\"inline-flex items-center text-xs text-muted-foreground empty:hidden\">\n          {item.breadcrumbs?.map((item, i) => (\n            <Fragment key={i}>\n              {i > 0 && <ChevronRight className=\"size-4 rtl:rotate-180\" />}\n              {item}\n            </Fragment>\n          ))}\n        </div>\n\n        {item.type !== \"page\" && (\n          <div\n            role=\"none\"\n            className=\"absolute inset-y-0 inset-s-3 w-px bg-border\"\n          />\n        )}\n        {item.type === \"heading\" && (\n          <Hash className=\"absolute inset-s-6 top-2.5 size-4 text-muted-foreground\" />\n        )}\n        <div\n          ref={highlightRef}\n          className={cn(\n            \"docs-typeset min-w-0 text-sm\",\n            item.type === \"text\" && \"ps-4\",\n            item.type === \"heading\" && \"ps-8\",\n            item.type === \"page\" || item.type === \"heading\"\n              ? \"font-medium text-inherit\"\n              : \"text-popover-foreground/80\",\n          )}\n        >\n          {content}\n        </div>\n      </>\n    );\n  }\n\n  return (\n    <div\n      id={`fd-search-option-${item.id}`}\n      role=\"option\"\n      ref={useCallback(\n        (element: HTMLDivElement | null) => {\n          if (active && element) {\n            scrollIntoView(element, {\n              scrollMode: \"if-needed\",\n              block: \"nearest\",\n              boundary: element.closest('[role=\"listbox\"]'),\n            });\n          }\n        },\n        [active],\n      )}\n      aria-selected={active}\n      className={cn(\n        \"cursor-default\",\n        table\n          ? \"col-span-full grid grid-cols-subgrid items-baseline px-3 py-1.5 not-first:border-t\"\n          : \"relative shrink-0 overflow-hidden rounded-lg px-2.5 py-2 text-sm\",\n        active && \"bg-accent text-accent-foreground\",\n        className,\n      )}\n      onPointerMove={() => setActive(item.id)}\n      {...props}\n    >\n      {children}\n    </div>\n  );\n}\n\nexport function SearchDialogIcon(props: ComponentProps<\"svg\">) {\n  const { isLoading } = useSearch();\n\n  return (\n    <SearchIcon\n      {...props}\n      className={cn(\n        \"size-5 text-muted-foreground\",\n        isLoading && \"animate-pulse duration-400\",\n        props.className,\n      )}\n    />\n  );\n}\n\nexport interface TagsListProps extends ComponentProps<\"div\"> {\n  tag?: string;\n  onTagChange: (tag: string | undefined) => void;\n  allowClear?: boolean;\n}\n\nconst itemVariants = cva(\n  \"rounded-md border px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors\",\n  {\n    variants: {\n      active: {\n        true: \"bg-accent text-accent-foreground\",\n      },\n    },\n  },\n);\nexport function TagsList({\n  tag,\n  onTagChange,\n  allowClear = false,\n  ...props\n}: TagsListProps) {\n  const onTagChangeCallback = useLatest(onTagChange);\n  return (\n    <div\n      {...props}\n      className={cn(\"flex flex-wrap items-center gap-1\", props.className)}\n    >\n      <TagsListContext\n        value={useMemo(\n          () => ({\n            value: tag,\n            onValueChange: (v) => onTagChangeCallback.current(v),\n            allowClear,\n          }),\n          [allowClear, tag, onTagChangeCallback],\n        )}\n      >\n        {props.children}\n      </TagsListContext>\n    </div>\n  );\n}\n\nexport function TagsListItem({\n  value,\n  className,\n  ...props\n}: ComponentProps<\"button\"> & {\n  value: string;\n}) {\n  const { onValueChange, value: selectedValue, allowClear } = useTagsList();\n  const selected = value === selectedValue;\n\n  return (\n    <button\n      type=\"button\"\n      data-active={selected}\n      className={cn(itemVariants({ active: selected, className }))}\n      onClick={() => onValueChange(selected && allowClear ? undefined : value)}\n      tabIndex={-1}\n      {...props}\n    >\n      {props.children}\n    </button>\n  );\n}\n\nexport function useSearch() {\n  const ctx = use(RootContext);\n  if (!ctx) throw new Error(\"Missing <SearchDialog />\");\n  return ctx;\n}\n\nexport function useTagsList() {\n  const ctx = use(TagsListContext);\n  if (!ctx) throw new Error(\"Missing <TagsList />\");\n  return ctx;\n}\n",
      "type": "registry:component",
      "target": "@components/docs/components/dialog/search.tsx"
    }
  ],
  "type": "registry:component"
}