{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "typewriter-search-hero",
  "title": "Typewriter Search Hero",
  "description": "A search-first hero whose box types out example searches by itself, then hands over to real search with live suggestions, highlighted matches and full keyboard support.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/typewriter-search-hero/typewriter-search-hero.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type TypewriterHeroTheme = \"dark\" | \"light\";\n\nexport interface SearchSuggestion {\n  title: string;\n  /** Second line, e.g. a place or a price. */\n  meta?: string;\n  href?: string;\n}\n\nexport interface TypewriterSearchHeroProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\" | \"onSelect\"\n> {\n  theme?: TypewriterHeroTheme;\n  eyebrow?: string;\n  title?: string;\n  description?: string;\n  /** Phrases the search box types out, one after another. */\n  phrases?: string[];\n  /** Word typed before each phrase, e.g. \"Find\". */\n  prefix?: string;\n  /** Matches shown under the box as people type. */\n  suggestions?: SearchSuggestion[];\n  /** Quick searches under the box. */\n  chips?: string[];\n  /** Small facts along the bottom. */\n  stats?: { value: string; label: string }[];\n  /** Milliseconds per typed letter. */\n  speed?: number;\n  /** Height from tablet width up, in px. */\n  minHeight?: number;\n  onSearch?: (query: string) => void;\n  onSelect?: (suggestion: SearchSuggestion) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0B0B0C\",\n    text: \"#F4F4F2\",\n    sub: \"rgba(244,244,242,0.6)\",\n    faint: \"rgba(244,244,242,0.36)\",\n    border: \"rgba(255,255,255,0.12)\",\n    field: \"#151517\",\n    list: \"#161618\",\n    hover: \"rgba(255,255,255,0.07)\",\n    chip: \"rgba(255,255,255,0.06)\",\n    ring: \"rgba(255,255,255,0.32)\",\n    btn: \"#F4F4F2\",\n    btnText: \"#0B0B0C\",\n    mark: \"#F4F4F2\",\n    shadow: \"0 30px 80px -30px rgba(0,0,0,0.9)\",\n    halo: \"rgba(255,255,255,0.075)\",\n  },\n  light: {\n    bg: \"#F6F5F1\",\n    text: \"#141412\",\n    sub: \"rgba(20,20,18,0.62)\",\n    faint: \"rgba(20,20,18,0.4)\",\n    border: \"rgba(20,20,18,0.12)\",\n    field: \"#FFFFFF\",\n    list: \"#FFFFFF\",\n    hover: \"rgba(20,20,18,0.05)\",\n    chip: \"rgba(20,20,18,0.05)\",\n    ring: \"rgba(20,20,18,0.3)\",\n    btn: \"#141412\",\n    btnText: \"#F6F5F1\",\n    mark: \"#141412\",\n    shadow: \"0 30px 70px -34px rgba(60,50,30,0.4)\",\n    halo: \"rgba(20,20,18,0.07)\",\n  },\n};\n\nconst DEFAULT_PHRASES = [\n  \"a cabin with a sauna near Bergen\",\n  \"a quiet flat in old Lisbon\",\n  \"a stone house above Kaş\",\n  \"somewhere with a long table for twelve\",\n];\n\nconst DEFAULT_SUGGESTIONS: SearchSuggestion[] = [\n  { title: \"Fjord cabin with sauna\", meta: \"Bergen, Norway · €184 a night\" },\n  { title: \"Forest cabin, wood stove\", meta: \"Dalarna, Sweden · €126 a night\" },\n  { title: \"Tiled flat in Alfama\", meta: \"Lisbon, Portugal · €98 a night\" },\n  {\n    title: \"Rooftop flat near the river\",\n    meta: \"Porto, Portugal · €112 a night\",\n  },\n  { title: \"Stone house with sea view\", meta: \"Kaş, Türkiye · €140 a night\" },\n  {\n    title: \"Olive farm with a long table\",\n    meta: \"Puglia, Italy · €310 a night\",\n  },\n  { title: \"Lake house for twelve\", meta: \"Bled, Slovenia · €420 a night\" },\n];\n\nconst DEFAULT_CHIPS = [\"Sauna\", \"Sea view\", \"Sleeps 12\", \"Pets welcome\"];\n\nconst DEFAULT_STATS = [\n  { value: \"12,400\", label: \"homes\" },\n  { value: \"86\", label: \"countries\" },\n  { value: \"4.9\", label: \"average stay\" },\n];\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction matches(item: SearchSuggestion, query: string) {\n  const hay = `${item.title} ${item.meta ?? \"\"}`.toLowerCase();\n  return query\n    .toLowerCase()\n    .split(/\\s+/)\n    .filter(Boolean)\n    .every((word) => hay.includes(word));\n}\n\n/** The title with the typed words picked out. */\nfunction Highlight({\n  text,\n  query,\n  color,\n}: {\n  text: string;\n  query: string;\n  color: string;\n}) {\n  const words = query.trim().split(/\\s+/).filter(Boolean);\n  if (!words.length) return <>{text}</>;\n  const safe = words.map((w) => w.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"));\n  const parts = text.split(new RegExp(`(${safe.join(\"|\")})`, \"gi\"));\n  return (\n    <>\n      {parts.map((part, i) =>\n        i % 2 ? (\n          <strong key={i} className=\"font-semibold\" style={{ color }}>\n            {part}\n          </strong>\n        ) : (\n          <React.Fragment key={i}>{part}</React.Fragment>\n        ),\n      )}\n    </>\n  );\n}\n\nexport function TypewriterSearchHero({\n  theme = \"dark\",\n  eyebrow = \"Homes worth the trip\",\n  title = \"Tell us where you'd rather be\",\n  description = \"Describe it the way you would to a friend. We'll find the place.\",\n  phrases = DEFAULT_PHRASES,\n  prefix = \"Find\",\n  suggestions = DEFAULT_SUGGESTIONS,\n  chips = DEFAULT_CHIPS,\n  stats = DEFAULT_STATS,\n  speed = 46,\n  minHeight = 720,\n  onSearch,\n  onSelect,\n  className,\n  style,\n  ...props\n}: TypewriterSearchHeroProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const listId = React.useId();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [query, setQuery] = React.useState(\"\");\n  const [focused, setFocused] = React.useState(false);\n  const [active, setActive] = React.useState(-1);\n  const [typed, setTyped] = React.useState(\"\");\n\n  const results = React.useMemo(\n    () =>\n      query.trim()\n        ? suggestions.filter((s) => matches(s, query)).slice(0, 5)\n        : suggestions.slice(0, 4),\n    [query, suggestions],\n  );\n  const open = focused;\n  const idle = !focused && !query;\n\n  // Type a phrase, wait, delete it, move on. Everything stops as soon as someone is using the box.\n  React.useEffect(() => {\n    if (!idle || reduce || !phrases.length) return;\n    let phrase = 0;\n    let length = 0;\n    let deleting = false;\n    let timer = 0;\n    const tick = () => {\n      const text = phrases[phrase % phrases.length];\n      if (deleting) {\n        length -= 1;\n        setTyped(text.slice(0, length));\n        if (length === 0) {\n          deleting = false;\n          phrase += 1;\n          timer = window.setTimeout(tick, 320);\n        } else timer = window.setTimeout(tick, speed * 0.42);\n      } else {\n        length += 1;\n        setTyped(text.slice(0, length));\n        if (length === text.length) {\n          deleting = true;\n          timer = window.setTimeout(tick, 1700);\n        } else {\n          timer = window.setTimeout(\n            tick,\n            speed * (0.7 + ((length * 7) % 5) / 6),\n          );\n        }\n      }\n    };\n    timer = window.setTimeout(tick, 420);\n    return () => window.clearTimeout(timer);\n  }, [idle, reduce, phrases, speed]);\n\n  const submit = (text: string) => {\n    if (text.trim()) onSearch?.(text.trim());\n  };\n  const choose = (item: SearchSuggestion) => {\n    setQuery(item.title);\n    setActive(-1);\n    inputRef.current?.blur();\n    onSelect?.(item);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      if (!results.length) return;\n      const dir = e.key === \"ArrowDown\" ? 1 : -1;\n      setActive(\n        (i) =>\n          (i + dir + results.length + (i < 0 && dir < 0 ? 1 : 0)) %\n          results.length,\n      );\n    } else if (e.key === \"Enter\") {\n      e.preventDefault();\n      if (active >= 0 && results[active]) choose(results[active]);\n      else {\n        submit(query);\n        inputRef.current?.blur();\n      }\n    } else if (e.key === \"Escape\") {\n      inputRef.current?.blur();\n    }\n  };\n\n  const shown = reduce ? phrases[0] : typed;\n  return (\n    <section\n      className={cn(\"@container relative w-full\", className)}\n      style={\n        {\n          \"--h\": `${minHeight}px`,\n          background: pal.bg,\n          color: pal.text,\n          fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\",\n          ...style,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      <div className=\"relative flex min-h-[620px] flex-col items-center justify-center px-5 pt-14 pb-24 @[640px]:min-h-[var(--h)]\">\n        <div\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute inset-0 overflow-hidden\"\n        >\n          {[420, 660, 900, 1140].map((d) => (\n            <span\n              key={d}\n              className=\"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full\"\n              style={{\n                width: d,\n                height: d,\n                boxShadow: `inset 0 0 0 1px ${pal.halo}`,\n              }}\n            />\n          ))}\n        </div>\n\n        <div className=\"relative flex w-full max-w-[680px] flex-col items-center text-center\">\n          <p\n            className=\"m-0 text-[13.5px] font-medium\"\n            style={{ color: pal.sub }}\n          >\n            {eyebrow}\n          </p>\n          <h1 className=\"m-0 mt-3 max-w-[15ch] text-[42px] leading-[1.02] font-medium tracking-[-0.035em] @[640px]:text-[64px]\">\n            {title}\n          </h1>\n          <p\n            className=\"m-0 mt-4 max-w-[44ch] text-[15.5px] leading-snug\"\n            style={{ color: pal.sub }}\n          >\n            {description}\n          </p>\n\n          <form\n            role=\"search\"\n            onSubmit={(e) => e.preventDefault()}\n            className=\"relative z-20 mt-8 w-full text-left\"\n          >\n            <div\n              className=\"flex h-[60px] items-center gap-3 rounded-2xl pr-2 pl-5 transition-shadow\"\n              style={{\n                background: pal.field,\n                boxShadow: `inset 0 0 0 1px ${focused ? pal.ring : pal.border}, ${pal.shadow}`,\n              }}\n            >\n              <svg\n                width=\"18\"\n                height=\"18\"\n                viewBox=\"0 0 18 18\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"1.7\"\n                strokeLinecap=\"round\"\n                aria-hidden=\"true\"\n                className=\"shrink-0\"\n                style={{ color: pal.faint }}\n              >\n                <circle cx=\"8\" cy=\"8\" r=\"5.6\" />\n                <path d=\"m12.4 12.4 3.6 3.6\" />\n              </svg>\n              <div className=\"relative h-full min-w-0 flex-1\">\n                <input\n                  ref={inputRef}\n                  value={query}\n                  role=\"combobox\"\n                  aria-label={title}\n                  aria-expanded={open}\n                  aria-controls={listId}\n                  aria-autocomplete=\"list\"\n                  aria-activedescendant={\n                    active >= 0 ? `${listId}-${active}` : undefined\n                  }\n                  autoComplete=\"off\"\n                  onChange={(e) => {\n                    setQuery(e.target.value);\n                    setActive(-1);\n                  }}\n                  onFocus={() => setFocused(true)}\n                  onBlur={() => {\n                    setFocused(false);\n                    setActive(-1);\n                  }}\n                  onKeyDown={onKeyDown}\n                  className=\"absolute inset-0 w-full bg-transparent text-[16px] outline-none\"\n                  style={{ color: pal.text }}\n                />\n                {!query && (\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"pointer-events-none absolute inset-0 flex items-center overflow-hidden text-[16px] whitespace-nowrap\"\n                    style={{ color: pal.sub }}\n                  >\n                    {focused ? (\n                      \"Describe your place\"\n                    ) : (\n                      <>\n                        {prefix} {shown}\n                        <span\n                          className=\"ml-px inline-block h-[1.15em] w-[1.5px]\"\n                          style={{ background: pal.text }}\n                        />\n                      </>\n                    )}\n                  </span>\n                )}\n              </div>\n              <button\n                type=\"button\"\n                onMouseDown={(e) => e.preventDefault()}\n                onClick={() => submit(query)}\n                className=\"h-11 shrink-0 cursor-pointer rounded-xl px-5 text-[14px] font-semibold transition-opacity hover:opacity-85\"\n                style={{ background: pal.btn, color: pal.btnText }}\n              >\n                Search\n              </button>\n            </div>\n\n            {/* Laid over the page, so opening it never moves anything underneath. */}\n            <div\n              id={listId}\n              role=\"listbox\"\n              aria-label=\"Suggestions\"\n              hidden={!open}\n              className=\"absolute inset-x-0 top-[calc(100%+8px)] overflow-hidden rounded-2xl p-1.5\"\n              style={{\n                background: pal.list,\n                boxShadow: `inset 0 0 0 1px ${pal.border}, ${pal.shadow}`,\n              }}\n            >\n              {results.length === 0 ? (\n                <p\n                  className=\"m-0 px-3 py-3 text-[13.5px]\"\n                  style={{ color: pal.sub }}\n                >\n                  Nothing close yet. Press Enter to search everything.\n                </p>\n              ) : (\n                results.map((item, i) => (\n                  <a\n                    key={item.title}\n                    id={`${listId}-${i}`}\n                    role=\"option\"\n                    aria-selected={i === active}\n                    href={item.href}\n                    onMouseDown={(e) => e.preventDefault()}\n                    onMouseEnter={() => setActive(i)}\n                    onClick={() => choose(item)}\n                    className=\"block cursor-pointer rounded-xl px-3 py-2 no-underline\"\n                    style={{\n                      background: i === active ? pal.hover : \"transparent\",\n                      color: pal.sub,\n                    }}\n                  >\n                    <span className=\"block text-[14.5px]\">\n                      <Highlight\n                        text={item.title}\n                        query={query}\n                        color={pal.mark}\n                      />\n                    </span>\n                    {item.meta && (\n                      <span\n                        className=\"block text-[12.5px]\"\n                        style={{ color: pal.faint }}\n                      >\n                        {item.meta}\n                      </span>\n                    )}\n                  </a>\n                ))\n              )}\n            </div>\n          </form>\n\n          {chips.length > 0 && (\n            <div className=\"mt-4 flex flex-wrap justify-center gap-2\">\n              {chips.map((chip) => (\n                <button\n                  key={chip}\n                  type=\"button\"\n                  onClick={() => {\n                    setQuery(chip);\n                    setActive(-1);\n                    inputRef.current?.focus();\n                  }}\n                  className=\"h-8 cursor-pointer rounded-full px-3.5 text-[13px] font-medium transition-opacity hover:opacity-75\"\n                  style={{ background: pal.chip, color: pal.sub }}\n                >\n                  {chip}\n                </button>\n              ))}\n            </div>\n          )}\n        </div>\n\n        {stats.length > 0 && (\n          <dl className=\"absolute inset-x-0 bottom-7 m-0 flex justify-center gap-8 @[640px]:gap-14\">\n            {stats.map((s) => (\n              <div key={s.label} className=\"flex items-baseline gap-1.5\">\n                <dd className=\"m-0 text-[14px] font-semibold tabular-nums\">\n                  {s.value}\n                </dd>\n                <dt className=\"text-[13px]\" style={{ color: pal.faint }}>\n                  {s.label}\n                </dt>\n              </div>\n            ))}\n          </dl>\n        )}\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}