{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"aurora-glow-input","type":"registry:component","title":"Aurora Glow Input","description":"A waitlist field that lights like the sky: focus raises a two-hue bloom and lights the rim, every keystroke sends a rose ripple from the caret, and joining sweeps the whole palette once.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/aurora-glow-input.tsx","content":"\"use client\";\n\nimport { useId, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, FormEvent, KeyboardEvent as ReactKeyboardEvent, ReactNode } from \"react\";\n\n/**\n * AuroraGlowInput — a waitlist field that lights like the sky.\n *\n * A hairline pill at rest; focus raises a soft two-hue bloom (320ms) and\n * lights the rim, and every keystroke sends a small rose ripple from the\n * caret (260ms). The address goes to `onJoin`, which is required: the field\n * never claims a sign-up on its own. On success the whole palette sweeps\n * once through the bloom (a 600ms borealis flash).\n *\n * Part of the Aurora kit: a near-black night (#050608) lit by curtains of\n * aurora in mint #7cf5c4 and sky #38bdf8, a violet #a78bfa blend, a rose\n * #f472b6 crown and an indigo #5b6cc4 fringe, all on one 60s clock; Bricolage\n * Grotesque through var(--font-bricolage) for lit display type over Geist.\n * Respects prefers-reduced-motion. No dependencies beyond React. Paste it as\n * its own file: it repeats the kit's small helpers, which would clash in one\n * module. For the display face, load Bricolage Grotesque with next/font\n * (variable: \"--font-bricolage\") on a parent; elsewhere, load it with a\n * Google Fonts link or @fontsource and set --font-bricolage yourself.\n * Needs Tailwind v4 (on v3.4, add the @tailwindcss/container-queries plugin).\n */\n\nconst SANS = 'var(--font-sans, \"Geist\", \"Inter\", ui-sans-serif, system-ui, sans-serif)';\n\nconst EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\n\nconst HEX = /^#[0-9a-fA-F]{6}$/;\n\n/** The night the kit is set in. */\nconst SKY = {\n  ground: \"#050608\",\n  panel: \"#0a0d12\",\n  raised: \"#0f141a\",\n  ink: \"rgba(236,244,248,0.94)\",\n  ink2: \"rgba(236,244,248,0.64)\",\n  ink3: \"rgba(236,244,248,0.42)\",\n  line: \"rgba(236,244,248,0.08)\",\n  line2: \"rgba(236,244,248,0.16)\",\n  shadow: \"0 40px 100px -30px rgba(0,0,0,0.7)\",\n} as const;\n\n/**\n * The sky's colours by altitude: the core low in the curtain (two hues it\n * drifts between on the aurora clock), a violet blend above it, a rose crown\n * seen only in a strong display, and an indigo fringe under the lower border.\n */\nexport type AuPalette = { core: string; core2: string; blend: string; high: string; fringe: string };\n\nexport const AU_PALETTES = {\n  boreal: { core: \"#7cf5c4\", core2: \"#38bdf8\", blend: \"#a78bfa\", high: \"#f472b6\", fringe: \"#5b6cc4\" },\n  verdant: { core: \"#6ee7a0\", core2: \"#7cf5c4\", blend: \"#8fb4f0\", high: \"#e879b9\", fringe: \"#5b6cc4\" },\n  violet: { core: \"#a78bfa\", core2: \"#38bdf8\", blend: \"#c4a6fb\", high: \"#f472b6\", fringe: \"#4c5bb8\" },\n} as const satisfies Record<string, AuPalette>;\n\nexport type AuPaletteName = keyof typeof AU_PALETTES;\n\nfunction own<T extends object>(map: T, key: string): key is Extract<keyof T, string> {\n  return Object.prototype.hasOwnProperty.call(map, key);\n}\n\n/** A named palette, or boreal. */\nfunction paletteOf(name: string): AuPalette {\n  return own(AU_PALETTES, name) ? AU_PALETTES[name] : AU_PALETTES.boreal;\n}\n\nfunction rgbOf(hex: string): [number, number, number] {\n  const n = parseInt((HEX.test(hex) ? hex : \"#7cf5c4\").slice(1), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction rgba(hex: string, a: number): string {\n  const [r, g, b] = rgbOf(hex);\n  return `rgba(${r},${g},${b},${a})`;\n}\n\n/**\n * The aurora clock: every lit part of the page reads one 60s cycle, so a\n * button, a rim and the sky drift together instead of breathing out of step.\n * The phase is the page's own timeline (performance.now), shared by\n * everything on it.\n */\nconst CLOCK_S = 60;\n\n/**\n * A ref callback that starts an element's CSS animation where the clock\n * already is, so parts that mount at different moments stay in step.\n */\nfunction syncClock(periodS: number) {\n  return (el: HTMLElement | null) => {\n    if (el) el.style.animationDelay = `${(-(performance.now() / 1000) % periodS).toFixed(3)}s`;\n  };\n}\n\n/** Links: strip tabs and newlines, refuse backslashes, allow http(s), mailto, tel and same-site paths. */\nfunction safeHref(raw: string): string {\n  const v = raw.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!v || v.includes(\"\\\\\")) return \"#\";\n  if (/^(https?:|mailto:|tel:)/i.test(v)) return v;\n  if (/^[/#?]/.test(v) && !/^\\/\\//.test(v)) return v;\n  return \"#\";\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n// Each part carries only the CSS it needs, so any one of them works on its own.\n// Nothing is interpolated into these sheets; colours arrive as CSS variables.\n// revert-layer keeps an element's own rounded corners when a host page's focus rule flattens them.\nconst FOCUS_CSS = \".au-scope :focus-visible,.au-scope:focus-visible{outline:2px solid var(--au-ring,#7cf5c4);outline-offset:3px;border-radius:revert-layer}\";\n\n/** The palette as CSS variables, for the parts drawn in CSS. */\nfunction paletteVars(p: AuPalette): CSSProperties {\n  return { \"--au-core\": p.core, \"--au-core2\": p.core2, \"--au-blend\": p.blend, \"--au-high\": p.high, \"--au-ring\": p.core } as CSSProperties;\n}\n\n// A registered angle, so the under-glow turns on the compositor without a render per frame.\nconst GLOW_BTN_CSS =\n  \"@property --au-a{syntax:'<angle>';inherits:false;initial-value:0deg}\" +\n  \"@keyframes au-turn{to{--au-a:360deg}}\" +\n  \"@keyframes au-ring{from{opacity:.9;transform:scale(1)}to{opacity:0;transform:scale(1.18,1.5)}}\" +\n  \".au-glow{inset:-6px -8px -12px;opacity:.55;animation:au-turn 60s linear infinite}\" +\n  \".au-btn:hover .au-glow,.au-btn:focus-visible .au-glow{inset:-12px -14px -18px;opacity:.85}\" +\n  \".au-q .au-glow{opacity:0}.au-q:hover .au-glow,.au-q:focus-visible .au-glow{opacity:.4}\" +\n  \".au-btn:active{transform:translateY(1px) scale(.985)}\" +\n  \"@media (prefers-reduced-motion: reduce){.au-glow{animation:none}.au-ring{animation:none!important;opacity:0}}\";\n\nexport type AuroraGlowButtonProps = {\n  children: ReactNode;\n  /** Renders a link when given, else a button. */\n  href?: string;\n  onClick?: () => void;\n  type?: \"button\" | \"submit\";\n  /** \"solid\" carries the sky under it; \"quiet\" is a hairline pill whose light wakes on hover. */\n  variant?: \"solid\" | \"quiet\";\n  size?: \"md\" | \"lg\";\n  palette?: AuPaletteName;\n  disabled?: boolean;\n  className?: string;\n};\n\n/**\n * A pill with a sliver of the sky under it. The under-glow is a slow turn\n * through the palette on the page's 60s aurora clock, so every button on the\n * page glows in step with the sky; hover or focus lets it spread (220ms), and\n * a press (or Enter or Space) sends a ring of light out from the pill (380ms). The top edge\n * carries a thin lit rim. Renders a link when given an href, else a button.\n */\nexport function AuroraGlowButton({ children, href, onClick, type = \"button\", variant = \"solid\", size = \"md\", palette = \"boreal\", disabled, className }: AuroraGlowButtonProps) {\n  const p = paletteOf(palette);\n  const [ring, setRing] = useState(0);\n  const solid = variant === \"solid\";\n  const cls =\n    \"au-scope au-btn relative isolate inline-flex select-none items-center justify-center gap-2 whitespace-nowrap rounded-full font-medium transition-[transform,color,box-shadow] duration-200 disabled:cursor-not-allowed disabled:opacity-50 \" +\n    (size === \"lg\" ? \"h-[52px] px-7 text-[15px]\" : \"h-11 px-5 text-[14px]\") +\n    (solid ? \"\" : \" au-q\") +\n    (className ? \" \" + className : \"\");\n  const style: CSSProperties = {\n    ...paletteVars(p),\n    color: SKY.ink,\n    fontFamily: SANS,\n    background: solid ? `linear-gradient(180deg, ${SKY.raised}, ${SKY.panel})` : \"transparent\",\n    boxShadow: solid ? `inset 0 0 0 1px ${SKY.line2}, 0 10px 30px -12px rgba(0,0,0,0.8)` : `inset 0 0 0 1px ${SKY.line2}`,\n  };\n  const sheet = <style>{FOCUS_CSS + GLOW_BTN_CSS}</style>;\n  const inner = (\n    <>\n      {/* The sky under the pill, turning on the aurora clock. */}\n      <span\n        ref={syncClock(CLOCK_S)}\n        aria-hidden\n        className=\"au-glow pointer-events-none absolute -z-10 rounded-full transition-[inset,opacity] duration-200\"\n        style={{\n          background: \"conic-gradient(from var(--au-a), var(--au-core), var(--au-core2), var(--au-blend), var(--au-core2), var(--au-core))\",\n          filter: \"blur(14px)\",\n        }}\n      />\n      {/* A lit rim along the top edge. */}\n      <span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-full\"\n        style={{\n          padding: 1,\n          background: `linear-gradient(90deg, transparent 12%, ${rgba(p.core, solid ? 0.7 : 0.35)} 40%, ${rgba(p.core2, solid ? 0.6 : 0.3)} 62%, transparent 88%) top / 100% 1px no-repeat`,\n        }}\n      />\n      {ring > 0 && (\n        <span\n          key={ring}\n          aria-hidden\n          className=\"au-ring pointer-events-none absolute inset-0 rounded-full\"\n          style={{ boxShadow: `0 0 0 1px ${rgba(p.core, 0.8)}, 0 0 24px ${rgba(p.core2, 0.5)}`, animation: `au-ring 380ms ${EASE} both` }}\n        />\n      )}\n      <span className=\"relative\">{children}</span>\n    </>\n  );\n  const onDown = () => {\n    if (!disabled) setRing((r) => r + 1);\n  };\n  const onKey = (e: ReactKeyboardEvent) => {\n    if (!e.repeat && (e.key === \"Enter\" || e.key === \" \")) onDown();\n  };\n  if (href !== undefined) {\n    return (\n      <>\n        {sheet}\n        <a href={safeHref(href)} onClick={onClick} onPointerDown={onDown} onKeyDown={onKey} className={cls} style={style}>\n          {inner}\n        </a>\n      </>\n    );\n  }\n  return (\n    <>\n      {sheet}\n      <button type={type} onClick={onClick} onPointerDown={onDown} onKeyDown={onKey} disabled={disabled} className={cls} style={style}>\n        {inner}\n      </button>\n    </>\n  );\n}\n\nconst INPUT_CSS =\n  \".au-field .au-bloom{opacity:0;transition:opacity 320ms cubic-bezier(0.22,1,0.36,1)}\" +\n  \".au-field:focus-within .au-bloom{opacity:.55}\" +\n  \".au-field .au-lit{opacity:0;transition:opacity 320ms cubic-bezier(0.22,1,0.36,1)}\" +\n  \".au-field:focus-within .au-lit{opacity:1}\" +\n  \".au-field input:focus-visible{outline:none}\" +\n  \"@media (prefers-reduced-motion: reduce){.au-field .au-bloom,.au-field .au-lit{transition:none}}\";\n\nexport type AuroraGlowInputProps = {\n  /** Called with the address. Resolve when it is received; throw to show `failed`. Required: the field never claims a sign-up on its own. */\n  onJoin: (email: string) => Promise<void> | void;\n  label?: string;\n  placeholder?: string;\n  cta?: string;\n  done?: string;\n  failed?: string;\n  note?: string;\n  palette?: AuPaletteName;\n  className?: string;\n};\n\n/**\n * A waitlist field that lights like the sky. At rest it is a hairline pill;\n * focus raises a soft two-hue bloom around it (320ms) and lights its rim, and\n * every keystroke sends a small rose ripple out from the caret (260ms). The\n * address goes to `onJoin`, which is required; while it runs the button says\n * so, and when it resolves the whole palette sweeps once through the bloom\n * (a 600ms borealis flash) and the field settles into its thank-you.\n * A native email input with a label and a polite status line.\n */\nexport function AuroraGlowInput({\n  onJoin,\n  label = \"Email address\",\n  placeholder = \"you@company.com\",\n  cta = \"Join the waitlist\",\n  done = \"You are on the list. We will write before your first night.\",\n  failed = \"That did not go through. Try again in a moment.\",\n  note,\n  palette = \"boreal\",\n  className,\n}: AuroraGlowInputProps) {\n  const p = paletteOf(palette);\n  const reduced = useReducedMotion();\n  const [email, setEmail] = useState(\"\");\n  const [state, setState] = useState<\"idle\" | \"sending\" | \"done\" | \"error\">(\"idle\");\n  const [hint, setHint] = useState(\"\");\n  const inputRef = useRef<HTMLInputElement>(null);\n  const mirrorRef = useRef<HTMLSpanElement>(null);\n  const rippleRef = useRef<HTMLSpanElement>(null);\n  const bloomRef = useRef<HTMLSpanElement>(null);\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n\n  // A ripple from the caret: measure the text before it in a hidden mirror of the field.\n  const ripple = () => {\n    const input = inputRef.current;\n    const mirror = mirrorRef.current;\n    const layer = rippleRef.current;\n    if (!input || !mirror || !layer || reduced) return;\n    mirror.textContent = input.value.slice(0, input.selectionStart ?? input.value.length) || \"\";\n    const x = Math.min(input.clientWidth - 8, mirror.offsetWidth - input.scrollLeft) + 22;\n    // Only numbers and the palette's own hex reach this style string; keep it that way if you extend it.\n    const dot = document.createElement(\"span\");\n    dot.setAttribute(\"aria-hidden\", \"true\");\n    dot.style.cssText = `position:absolute;left:${x}px;top:50%;width:46px;height:46px;margin:-23px 0 0 -23px;border-radius:999px;pointer-events:none;background:radial-gradient(closest-side, ${rgba(p.high, 0.55)}, ${rgba(p.high, 0)});`;\n    layer.appendChild(dot);\n    const a = dot.animate([{ transform: \"scale(0.25)\", opacity: 0.9 }, { transform: \"scale(1.5)\", opacity: 0 }], { duration: 260, easing: EASE });\n    a.onfinish = () => dot.remove();\n  };\n\n  const submit = async (e: FormEvent) => {\n    e.preventDefault();\n    if (state === \"sending\" || state === \"done\") return;\n    if (!inputRef.current?.checkValidity() || !email.trim()) {\n      setHint(\"Enter an email address.\");\n      inputRef.current?.focus();\n      return;\n    }\n    setHint(\"\");\n    setState(\"sending\");\n    try {\n      await onJoin(email.trim());\n      setState(\"done\");\n      // The borealis flash: the whole palette sweeps once through the bloom.\n      const b = bloomRef.current;\n      if (b && !reduced) {\n        b.animate(\n          [\n            { opacity: 0.2, backgroundPosition: \"0% 50%\" },\n            { opacity: 0.95, backgroundPosition: \"100% 50%\", offset: 0.55 },\n            { opacity: 0.45, backgroundPosition: \"200% 50%\" },\n          ],\n          { duration: 600, easing: EASE },\n        );\n      }\n    } catch {\n      setState(\"error\");\n    }\n  };\n\n  const doneNow = state === \"done\";\n  return (\n    <form onSubmit={submit} noValidate className={\"au-scope @container w-full\" + (className ? \" \" + className : \"\")} style={{ ...paletteVars(p), color: SKY.ink, fontFamily: SANS }}>\n      <style>{FOCUS_CSS + INPUT_CSS}</style>\n      <label htmlFor={`${uid}-email`} className=\"sr-only\">\n        {label}\n      </label>\n      <div className=\"flex flex-col gap-3 @md:flex-row @md:items-center\">\n        <div className=\"au-field relative isolate h-[54px] min-w-0 flex-1 rounded-full\">\n          {/* The bloom behind the field; on success it carries the borealis flash. */}\n          <span\n            ref={bloomRef}\n            aria-hidden\n            className=\"au-bloom pointer-events-none absolute -inset-1 -z-10 rounded-full\"\n            style={{ background: `linear-gradient(90deg, ${p.core2}, ${p.core}, ${p.blend}, ${p.high}, ${p.core2}, ${p.core})`, backgroundSize: \"200% 100%\", filter: \"blur(16px)\" }}\n          />\n          <span aria-hidden className=\"pointer-events-none absolute inset-0 rounded-full\" style={{ background: SKY.panel, boxShadow: `inset 0 0 0 1px ${SKY.line2}` }} />\n          {/* The lit rim on focus. */}\n          <span\n            aria-hidden\n            className=\"au-lit pointer-events-none absolute inset-0 rounded-full\"\n            style={{\n              padding: 1,\n              background: `linear-gradient(90deg, ${p.core2}, ${p.core} 50%, ${p.blend})`,\n              WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n              WebkitMaskComposite: \"xor\",\n              mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n              maskComposite: \"exclude\",\n            }}\n          />\n          <span ref={rippleRef} aria-hidden className=\"pointer-events-none absolute inset-0 overflow-hidden rounded-full\" />\n          {/* A hidden mirror of the text, to find the caret. */}\n          <span ref={mirrorRef} aria-hidden className=\"invisible absolute left-0 top-0 whitespace-pre text-[15.5px]\" />\n          <input\n            ref={inputRef}\n            id={`${uid}-email`}\n            type=\"email\"\n            required\n            autoComplete=\"email\"\n            placeholder={placeholder}\n            value={email}\n            disabled={doneNow}\n            onChange={(e) => {\n              setEmail(e.target.value);\n              if (state === \"error\") setState(\"idle\");\n              if (hint) setHint(\"\");\n            }}\n            onKeyUp={(e: ReactKeyboardEvent<HTMLInputElement>) => {\n              if (e.key.length === 1 || e.key === \"Backspace\") ripple();\n            }}\n            aria-describedby={`${uid}-msg`}\n            aria-invalid={hint ? true : undefined}\n            className=\"relative h-full w-full rounded-full bg-transparent px-[22px] text-[15.5px] placeholder:text-[rgba(236,244,248,0.38)] disabled:opacity-70\"\n            style={{ color: SKY.ink }}\n          />\n        </div>\n        <AuroraGlowButton type=\"submit\" size=\"lg\" palette={palette} disabled={state === \"sending\" || doneNow}>\n          {state === \"sending\" ? \"Joining\" : doneNow ? \"Joined\" : cta}\n        </AuroraGlowButton>\n      </div>\n      <p id={`${uid}-msg`} role=\"status\" aria-live=\"polite\" className=\"m-0 mt-3 flex min-h-[20px] items-center gap-2 text-[13.5px]\" style={{ color: state === \"error\" || hint ? \"#f4a3b4\" : doneNow ? SKY.ink : SKY.ink3 }}>\n        {doneNow && <span aria-hidden className=\"h-1.5 w-1.5 rounded-full\" style={{ background: p.core, boxShadow: `0 0 10px ${p.core}` }} />}\n        {state === \"error\" ? failed : doneNow ? done : hint || note || \"\"}\n      </p>\n    </form>\n  );\n}\n","type":"registry:component","target":"components/viberdy/aurora-glow-input.tsx"}],"meta":{"tier":"free","tags":["form","input","email","waitlist","glow","aurora","focus"],"href":"https://viberdy.dev/library/aurora-glow-input","aiPrompt":"Build a React + Tailwind form, `AuroraGlowInput({ onJoin, label, placeholder, cta, done, failed, note, palette })`; onJoin is required and receives the trimmed address.\n\nA 54px pill field: behind it a bloom span (inset -4px, blur 16px, a 200%-wide gradient through core2, core, blend, high) at opacity 0, 0.55 on focus-within over 320ms; a panel fill with a hairline; a lit rim (1px padding, gradient core2, core, blend, masked to the border) that appears on focus-within; a ripple layer; and an invisible mirror span with the same font. On keyup (a character or Backspace) put the text before the caret in the mirror, take its width minus scrollLeft plus the 22px padding, and animate a 46px radial of the high hue from scale 0.25 to 1.5 and opacity 0.9 to 0 over 260ms, removing it on finish. Submit checks validity, calls onJoin, shows sending, done or failed; on done animate the bloom's opacity and background-position through the whole gradient over 600ms. Hint and status in a polite live line.\n\nAurora grammar: a near-black night #050608 (panels #0a0d12, raised #0f141a; ink #ecf4f8 at 94/64/42%; hairlines at 8% and 16%). The light is real aurora, coloured by altitude: a core in mint #7cf5c4 drifting toward sky #38bdf8 on one shared 60s clock, a violet #a78bfa blend above it, a rose #f472b6 crown seen only in a strong display, and an indigo #5b6cc4 fringe under the lower border (palettes: boreal, verdant #6ee7a0, violet). Never a hue-rotate cycle, never full-saturation rainbow; colour is a function of position and altitude, blended through noise. Curtains have a bright lower border, rays that rise and fray, folds that brighten where a sheet turns edge-on, and stretches that are lit and gone; layers are phase-offset, never in unison. A static 2% dither against banding (not re-seeded). Text never sits on bare aurora: frosted glass (blur 14-18px) or the dark between curtains. Bricolage Grotesque through var(--font-bricolage, \"Bricolage Grotesque\", ...) at 600-650 for lit display type only, Geist for UI, Geist Mono uppercase captions. Radii 20-24px on panels, pills for controls. Motion: the 60s aurora clock, ambient drifts of 30s and longer, discrete hover or focus changes under 450ms, pointer chases that settle over 600-900ms (1 - e^(-4dt)); WebGL runs at 30fps and only on screen. Every CSS-animated glow is started where the clock already is (a negative animation-delay from performance.now()), so parts mounted at different moments stay in step. Nothing interpolated into the small static <style> each part renders; colours arrive as CSS variables. Respect prefers-reduced-motion (still sky, no chases). No dependencies beyond React.","license":"https://viberdy.dev/license"}}