{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search-field",
  "title": "Search field",
  "description": "A search box with a clear button, an inline error or note and an optional help popover.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "src/components/blocks/search-field.tsx",
      "content": "\"use client\";\n\n// Search field with a clear button and an optional help popover. Built from\n// the React Bits Pro App UI input box and popover (navbar-2), mapped onto this\n// app's tokens. Used by the Explorer's hand search.\n\nimport { useEffect, useId, useRef, useState, type ReactNode } from \"react\";\nimport { CircleHelp, Search, X } from \"lucide-react\";\n\nexport function SearchField({\n  value,\n  onChange,\n  label,\n  placeholder,\n  error,\n  note,\n  helpLabel = \"Search help\",\n  examples,\n  help,\n}: {\n  value: string;\n  onChange: (next: string) => void;\n  /** Screen-reader label for the field. */\n  label: string;\n  placeholder?: string;\n  /** Error to show under the field (marks it invalid). */\n  error?: string | null;\n  /** A non-error message under the field. */\n  note?: string | null;\n  helpLabel?: string;\n  /** Clickable examples at the top of the help popover. */\n  examples?: { code: string; text: string }[];\n  /** Help popover body; the ? button appears only when given. */\n  help?: ReactNode;\n}) {\n  const [open, setOpen] = useState(false);\n  const wrap = useRef<HTMLDivElement>(null);\n  const inputRef = useRef<HTMLInputElement>(null);\n  const helpId = useId();\n  const msgId = useId();\n\n  useEffect(() => {\n    if (!open) return;\n    const onDown = (e: PointerEvent) => {\n      if (wrap.current && !wrap.current.contains(e.target as Node))\n        setOpen(false);\n    };\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false);\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"pointerdown\", onDown);\n      document.removeEventListener(\"keydown\", onKey);\n    };\n  }, [open]);\n\n  return (\n    <div ref={wrap} className=\"relative flex flex-col gap-1.5\">\n      <div className=\"flex items-center gap-2\">\n        <label\n          className={`relative flex h-9 min-w-0 flex-1 cursor-text items-center gap-2 rounded-[var(--rb-r-sm,6px)] border bg-background px-2.5 shadow-[0_1px_2px_-1px_rgb(0_0_0/0.12)] transition-[border-color,box-shadow] focus-within:ring-3 focus-within:ring-foreground/8 ${\n            error\n              ? \"border-destructive\"\n              : \"border-border hover:border-foreground/30 focus-within:border-foreground/60\"\n          }`}\n        >\n          <Search\n            aria-hidden\n            className=\"size-4 shrink-0 text-muted-foreground\"\n          />\n          <span className=\"sr-only\">{label}</span>\n          <input\n            ref={inputRef}\n            value={value}\n            onChange={(e) => onChange(e.target.value)}\n            placeholder={placeholder}\n            spellCheck={false}\n            autoCapitalize=\"off\"\n            autoComplete=\"off\"\n            aria-invalid={error ? true : undefined}\n            aria-describedby={error || note ? msgId : undefined}\n            className=\"h-full min-w-0 flex-1 bg-transparent font-mono text-[13px] text-foreground outline-none placeholder:font-sans placeholder:text-muted-foreground\"\n          />\n          {value ? (\n            <button\n              type=\"button\"\n              aria-label=\"Clear search\"\n              onClick={() => {\n                onChange(\"\");\n                inputRef.current?.focus();\n              }}\n              className=\"inline-flex size-6 items-center justify-center rounded-[var(--rb-r-xs,4px)] text-muted-foreground hover:bg-accent hover:text-foreground\"\n            >\n              <X className=\"size-3.5\" />\n            </button>\n          ) : null}\n        </label>\n        {help ? (\n          <button\n            type=\"button\"\n            aria-label={helpLabel}\n            aria-expanded={open}\n            aria-controls={helpId}\n            onClick={() => setOpen((o) => !o)}\n            className={`inline-flex size-9 shrink-0 items-center justify-center rounded-[var(--rb-r-sm,6px)] border border-border bg-background text-muted-foreground shadow-[0_1px_2px_-1px_rgb(0_0_0/0.12)] transition-colors hover:border-foreground/30 hover:text-foreground ${\n              open ? \"bg-accent text-foreground\" : \"\"\n            }`}\n          >\n            <CircleHelp className=\"size-4\" />\n          </button>\n        ) : null}\n      </div>\n\n      {error ? (\n        <p id={msgId} className=\"text-xs text-destructive\">\n          {error}\n        </p>\n      ) : note ? (\n        <p id={msgId} className=\"text-xs text-muted-foreground\">\n          {note}\n        </p>\n      ) : null}\n\n      {open ? (\n        <div\n          id={helpId}\n          role=\"dialog\"\n          aria-label={helpLabel}\n          className=\"absolute right-0 top-11 z-30 flex max-h-[min(70vh,560px)] w-[min(440px,calc(100vw-2rem))] flex-col gap-4 overflow-y-auto rounded-[var(--rb-r-lg,10px)] border border-border bg-popover p-4 text-popover-foreground shadow-[0_12px_24px_-12px_rgb(0_0_0/0.35)]\"\n        >\n          {examples?.length ? (\n            <section className=\"flex flex-col gap-1.5\">\n              <h3 className=\"text-[12px] font-medium uppercase tracking-wide text-muted-foreground\">\n                Examples\n              </h3>\n              {examples.map(({ code, text }) => (\n                <button\n                  key={code}\n                  type=\"button\"\n                  onClick={() => {\n                    onChange(code);\n                    setOpen(false);\n                    inputRef.current?.focus();\n                  }}\n                  className=\"grid grid-cols-[minmax(0,9.5rem)_1fr] items-baseline gap-3 rounded-[var(--rb-r-xs,4px)] px-1 py-0.5 text-left hover:bg-accent\"\n                >\n                  <code className=\"truncate font-mono text-[12px] text-foreground\">\n                    {code}\n                  </code>\n                  <span className=\"text-[12px] text-muted-foreground\">\n                    {text}\n                  </span>\n                </button>\n              ))}\n            </section>\n          ) : null}\n          {help}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/search-field.tsx"
    }
  ],
  "type": "registry:component"
}