{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "newsletter",
  "title": "Newsletter",
  "description": "A compact sign-up band with an inline email form that reports pending, success and error states.",
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/button",
    "@corsair-ui/input"
  ],
  "files": [
    {
      "path": "registry/default/components/blocks/newsletter.tsx",
      "content": "\"use client\";\n\nimport { useId, useState, type ComponentProps, type ReactNode, type SubmitEvent } from \"react\";\n\nimport { cn } from \"@/registry/default/lib/utils\";\nimport { Button } from \"@/registry/default/ui/button\";\nimport { Input } from \"@/registry/default/ui/input\";\n\n/** Every string the form shows, including the hidden label and status messages. */\ninterface NewsletterLabels {\n  /** Visually hidden label of the email field. */\n  email: ReactNode;\n  submit: ReactNode;\n  /** Button text while `onSubscribe` is running. */\n  pending: ReactNode;\n  /** Announced in the status region once `onSubscribe` resolves. */\n  success: ReactNode;\n  /** Announced in the alert region when `onSubscribe` throws. */\n  error: ReactNode;\n}\n\ntype NewsletterStatus = \"idle\" | \"pending\" | \"success\" | \"error\";\n\nconst defaultLabels: NewsletterLabels = {\n  email: \"Email address\",\n  submit: \"Subscribe\",\n  pending: \"Subscribing…\",\n  success: \"You're subscribed. Check your inbox to confirm.\",\n  error: \"Could not subscribe. Please try again.\",\n};\n\ninterface NewsletterProps extends Omit<ComponentProps<\"section\">, \"title\"> {\n  /** Section title, rendered as an `<h2>`. */\n  title?: ReactNode;\n  description?: ReactNode;\n  /** Small print under the form. Pass `null` to hide it. */\n  note?: ReactNode;\n  placeholder?: string;\n  /** Overrides for any of the form's strings; the rest keep their English defaults. */\n  labels?: Partial<NewsletterLabels>;\n  /**\n   * Called with the email instead of a native submit. While it runs the button\n   * is disabled; resolving clears the field and shows `labels.success`,\n   * throwing keeps the email and shows `labels.error`.\n   */\n  onSubscribe?: (email: string) => void | Promise<void>;\n  /** Props for the `<form>`, such as `action` and `method` for a native submit. */\n  formProps?: ComponentProps<\"form\">;\n  /** \"card\" puts the band in a bordered box; \"plain\" leaves it on the page background. */\n  variant?: \"plain\" | \"card\";\n}\n\n/**\n * A compact sign-up band: title and description on the left and an inline\n * email form on the right from `md` up (stacked on small screens). The email\n * field is `type=\"email\"`, `required` and has `autoComplete=\"email\"`, with a\n * visually hidden label, so the browser validates it before `onSubscribe` runs.\n *\n * With `onSubscribe`, the form does not navigate: the section and form get\n * `data-status=\"pending\"`, then `\"success\"` or `\"error\"`. The success message\n * goes to a `role=\"status\"` region and the error to a `role=\"alert\"` region;\n * both stay mounted (empty when idle) so screen readers announce them.\n * Without `onSubscribe` the form submits natively: pass `action` and `method`\n * through `formProps`. `data-variant` reflects `variant`.\n *\n * @example\n * <Newsletter\n *   title=\"Product updates\"\n *   variant=\"plain\"\n *   onSubscribe={async (email) => {\n *     await fetch(\"/api/subscribe\", { method: \"POST\", body: JSON.stringify({ email }) });\n *   }}\n * />\n */\nfunction Newsletter({\n  title = \"Stay in the loop\",\n  description = \"Get product updates, tips and release notes in your inbox once a month.\",\n  note = \"No spam. Unsubscribe at any time.\",\n  placeholder = \"you@example.com\",\n  labels: labelsProp,\n  onSubscribe,\n  formProps,\n  variant = \"card\",\n  className,\n  ...props\n}: NewsletterProps) {\n  const id = useId();\n  const [status, setStatus] = useState<NewsletterStatus>(\"idle\");\n  const labels = { ...defaultLabels, ...labelsProp };\n  const pending = status === \"pending\";\n\n  async function handleSubmit(event: SubmitEvent<HTMLFormElement>) {\n    formProps?.onSubmit?.(event);\n    // No handler, or the consumer cancelled it: leave the native submit alone.\n    if (!onSubscribe || event.defaultPrevented) return;\n    event.preventDefault();\n    if (pending) return;\n\n    // React clears currentTarget once the event is handled, so keep the form.\n    const form = event.currentTarget;\n    const email = String(new FormData(form).get(\"email\") ?? \"\");\n\n    setStatus(\"pending\");\n    try {\n      await onSubscribe(email);\n      form.reset();\n      setStatus(\"success\");\n    } catch {\n      setStatus(\"error\");\n    }\n  }\n\n  return (\n    <section\n      data-slot=\"newsletter\"\n      data-status={status}\n      data-variant={variant}\n      className={cn(\"py-16 sm:py-24\", className)}\n      {...props}\n    >\n      <div data-slot=\"newsletter-container\" className=\"mx-auto w-full max-w-6xl px-4 sm:px-6\">\n        <div\n          data-slot=\"newsletter-content\"\n          className={cn(\n            \"flex flex-col gap-8 md:flex-row md:items-center md:justify-between\",\n            variant === \"card\" && \"bg-card text-card-foreground rounded-xl border p-6 sm:p-10\"\n          )}\n        >\n          <div data-slot=\"newsletter-header\" className=\"max-w-2xl min-w-0\">\n            <h2\n              data-slot=\"newsletter-title\"\n              className=\"text-3xl font-semibold tracking-tight text-balance sm:text-4xl\"\n            >\n              {title}\n            </h2>\n            {description ? (\n              <p\n                data-slot=\"newsletter-description\"\n                className=\"text-muted-foreground mt-4 text-lg text-pretty\"\n              >\n                {description}\n              </p>\n            ) : null}\n          </div>\n          <div data-slot=\"newsletter-body\" className=\"w-full min-w-0 md:max-w-md\">\n            <form\n              data-slot=\"newsletter-form\"\n              data-status={status}\n              {...formProps}\n              className={cn(\"flex flex-col gap-3 sm:flex-row\", formProps?.className)}\n              onSubmit={handleSubmit}\n            >\n              <label htmlFor={`${id}-email`} className=\"sr-only\">\n                {labels.email}\n              </label>\n              <Input\n                id={`${id}-email`}\n                name=\"email\"\n                type=\"email\"\n                autoComplete=\"email\"\n                placeholder={placeholder}\n                required\n                className=\"sm:flex-1\"\n              />\n              <Button type=\"submit\" data-slot=\"newsletter-submit\" loading={pending}>\n                {pending ? labels.pending : labels.submit}\n              </Button>\n            </form>\n            <p role=\"status\" data-slot=\"newsletter-success\" className=\"mt-3 text-sm empty:mt-0\">\n              {status === \"success\" ? labels.success : null}\n            </p>\n            <p\n              role=\"alert\"\n              data-slot=\"newsletter-error\"\n              className=\"text-destructive mt-3 text-sm empty:mt-0\"\n            >\n              {status === \"error\" ? labels.error : null}\n            </p>\n            {note ? (\n              <p data-slot=\"newsletter-note\" className=\"text-muted-foreground mt-3 text-sm\">\n                {note}\n              </p>\n            ) : null}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport { Newsletter, type NewsletterLabels, type NewsletterProps, type NewsletterStatus };\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:block"
}