{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"search-box-placeholder-that-types-product-suggestions","type":"registry:component","title":"Search Box with Typing Placeholder","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/search-box-placeholder-that-types-product-suggestions.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Suggestions typed into the placeholder. Typing stops as soon as the field is focused or filled.\nconst SUGGESTIONS = [\"brass cabinet hinges\", \"linseed oil for oak\", \"a cast iron door knocker\", \"wood glue that sets fast\"];\nconst STATIC_HINT = \"Search hinges, oils, tools and more\";\n\nexport default function SearchPlaceholderTyper() {\n  const rootRef = useRef<HTMLElement>(null);\n  const [hint, setHint] = useState(`Try: ${SUGGESTIONS[0]}`);\n  const [active, setActive] = useState(false);\n  const [value, setValue] = useState(\"\");\n  const reduce = useReducedMotion();\n  const stopped = active || value.length > 0 || !!reduce;\n\n  useEffect(() => {\n    const el = rootRef.current;\n    if (!el || stopped) return;\n    let alive = true;\n    let visible = true;\n    let timer = 0;\n    let resume: null | (() => void) = null;\n    const wait = (ms: number) =>\n      new Promise<void>((done) => {\n        const go = () => { timer = window.setTimeout(done, ms); };\n        if (visible) go();\n        else resume = go;\n      });\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && resume) { const r = resume; resume = null; r(); }\n    });\n    io.observe(el);\n    (async () => {\n      let i = 0;\n      await wait(800);\n      while (alive) {\n        const cur = SUGGESTIONS[i];\n        for (let n = cur.length; n >= 0 && alive; n--) { setHint(`Try: ${cur.slice(0, n)}`); await wait(22); }\n        i = (i + 1) % SUGGESTIONS.length;\n        const next = SUGGESTIONS[i];\n        await wait(260);\n        for (let n = 1; n <= next.length && alive; n++) {\n          setHint(`Try: ${next.slice(0, n)}`);\n          await wait(55 + Math.random() * 60 + (next[n - 1] === \" \" ? 60 : 0));\n        }\n        await wait(1600);\n      }\n    })();\n    return () => { alive = false; window.clearTimeout(timer); io.disconnect(); };\n  }, [stopped]);\n\n  return (\n    <section ref={rootRef} className=\"bg-gradient-to-b from-[#e3f0ec] to-[#cfe4de] px-4 py-20 sm:py-24\">\n      <div className=\"mx-auto max-w-xl text-center\">\n        <h2 className=\"font-serif text-3xl font-medium text-[#12403a] sm:text-4xl\">Pennick &amp; Sons Hardware</h2>\n        <p className=\"mt-3 text-base text-[#2f5a53]\">Four floors of fittings, finishes and hand tools, all in stock.</p>\n        <form role=\"search\" className=\"mt-8\" onSubmit={(e) => e.preventDefault()}>\n          <label htmlFor=\"sph-q\" className=\"sr-only\">Search the shop</label>\n          <div className=\"flex items-center gap-2 rounded-2xl border border-[#9cc3b9] bg-white p-2 shadow-[0_18px_40px_-24px_rgba(18,64,58,0.45)] focus-within:border-[#12403a]\">\n            <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" className=\"ml-2 h-5 w-5 shrink-0 text-[#3f6b64]\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\"><circle cx=\"11\" cy=\"11\" r=\"7\" /><path d=\"m20 20-3.5-3.5\" /></svg>\n            <input\n              id=\"sph-q\"\n              type=\"search\"\n              value={value}\n              onChange={(e) => setValue(e.target.value)}\n              onFocus={() => setActive(true)}\n              onBlur={() => setActive(false)}\n              placeholder={stopped ? STATIC_HINT : hint}\n              className=\"h-11 min-w-0 flex-1 bg-transparent text-base text-[#12403a] placeholder:text-[#4b6b66] focus:outline-none\"\n            />\n            <button type=\"submit\" className=\"h-11 shrink-0 rounded-xl bg-[#12403a] px-4 text-sm font-semibold text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#12403a] focus-visible:ring-offset-2\">Search</button>\n          </div>\n        </form>\n        <p className=\"mt-4 text-sm text-[#2f5a53]\">Popular this week: hinges, beeswax, chisels</p>\n      </div>\n    </section>\n  );\n}\n"}]}
