{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "newsletter-signup",
  "type": "registry:component",
  "title": "Newsletter Signup",
  "description": "An email capture block with inline validation and shake, a spinner while submitting and a success state that morphs the button into a check.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "site",
    "newsletter",
    "email",
    "form",
    "signup",
    "subscribe",
    "validation"
  ],
  "docs": "https://hyperblur.dev/effects/newsletter-signup",
  "files": [
    {
      "path": "registry/hyperblur/newsletter-signup.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/newsletter-signup.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface NewsletterSignupProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSubmit\" | \"title\"> {\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  placeholder?: string;\n  buttonLabel?: string;\n  successMessage?: string;\n  privacyNote?: React.ReactNode;\n  align?: \"center\" | \"left\";\n  accent?: string;\n  onSubmit?: (email: string) => void | Promise<void>;\n}\n\nconst emailPattern = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\n\nconst css = `\n.hb-nws {\n  --hb-nws-a: #2f7bff;\n  container: hb-nws / inline-size;\n  box-sizing: border-box;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n}\n.hb-nws *, .hb-nws *::before, .hb-nws *::after { box-sizing: border-box; }\n.hb-nws-in { display: grid; gap: 8px; justify-items: center; text-align: center; }\n.hb-nws[data-align=\"left\"] .hb-nws-in { justify-items: start; text-align: left; }\n.hb-nws-title { margin: 0; color: #fff; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }\n.hb-nws-desc { margin: 0; max-width: 46ch; color: #a1a1a1; font-size: 14px; line-height: 1.5; }\n.hb-nws-form { width: 100%; max-width: 440px; margin: 8px 0 0; }\n.hb-nws-field {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  padding: 5px;\n  border-radius: 14px;\n  background: #121212;\n  box-shadow: inset 0 0 0 1px #2a2a2a;\n  transition: box-shadow 0.25s ease, background 0.25s ease;\n}\n.hb-nws-field:focus-within {\n  box-shadow: inset 0 0 0 1px var(--hb-nws-a), 0 0 0 4px color-mix(in srgb, var(--hb-nws-a) 20%, transparent);\n}\n.hb-nws-field[data-invalid=\"true\"] {\n  box-shadow: inset 0 0 0 1px #ff5a5f, 0 0 0 4px rgba(255, 90, 95, 0.14);\n}\n.hb-nws-field[data-shake=\"a\"] { animation: hb-nws-shake-a 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }\n.hb-nws-field[data-shake=\"b\"] { animation: hb-nws-shake-b 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }\n.hb-nws-field[data-state=\"success\"] {\n  background: color-mix(in srgb, #2fd17a 8%, #121212);\n  box-shadow: inset 0 0 0 1px color-mix(in srgb, #2fd17a 40%, #121212);\n}\n.hb-nws-input {\n  flex: 1;\n  min-width: 0;\n  height: 40px;\n  margin: 0;\n  padding: 0 12px;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 14.5px;\n  transition: opacity 0.25s ease;\n}\n.hb-nws-input::placeholder { color: #6b6b6b; }\n.hb-nws-field[data-state=\"success\"] .hb-nws-input { opacity: 0; pointer-events: none; }\n.hb-nws-done {\n  position: absolute;\n  top: 0;\n  right: 52px;\n  bottom: 0;\n  left: 0;\n  display: flex;\n  align-items: center;\n  padding: 0 16px;\n  color: #d9f7e6;\n  font-size: 14px;\n  font-weight: 500;\n  line-height: 1.25;\n  opacity: 0;\n  transform: translateY(6px);\n  pointer-events: none;\n  transition: opacity 0.35s ease 0.15s, transform 0.4s cubic-bezier(0.2, 0.9, 0.2, 1) 0.15s;\n}\n.hb-nws-field[data-state=\"success\"] .hb-nws-done { opacity: 1; transform: none; }\n.hb-nws-btn {\n  position: relative;\n  display: grid;\n  flex: none;\n  place-items: center;\n  height: 40px;\n  min-width: 40px;\n  margin: 0;\n  padding: 0 18px;\n  overflow: hidden;\n  border: 0;\n  border-radius: 10px;\n  background: var(--hb-nws-a);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);\n  color: #fff;\n  font: inherit;\n  font-size: 14px;\n  font-weight: 550;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: width 0.45s cubic-bezier(0.2, 0.9, 0.2, 1), padding 0.45s cubic-bezier(0.2, 0.9, 0.2, 1), background 0.3s ease, filter 0.2s ease, transform 0.15s ease;\n}\n.hb-nws-btn:hover { filter: brightness(1.1); }\n.hb-nws-btn:active { transform: scale(0.97); }\n.hb-nws-btn:disabled { cursor: default; filter: none; transform: none; }\n.hb-nws-btn > * { grid-area: 1 / 1; transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.2, 0.9, 0.2, 1); }\n.hb-nws-spin, .hb-nws-check { width: 18px; height: 18px; opacity: 0; transform: scale(0.6); }\n.hb-nws-spin circle { transform-origin: center; animation: hb-nws-spin 0.8s linear infinite; }\n.hb-nws-field[data-state=\"submitting\"] .hb-nws-lbl { opacity: 0; transform: translateY(-8px); }\n.hb-nws-field[data-state=\"submitting\"] .hb-nws-spin { opacity: 1; transform: none; }\n.hb-nws-field[data-state=\"success\"] .hb-nws-btn { padding: 0; background: #22c55e; }\n.hb-nws-field[data-state=\"success\"] .hb-nws-lbl { opacity: 0; transform: translateY(-8px); }\n.hb-nws-field[data-state=\"success\"] .hb-nws-spin { opacity: 0; }\n.hb-nws-field[data-state=\"success\"] .hb-nws-check { opacity: 1; transform: none; }\n.hb-nws-check path {\n  stroke-dasharray: 22;\n  stroke-dashoffset: 22;\n}\n.hb-nws-field[data-state=\"success\"] .hb-nws-check path { animation: hb-nws-draw 0.45s cubic-bezier(0.2, 0.9, 0.2, 1) 0.25s forwards; }\n.hb-nws-input:focus-visible { outline: 0; }\n.hb-nws-btn:focus-visible,\n.hb-nws-again:focus-visible {\n  outline: 2px solid #fff;\n  outline-offset: 2px;\n  border-radius: 8px;\n}\n.hb-nws-note { margin: 0; color: #6b6b6b; font-size: 12px; line-height: 1.4; }\n.hb-nws-note[data-error=\"true\"] { color: #ff7a7e; }\n.hb-nws-again {\n  margin: 0;\n  padding: 0;\n  border: 0;\n  background: transparent;\n  color: color-mix(in srgb, var(--hb-nws-a) 55%, #fff);\n  font: inherit;\n  font-size: 12px;\n  text-decoration: underline;\n  text-underline-offset: 3px;\n  cursor: pointer;\n}\n@keyframes hb-nws-shake-a {\n  10%, 90% { transform: translateX(-2px); }\n  20%, 80% { transform: translateX(4px); }\n  30%, 50%, 70% { transform: translateX(-7px); }\n  40%, 60% { transform: translateX(7px); }\n}\n@keyframes hb-nws-shake-b {\n  10%, 90% { transform: translateX(-2px); }\n  20%, 80% { transform: translateX(4px); }\n  30%, 50%, 70% { transform: translateX(-7px); }\n  40%, 60% { transform: translateX(7px); }\n}\n@keyframes hb-nws-spin { to { transform: rotate(360deg); } }\n@keyframes hb-nws-draw { to { stroke-dashoffset: 0; } }\n@container hb-nws (max-width: 339px) {\n  .hb-nws-title { font-size: 20px; }\n  .hb-nws-btn { padding: 0 14px; }\n  .hb-nws-input { padding: 0 8px; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-nws-field[data-shake] { animation: none; }\n  .hb-nws-btn, .hb-nws-btn > *, .hb-nws-done, .hb-nws-input, .hb-nws-field { transition: none; }\n  .hb-nws-spin circle { animation-duration: 2s; }\n  .hb-nws-field[data-state=\"success\"] .hb-nws-check path { animation: none; stroke-dashoffset: 0; }\n}\n`;\n\nexport function NewsletterSignup({\n  title = \"Get the Friday dispatch\",\n  description = \"One short email every week with new features, product notes and what we are reading.\",\n  placeholder = \"you@company.com\",\n  buttonLabel = \"Subscribe\",\n  successMessage = \"You are in. Check your inbox to confirm.\",\n  privacyNote = \"No spam. Unsubscribe with one click.\",\n  align = \"center\",\n  accent = \"#2f7bff\",\n  onSubmit,\n  className = \"\",\n  style,\n  ...rest\n}: NewsletterSignupProps) {\n  const uid = React.useId();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const buttonRef = React.useRef<HTMLButtonElement>(null);\n  const [email, setEmail] = React.useState(\"\");\n  const [status, setStatus] = React.useState<\"idle\" | \"submitting\" | \"success\">(\"idle\");\n  const [error, setError] = React.useState(\"\");\n  const [shake, setShake] = React.useState<\"\" | \"a\" | \"b\">(\"\");\n\n  React.useEffect(() => {\n    const btn = buttonRef.current;\n    if (!btn) return;\n    if (status === \"success\") btn.style.width = \"40px\";\n    else if (status === \"idle\") btn.style.width = \"\";\n  }, [status]);\n\n  async function submit(e: React.FormEvent<HTMLFormElement>) {\n    e.preventDefault();\n    if (status !== \"idle\") return;\n    const value = email.trim();\n    if (!emailPattern.test(value)) {\n      setError(value ? \"That email address does not look right.\" : \"Enter your email address.\");\n      setShake((s) => (s === \"a\" ? \"b\" : \"a\"));\n      inputRef.current?.focus();\n      return;\n    }\n    setError(\"\");\n    const btn = buttonRef.current;\n    if (btn) btn.style.width = `${btn.offsetWidth}px`;\n    setStatus(\"submitting\");\n    try {\n      await onSubmit?.(value);\n      setStatus(\"success\");\n    } catch {\n      setStatus(\"idle\");\n      setError(\"Something went wrong. Please try again.\");\n    }\n  }\n\n  function reset() {\n    setEmail(\"\");\n    setStatus(\"idle\");\n    setError(\"\");\n    window.setTimeout(() => inputRef.current?.focus(), 0);\n  }\n\n  const rootStyle = { \"--hb-nws-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-nws ${className}`} data-align={align} style={rootStyle} {...rest}>\n      <style href=\"hb-newsletter-signup\" precedence=\"default\">{css}</style>\n      <div className=\"hb-nws-in\">\n        <h2 className=\"hb-nws-title\">{title}</h2>\n        {description && <p className=\"hb-nws-desc\">{description}</p>}\n        <form className=\"hb-nws-form\" onSubmit={submit} noValidate>\n          <div\n            className=\"hb-nws-field\"\n            data-state={status}\n            data-invalid={error ? \"true\" : \"false\"}\n            data-shake={shake || undefined}\n          >\n            <input\n              ref={inputRef}\n              className=\"hb-nws-input\"\n              type=\"email\"\n              name=\"email\"\n              autoComplete=\"email\"\n              placeholder={placeholder}\n              aria-label=\"Email address\"\n              aria-invalid={error ? true : undefined}\n              aria-describedby={error ? `${uid}-err` : undefined}\n              disabled={status === \"submitting\"}\n              tabIndex={status === \"success\" ? -1 : 0}\n              value={email}\n              onChange={(e) => {\n                setEmail(e.target.value);\n                if (error) setError(\"\");\n              }}\n            />\n            <span className=\"hb-nws-done\" role=\"status\">\n              {status === \"success\" ? successMessage : \"\"}\n            </span>\n            <button\n              ref={buttonRef}\n              className=\"hb-nws-btn\"\n              type=\"submit\"\n              disabled={status !== \"idle\"}\n              aria-label={status === \"success\" ? \"Subscribed\" : undefined}\n            >\n              <span className=\"hb-nws-lbl\">{buttonLabel}</span>\n              <svg className=\"hb-nws-spin\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <circle cx=\"12\" cy=\"12\" r=\"8.5\" strokeDasharray=\"38 60\" />\n              </svg>\n              <svg className=\"hb-nws-check\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"m5.5 12.5 4.2 4.2 8.8-9.4\" />\n              </svg>\n            </button>\n          </div>\n        </form>\n        <p className=\"hb-nws-note\" id={`${uid}-err`} data-error={error ? \"true\" : \"false\"} role={error ? \"alert\" : undefined}>\n          {error ? (\n            error\n          ) : status === \"success\" ? (\n            <button type=\"button\" className=\"hb-nws-again\" onClick={reset}>\n              Use a different email\n            </button>\n          ) : (\n            privacyNote\n          )}\n        </p>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}