{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "login-form",
  "type": "registry:block",
  "title": "Login form",
  "description": "Email and password login with 'Remember me', 'Forgot password?' and an optional sign-up link. Validates on blur and submit; a server error shows in a Banner above the fields.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://unbuiltui.com/r/banner.json",
    "https://unbuiltui.com/r/button.json",
    "https://unbuiltui.com/r/checkbox.json",
    "https://unbuiltui.com/r/input.json",
    "https://unbuiltui.com/r/utils.json"
  ],
  "files": [
    {
      "path": "components/blocks/login-form.tsx",
      "type": "registry:component",
      "target": "components/blocks/login-form.tsx",
      "content": "\"use client\";\n\nimport { CircleAlert } from \"lucide-react\";\nimport { type FormEvent, useId, useState } from \"react\";\nimport { Banner, BannerDescription, BannerTitle } from \"@/components/ui/banner\";\nimport { Button } from \"@/components/ui/button\";\nimport { Checkbox } from \"@/components/ui/checkbox\";\nimport { Field, FieldError, FieldLabel } from \"@/components/ui/field\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { PasswordInput } from \"@/components/ui/password-input\";\nimport { cn } from \"@/lib/utils\";\n\n// UnbuiltUI block: email and password login. Field errors appear after the user\n// leaves a field or submits; a server error (wrong password) goes in a Banner.\n\nexport type LoginFormValues = { email: string; password: string; remember: boolean };\n\ntype LoginFormProps = {\n  title?: string;\n  description?: string;\n  /** Server-side error, e.g. \"Wrong email or password\". */\n  error?: string;\n  loading?: boolean;\n  /** Starting values, e.g. a remembered email. */\n  defaultValues?: Partial<LoginFormValues>;\n  onSubmit?: (values: LoginFormValues) => void;\n  onForgotPassword?: () => void;\n  onSignUp?: () => void;\n  className?: string;\n};\n\nconst emailPattern = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nfunction validate({ email, password }: LoginFormValues) {\n  return {\n    email: emailPattern.test(email) ? undefined : \"Enter an email like jane@mail.com\",\n    password: password.length >= 8 ? undefined : \"Enter at least 8 characters\",\n  };\n}\n\nfunction LoginForm({\n  title = \"Log in\",\n  description = \"Welcome back. Enter your details to continue.\",\n  error,\n  loading = false,\n  defaultValues,\n  onSubmit,\n  onForgotPassword,\n  onSignUp,\n  className,\n}: LoginFormProps) {\n  const id = useId();\n  const [values, setValues] = useState<LoginFormValues>({\n    email: \"\",\n    password: \"\",\n    remember: true,\n    ...defaultValues,\n  });\n  const [touched, setTouched] = useState({ email: false, password: false });\n  const errors = validate(values);\n  const show = {\n    email: touched.email ? errors.email : undefined,\n    password: touched.password ? errors.password : undefined,\n  };\n\n  function submit(event: FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    setTouched({ email: true, password: true });\n    if (!errors.email && !errors.password) onSubmit?.(values);\n  }\n\n  return (\n    <form\n      noValidate\n      onSubmit={submit}\n      data-slot=\"login-form\"\n      className={cn(\"flex w-full max-w-sm flex-col gap-6\", className)}\n    >\n      <div className=\"flex flex-col gap-1.5\">\n        <h1 className=\"font-semibold text-2xl tracking-tight\">{title}</h1>\n        <p className=\"text-muted-foreground text-sm\">{description}</p>\n      </div>\n\n      {error && (\n        <Banner variant=\"destructive\">\n          <CircleAlert />\n          <BannerTitle>{error}</BannerTitle>\n          <BannerDescription>Check your details and try again.</BannerDescription>\n        </Banner>\n      )}\n\n      <div className=\"flex flex-col gap-4\">\n        <Field>\n          <FieldLabel htmlFor={`${id}-email`}>Email</FieldLabel>\n          <Input\n            id={`${id}-email`}\n            type=\"email\"\n            autoComplete=\"email\"\n            placeholder=\"jane@mail.com\"\n            value={values.email}\n            onChange={(e) => setValues({ ...values, email: e.target.value })}\n            onBlur={() => setTouched({ ...touched, email: true })}\n            aria-invalid={Boolean(show.email)}\n            aria-describedby={show.email ? `${id}-email-error` : undefined}\n          />\n          {show.email && <FieldError id={`${id}-email-error`}>{show.email}</FieldError>}\n        </Field>\n        <Field>\n          <div className=\"flex items-center justify-between\">\n            <FieldLabel htmlFor={`${id}-password`}>Password</FieldLabel>\n            <Button\n              type=\"button\"\n              variant=\"link\"\n              className=\"h-auto p-0 font-normal text-muted-foreground text-sm\"\n              onClick={onForgotPassword}\n            >\n              Forgot password?\n            </Button>\n          </div>\n          <PasswordInput\n            id={`${id}-password`}\n            autoComplete=\"current-password\"\n            value={values.password}\n            onChange={(e) => setValues({ ...values, password: e.target.value })}\n            onBlur={() => setTouched({ ...touched, password: true })}\n            aria-invalid={Boolean(show.password)}\n            aria-describedby={show.password ? `${id}-password-error` : undefined}\n          />\n          {show.password && <FieldError id={`${id}-password-error`}>{show.password}</FieldError>}\n        </Field>\n        <div className=\"flex items-center gap-3\">\n          <Checkbox\n            id={`${id}-remember`}\n            checked={values.remember}\n            onCheckedChange={(checked) => setValues({ ...values, remember: checked === true })}\n          />\n          <Label htmlFor={`${id}-remember`} className=\"font-normal\">\n            Remember me\n          </Label>\n        </div>\n      </div>\n\n      <div className=\"flex flex-col gap-3\">\n        <Button type=\"submit\" size=\"lg\" className=\"w-full\" loading={loading}>\n          {loading ? \"Logging in\" : \"Log in\"}\n        </Button>\n        {onSignUp && (\n          <p className=\"text-center text-muted-foreground text-sm\">\n            Don't have an account?{\" \"}\n            <Button type=\"button\" variant=\"link\" className=\"h-auto p-0\" onClick={onSignUp}>\n              Sign up\n            </Button>\n          </p>\n        )}\n      </div>\n    </form>\n  );\n}\n\nexport { LoginForm };\n"
    }
  ]
}
