{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "login-form",
  "title": "Login Form",
  "description": "A centred sign-in card with email and password fields, a remember-me checkbox, optional sign-in providers and pending, success and error states.",
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/button",
    "@corsair-ui/card",
    "@corsair-ui/checkbox",
    "@corsair-ui/field",
    "@corsair-ui/input",
    "@corsair-ui/password-input",
    "@corsair-ui/separator"
  ],
  "files": [
    {
      "path": "registry/default/components/blocks/login-form.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 { Card, CardContent, CardFooter, CardHeader } from \"@/registry/default/ui/card\";\nimport { Checkbox } from \"@/registry/default/ui/checkbox\";\nimport { Field, FieldLabel } from \"@/registry/default/ui/field\";\nimport { Input } from \"@/registry/default/ui/input\";\nimport { PasswordInput } from \"@/registry/default/ui/password-input\";\nimport { Separator } from \"@/registry/default/ui/separator\";\n\n/** What the form hands to `onSubmit`, read from its fields with FormData. */\ninterface LoginFormValues {\n  email: string;\n  password: string;\n  /** Whether \"Remember me\" was checked; always `false` when `showRemember` is off. */\n  remember: boolean;\n}\n\n/** A third-party sign-in option, rendered as an outline button under the form. */\ninterface LoginFormProvider {\n  /** React key; defaults to `label`. */\n  id?: string;\n  /** Visible text, such as \"Continue with GitHub\". */\n  label: string;\n  /** Decorative icon before the label; it is hidden from screen readers. */\n  icon?: ReactNode;\n  /** Renders a button that calls this. Ignored when `href` is set. */\n  onClick?: () => void;\n  /** Renders a link instead of a button. */\n  href?: string;\n}\n\n/** Every string the form shows, including the button and status messages. */\ninterface LoginFormLabels {\n  email: ReactNode;\n  password: ReactNode;\n  /** Accessible name of the button that reveals the password. */\n  showPassword: string;\n  forgot: ReactNode;\n  remember: ReactNode;\n  submit: ReactNode;\n  /** Button text while `onSubmit` is running. */\n  pending: ReactNode;\n  /** Announced in the status region once `onSubmit` resolves. */\n  success: ReactNode;\n  /** Announced in the alert region when `onSubmit` throws. */\n  error: ReactNode;\n  /** Text in the separator above the providers. */\n  or: ReactNode;\n  /** Text before the sign-up link in the footer. */\n  signupPrompt: ReactNode;\n  signup: ReactNode;\n}\n\ntype LoginFormStatus = \"idle\" | \"pending\" | \"success\" | \"error\";\n\nconst defaultLabels: LoginFormLabels = {\n  email: \"Email\",\n  password: \"Password\",\n  showPassword: \"Show password\",\n  forgot: \"Forgot password?\",\n  remember: \"Remember me\",\n  submit: \"Sign in\",\n  pending: \"Signing in…\",\n  success: \"You're signed in.\",\n  error: \"Could not sign you in. Check your email and password and try again.\",\n  or: \"or continue with\",\n  signupPrompt: \"Don't have an account?\",\n  signup: \"Sign up\",\n};\n\nconst linkClassName =\n  \"text-foreground focus-visible:ring-ring/50 rounded-md font-medium underline-offset-4 outline-none hover:underline focus-visible:ring-[3px]\";\n\ninterface LoginFormProps extends Omit<ComponentProps<\"section\">, \"title\" | \"onSubmit\"> {\n  /** Card title, rendered as an `<h1>` since the form is usually the page's main content. */\n  title?: ReactNode;\n  description?: ReactNode;\n  /** Target of the \"Forgot password?\" link. Pass `null` to hide the link. */\n  forgotHref?: string | null;\n  /** Target of the \"Sign up\" link in the footer. Pass `null` to hide the footer line. */\n  signupHref?: string | null;\n  /** Shows the \"Remember me\" checkbox. */\n  showRemember?: boolean;\n  /** Third-party sign-in options shown under a separator. None by default. */\n  providers?: LoginFormProvider[];\n  /** Overrides for any of the form's strings; the rest keep their English defaults. */\n  labels?: Partial<LoginFormLabels>;\n  /**\n   * Called with the field values instead of a native submit. While it runs the\n   * button is disabled; resolving resets the form and shows `labels.success`,\n   * throwing keeps the values and shows `labels.error`.\n   */\n  onSubmit?: (values: LoginFormValues) => void | Promise<void>;\n  /** Props for the `<form>`, such as `action` and `method` for a native submit. */\n  formProps?: ComponentProps<\"form\">;\n}\n\n/**\n * A sign-in card centred in a section: a title, a description, email and\n * password fields, a \"Forgot password?\" link, a \"Remember me\" checkbox, the\n * submit button, optional third-party providers under an \"or continue with\"\n * separator and a \"Don't have an account? Sign up\" line.\n * `<LoginForm />` renders a complete example.\n *\n * Both fields are `required` with `autoComplete` (\"email\" and\n * \"current-password\"), so the browser validates them and password managers\n * fill them. The password field has a button to reveal what was typed\n * (`aria-pressed` tells its state). The section is named by its `<h1>`.\n *\n * With `onSubmit`, 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 `onSubmit` the form submits natively: pass `action` and `method`\n * through `formProps`. The checkbox then submits `remember=on` when checked.\n *\n * @example\n * <LoginForm\n *   forgotHref=\"/forgot-password\"\n *   signupHref=\"/sign-up\"\n *   providers={[{ label: \"Continue with SSO\", href: \"/sso\" }]}\n *   onSubmit={async (values) => {\n *     await signIn(values);\n *   }}\n * />\n */\nfunction LoginForm({\n  title = \"Sign in to your account\",\n  description = \"Enter your email and password to continue.\",\n  forgotHref = \"#forgot-password\",\n  signupHref = \"#sign-up\",\n  showRemember = true,\n  providers,\n  labels: labelsProp,\n  onSubmit,\n  formProps,\n  className,\n  ...props\n}: LoginFormProps) {\n  const id = useId();\n  const [status, setStatus] = useState<LoginFormStatus>(\"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 (!onSubmit || 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 data = new FormData(form);\n    const values: LoginFormValues = {\n      email: String(data.get(\"email\") ?? \"\"),\n      password: String(data.get(\"password\") ?? \"\"),\n      remember: data.get(\"remember\") != null,\n    };\n\n    setStatus(\"pending\");\n    try {\n      await onSubmit(values);\n      form.reset();\n      setStatus(\"success\");\n    } catch {\n      setStatus(\"error\");\n    }\n  }\n\n  return (\n    <section\n      data-slot=\"login-form\"\n      data-status={status}\n      aria-labelledby={`${id}-title`}\n      className={cn(\"py-16 sm:py-24\", className)}\n      {...props}\n    >\n      <div\n        data-slot=\"login-form-container\"\n        className=\"mx-auto flex w-full max-w-6xl justify-center px-4 sm:px-6\"\n      >\n        <Card data-slot=\"login-form-card\" className=\"w-full max-w-sm\">\n          <CardHeader data-slot=\"login-form-header\">\n            <h1\n              id={`${id}-title`}\n              data-slot=\"login-form-title\"\n              className=\"text-xl leading-tight font-semibold tracking-tight\"\n            >\n              {title}\n            </h1>\n            {description ? (\n              <p data-slot=\"login-form-description\" className=\"text-muted-foreground text-sm\">\n                {description}\n              </p>\n            ) : null}\n          </CardHeader>\n          <CardContent data-slot=\"login-form-content\" className=\"flex flex-col gap-6\">\n            <form\n              data-slot=\"login-form-form\"\n              data-status={status}\n              {...formProps}\n              className={cn(\"flex flex-col gap-6\", formProps?.className)}\n              onSubmit={handleSubmit}\n            >\n              <Field>\n                <FieldLabel htmlFor={`${id}-email`}>{labels.email}</FieldLabel>\n                <Input id={`${id}-email`} name=\"email\" type=\"email\" autoComplete=\"email\" required />\n              </Field>\n              <Field>\n                <div className=\"flex items-center justify-between gap-2\">\n                  <FieldLabel htmlFor={`${id}-password`}>{labels.password}</FieldLabel>\n                  {forgotHref != null ? (\n                    <a\n                      href={forgotHref}\n                      data-slot=\"login-form-forgot\"\n                      className={cn(linkClassName, \"text-sm\")}\n                    >\n                      {labels.forgot}\n                    </a>\n                  ) : null}\n                </div>\n                <PasswordInput\n                  id={`${id}-password`}\n                  name=\"password\"\n                  autoComplete=\"current-password\"\n                  toggleLabel={labels.showPassword}\n                  required\n                />\n              </Field>\n              {showRemember ? (\n                <Field orientation=\"horizontal\" data-slot=\"login-form-remember\">\n                  <Checkbox id={`${id}-remember`} name=\"remember\" />\n                  <FieldLabel htmlFor={`${id}-remember`} className=\"font-normal\">\n                    {labels.remember}\n                  </FieldLabel>\n                </Field>\n              ) : null}\n              <div data-slot=\"login-form-footer\">\n                <Button\n                  type=\"submit\"\n                  data-slot=\"login-form-submit\"\n                  loading={pending}\n                  className=\"w-full\"\n                >\n                  {pending ? labels.pending : labels.submit}\n                </Button>\n                <p role=\"status\" data-slot=\"login-form-success\" className=\"mt-4 text-sm empty:mt-0\">\n                  {status === \"success\" ? labels.success : null}\n                </p>\n                <p\n                  role=\"alert\"\n                  data-slot=\"login-form-error\"\n                  className=\"text-destructive mt-4 text-sm empty:mt-0\"\n                >\n                  {status === \"error\" ? labels.error : null}\n                </p>\n              </div>\n            </form>\n            {providers && providers.length > 0 ? (\n              <div data-slot=\"login-form-providers\" className=\"flex flex-col gap-4\">\n                <div data-slot=\"login-form-separator\" className=\"flex items-center gap-3\">\n                  <Separator className=\"flex-1\" />\n                  <span className=\"text-muted-foreground text-xs\">{labels.or}</span>\n                  <Separator className=\"flex-1\" />\n                </div>\n                <div className=\"grid gap-2\">\n                  {providers.map((provider) => {\n                    const content = (\n                      <>\n                        {provider.icon ? (\n                          <span aria-hidden=\"true\" className=\"contents\">\n                            {provider.icon}\n                          </span>\n                        ) : null}\n                        {provider.label}\n                      </>\n                    );\n                    return provider.href != null ? (\n                      <Button\n                        key={provider.id ?? provider.label}\n                        asChild\n                        variant=\"outline\"\n                        data-slot=\"login-form-provider\"\n                        className=\"w-full\"\n                      >\n                        <a href={provider.href}>{content}</a>\n                      </Button>\n                    ) : (\n                      <Button\n                        key={provider.id ?? provider.label}\n                        type=\"button\"\n                        variant=\"outline\"\n                        data-slot=\"login-form-provider\"\n                        className=\"w-full\"\n                        onClick={provider.onClick}\n                      >\n                        {content}\n                      </Button>\n                    );\n                  })}\n                </div>\n              </div>\n            ) : null}\n          </CardContent>\n          {signupHref != null ? (\n            <CardFooter data-slot=\"login-form-signup\" className=\"justify-center\">\n              <p className=\"text-muted-foreground text-center text-sm\">\n                {labels.signupPrompt}{\" \"}\n                <a href={signupHref} className={linkClassName}>\n                  {labels.signup}\n                </a>\n              </p>\n            </CardFooter>\n          ) : null}\n        </Card>\n      </div>\n    </section>\n  );\n}\n\nexport {\n  LoginForm,\n  type LoginFormLabels,\n  type LoginFormProps,\n  type LoginFormProvider,\n  type LoginFormStatus,\n  type LoginFormValues,\n};\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:block"
}