{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "vanish-input",
  "title": "Vanish input",
  "description": "Search field with rotating, blurred-in placeholder hints; on submit the typed text dissolves into drifting particles drawn on a canvas.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/inputs/vanish-input.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { ArrowRight } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, spring, ease as easing } from \"@/lib/goodui-motion\"\n\ntype Particle = { x: number; y: number; vx: number; vy: number; r: number; a: number; delay: number; color: string }\n\nexport type VanishInputProps = Omit<React.ComponentProps<\"form\">, \"onSubmit\" | \"defaultValue\"> & {\n  /** Hints that rotate while the field is empty. */\n  placeholders?: string[]\n  /** Milliseconds between placeholder changes. */\n  interval?: number\n  /** Controlled text. It is set to \"\" when the text is submitted. */\n  value?: string\n  /** Initial text when uncontrolled. */\n  defaultValue?: string\n  /** Called on every keystroke, and with \"\" when the text is submitted. */\n  onValueChange?: (value: string) => void\n  /** Called with the text when the user presses Enter or the arrow button; the text then dissolves. */\n  onSubmit?: (value: string) => void\n  /** Accessible name of the input (defaults to the first placeholder). */\n  label?: string\n  /** aria-label of the arrow submit button. */\n  submitLabel?: string\n  /** name attribute of the text input, for native form handling. */\n  name?: string\n  /** Classes for the native input; `className` styles the pill-shaped form. */\n  inputClassName?: string\n}\n\n/** Input with rotating placeholders whose text dissolves into particles when submitted. */\nexport function VanishInput({\n  placeholders = [\"Search…\"],\n  interval = 3000,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  onSubmit,\n  label,\n  submitLabel = \"Submit\",\n  name,\n  className,\n  inputClassName,\n  ...props\n}: VanishInputProps) {\n  const reduce = useReducedMotion() ?? false\n  const [inner, setInner] = React.useState(defaultValue)\n  const text = value ?? inner\n  const [index, setIndex] = React.useState(0)\n  const [vanishing, setVanishing] = React.useState(false)\n  const inputRef = React.useRef<HTMLInputElement>(null)\n  const canvasRef = React.useRef<HTMLCanvasElement>(null)\n  const raf = React.useRef(0)\n\n  const setText = (v: string) => {\n    if (value === undefined) setInner(v)\n    onValueChange?.(v)\n  }\n\n  // Rotate placeholders while visible; pause in background tabs.\n  React.useEffect(() => {\n    if (placeholders.length < 2 || text) return\n    let t = 0\n    const start = () => {\n      window.clearInterval(t)\n      if (!document.hidden) t = window.setInterval(() => setIndex((i) => (i + 1) % placeholders.length), interval)\n    }\n    start()\n    document.addEventListener(\"visibilitychange\", start)\n    return () => {\n      window.clearInterval(t)\n      document.removeEventListener(\"visibilitychange\", start)\n    }\n  }, [placeholders.length, interval, text])\n\n  React.useEffect(() => () => cancelAnimationFrame(raf.current), [])\n\n  const vanish = (submitted: string) => {\n    const input = inputRef.current\n    const canvas = canvasRef.current\n    const ctx = canvas?.getContext(\"2d\", { willReadFrequently: true })\n    setText(\"\")\n    if (reduce || !input || !canvas || !ctx || document.hidden) {\n      setVanishing(true)\n      window.setTimeout(() => setVanishing(false), reduce ? 150 : 0)\n      return\n    }\n    const dpr = Math.min(window.devicePixelRatio || 1, 2)\n    const w = input.clientWidth\n    const h = input.clientHeight\n    canvas.width = Math.round(w * dpr)\n    canvas.height = Math.round(h * dpr)\n    canvas.style.width = `${w}px`\n    canvas.style.height = `${h}px`\n    const cs = getComputedStyle(input)\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0)\n    ctx.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`\n    ctx.fillStyle = cs.color\n    ctx.textBaseline = \"middle\"\n    ctx.fillText(submitted, parseFloat(cs.paddingLeft) - input.scrollLeft, h / 2 + 0.5)\n\n    // Sample the drawn text into particles.\n    const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data\n    const step = Math.max(1, Math.round(1.5 * dpr))\n    const particles: Particle[] = []\n    let maxX = 1\n    for (let y = 0; y < canvas.height; y += step) {\n      for (let x = 0; x < canvas.width; x += step) {\n        const i = (y * canvas.width + x) * 4\n        const alpha = data[i + 3]!\n        if (alpha > 90) {\n          const px = x / dpr\n          maxX = Math.max(maxX, px)\n          particles.push({\n            x: px,\n            y: y / dpr,\n            vx: 0,\n            vy: 0,\n            r: step / dpr,\n            a: alpha / 255,\n            delay: 0,\n            color: `${data[i]},${data[i + 1]},${data[i + 2]}`,\n          })\n        }\n      }\n    }\n    // The end of the text goes first, like a fast backspace turning into dust.\n    for (const p of particles) {\n      p.delay = ((maxX - p.x) / maxX) * 22 + Math.random() * 6\n      p.vx = 0.4 + Math.random() * 1.6\n      p.vy = -(0.2 + Math.random() * 1.2)\n    }\n    setVanishing(true)\n    cancelAnimationFrame(raf.current)\n    let frame = 0\n    const tick = () => {\n      frame++\n      ctx.clearRect(0, 0, w, h)\n      let alive = 0\n      for (const p of particles) {\n        if (p.a <= 0.02) continue\n        alive++\n        if (frame > p.delay) {\n          p.x += p.vx\n          p.y += p.vy\n          p.vx *= 0.985\n          p.vy -= 0.015\n          p.a -= 0.028\n          p.r = Math.max(0.3, p.r * 0.985)\n        }\n        ctx.fillStyle = `rgba(${p.color},${Math.max(0, p.a)})`\n        ctx.fillRect(p.x, p.y, p.r, p.r)\n      }\n      if (alive && frame < 120 && !document.hidden) raf.current = requestAnimationFrame(tick)\n      else {\n        ctx.clearRect(0, 0, w, h)\n        setVanishing(false)\n      }\n    }\n    raf.current = requestAnimationFrame(tick)\n  }\n\n  const submit = (e: React.FormEvent<HTMLFormElement>) => {\n    e.preventDefault()\n    const v = text.trim()\n    if (!v || vanishing) return\n    onSubmit?.(v)\n    vanish(text)\n  }\n\n  const showPlaceholder = !text && !vanishing\n\n  return (\n    <form\n      onSubmit={submit}\n      className={cn(\n        \"relative flex h-12 w-full items-center gap-2 overflow-hidden rounded-full border border-input bg-background ps-4 pe-1.5 shadow-xs transition-[border-color,box-shadow] focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 dark:bg-input/30\",\n        className,\n      )}\n      {...props}\n    >\n      <GooduiTokens />\n      <div className=\"relative h-full min-w-0 flex-1\">\n        <input\n          ref={inputRef}\n          name={name}\n          value={text}\n          onChange={(e) => setText(e.target.value)}\n          aria-label={label ?? placeholders[0]}\n          autoComplete=\"off\"\n          className={cn(\n            \"size-full bg-transparent text-sm text-foreground outline-none sm:text-base\",\n            vanishing && reduce && \"opacity-0 transition-opacity duration-150\",\n            inputClassName,\n          )}\n        />\n        <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute top-0 left-0 size-0\" />\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 flex items-center overflow-hidden\">\n          <AnimatePresence mode=\"wait\" initial={false}>\n            {showPlaceholder && (\n              <motion.span\n                key={index}\n                initial={reduce ? { opacity: 0 } : { opacity: 0, y: 14, filter: \"blur(3px)\" }}\n                animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n                exit={reduce ? { opacity: 0 } : { opacity: 0, y: -14, filter: \"blur(3px)\" }}\n                transition={{ duration: reduce ? 0.15 : 0.3, ease: easing.out }}\n                className=\"truncate text-sm text-muted-foreground sm:text-base\"\n              >\n                {placeholders[index % placeholders.length]}\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n      <button\n        type=\"submit\"\n        aria-label={submitLabel}\n        disabled={!text.trim()}\n        className=\"pc-press grid size-9 shrink-0 place-items-center rounded-full bg-primary text-primary-foreground transition-[background-color,color,transform] outline-none focus-visible:ring-3 focus-visible:ring-ring/50 active:scale-95 disabled:bg-muted disabled:text-muted-foreground\"\n      >\n        <motion.span\n          initial={false}\n          animate={text.trim() ? { x: 0, rotate: 0 } : { x: 0, rotate: reduce ? 0 : -90 }}\n          transition={reduce ? { duration: 0 } : spring.ui}\n          className=\"grid place-items-center\"\n        >\n          <ArrowRight className=\"size-4 rtl:-scale-x-100\" />\n        </motion.span>\n      </button>\n    </form>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/vanish-input.tsx"
    }
  ],
  "categories": [
    "components",
    "inputs"
  ],
  "type": "registry:component"
}