{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "signup-form",
  "type": "registry:block",
  "title": "Sign-up form",
  "description": "Create an account with full name, email and password. A strength bar under the password guides the user, the terms checkbox is required, and a server error (email already taken) shows in a Banner.",
  "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/progress.json",
    "https://unbuiltui.com/r/utils.json"
  ],
  "files": [
    {
      "path": "components/blocks/signup-form.tsx",
      "type": "registry:component",
      "target": "components/blocks/signup-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, FieldDescription, 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 { Progress } from \"@/components/ui/progress\";\nimport { cn } from \"@/lib/utils\";\n\n// UnbuiltUI block: create an account with name, email and password. A strength bar\n// guides the password; the terms checkbox must be ticked; server errors use a Banner.\n\nexport type SignupFormValues = { name: string; email: string; password: string };\n\ntype SignupFormProps = {\n  title?: string;\n  description?: string;\n  /** Server-side error, e.g. \"An account with this email already exists\". */\n  error?: string;\n  loading?: boolean;\n  onSubmit?: (values: SignupFormValues) => void;\n  onLogIn?: () => void;\n  /** Where the terms link points. */\n  termsHref?: string;\n  className?: string;\n};\n\nconst emailPattern = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\n/** 0 to 4: one point each for length 8+, 12+, mixed case and a digit or symbol. */\nfunction passwordScore(password: string) {\n  return [\n    password.length >= 8,\n    password.length >= 12,\n    /[a-z]/.test(password) && /[A-Z]/.test(password),\n    /[\\d\\W]/.test(password),\n  ].filter(Boolean).length;\n}\n\nconst strength = [\n  { label: \"Too short\", variant: \"destructive\" },\n  { label: \"Weak\", variant: \"destructive\" },\n  { label: \"Fair\", variant: \"warning\" },\n  { label: \"Good\", variant: \"success\" },\n  { label: \"Strong\", variant: \"success\" },\n] as const;\n\nfunction SignupForm({\n  title = \"Create your account\",\n  description = \"It takes less than a minute.\",\n  error,\n  loading = false,\n  onSubmit,\n  onLogIn,\n  termsHref = \"/terms\",\n  className,\n}: SignupFormProps) {\n  const id = useId();\n  const [values, setValues] = useState<SignupFormValues>({ name: \"\", email: \"\", password: \"\" });\n  const [terms, setTerms] = useState(false);\n  const [touched, setTouched] = useState({ name: false, email: false, password: false });\n  const [submitted, setSubmitted] = useState(false);\n  const score = values.password.length < 8 ? 0 : passwordScore(values.password);\n  const level = strength[score] ?? strength[0];\n  const errors = {\n    name: values.name.trim() ? undefined : \"Enter your name\",\n    email: emailPattern.test(values.email) ? undefined : \"Enter an email like jane@mail.com\",\n    password: values.password.length >= 8 ? undefined : \"Use at least 8 characters\",\n    terms: terms ? undefined : \"Accept the terms to continue\",\n  };\n  const show = (field: keyof typeof touched) =>\n    touched[field] || submitted ? errors[field] : undefined;\n\n  function submit(event: FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    setSubmitted(true);\n    if (Object.values(errors).every((e) => !e)) onSubmit?.(values);\n  }\n\n  const field = (name: \"name\" | \"email\", label: string, type: string, autoComplete: string) => (\n    <Field>\n      <FieldLabel htmlFor={`${id}-${name}`}>{label}</FieldLabel>\n      <Input\n        id={`${id}-${name}`}\n        type={type}\n        autoComplete={autoComplete}\n        value={values[name]}\n        onChange={(e) => setValues({ ...values, [name]: e.target.value })}\n        onBlur={() => setTouched({ ...touched, [name]: true })}\n        aria-invalid={Boolean(show(name))}\n        aria-describedby={show(name) ? `${id}-${name}-error` : undefined}\n      />\n      {show(name) && <FieldError id={`${id}-${name}-error`}>{show(name)}</FieldError>}\n    </Field>\n  );\n\n  return (\n    <form\n      noValidate\n      onSubmit={submit}\n      data-slot=\"signup-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          {onLogIn && <BannerDescription>Try logging in instead.</BannerDescription>}\n        </Banner>\n      )}\n\n      <div className=\"flex flex-col gap-4\">\n        {field(\"name\", \"Full name\", \"text\", \"name\")}\n        {field(\"email\", \"Email\", \"email\", \"email\")}\n        <Field>\n          <FieldLabel htmlFor={`${id}-password`}>Password</FieldLabel>\n          <PasswordInput\n            id={`${id}-password`}\n            autoComplete=\"new-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={`${id}-password-help`}\n          />\n          {values.password && (\n            <div className=\"flex items-center gap-3\">\n              <Progress\n                value={(Math.max(score, 1) / 4) * 100}\n                variant={level.variant}\n                aria-label=\"Password strength\"\n                className=\"h-1.5\"\n              />\n              <span className=\"w-16 shrink-0 text-right text-[13px] text-muted-foreground\">\n                {level.label}\n              </span>\n            </div>\n          )}\n          {show(\"password\") ? (\n            <FieldError id={`${id}-password-help`}>{show(\"password\")}</FieldError>\n          ) : (\n            <FieldDescription id={`${id}-password-help`}>\n              8 or more characters. Mix cases and add a number to make it stronger.\n            </FieldDescription>\n          )}\n        </Field>\n        <Field>\n          <div className=\"flex items-start gap-3\">\n            <Checkbox\n              id={`${id}-terms`}\n              checked={terms}\n              onCheckedChange={(checked) => setTerms(checked === true)}\n              aria-invalid={Boolean(submitted && errors.terms)}\n              className=\"mt-0.5\"\n            />\n            <Label htmlFor={`${id}-terms`} className=\"font-normal leading-5\">\n              <span>\n                I agree to the{\" \"}\n                <a href={termsHref} className=\"font-medium text-foreground underline\">\n                  Terms and Privacy Policy\n                </a>\n              </span>\n            </Label>\n          </div>\n          {submitted && errors.terms && <FieldError>{errors.terms}</FieldError>}\n        </Field>\n      </div>\n\n      <div className=\"flex flex-col gap-3\">\n        <Button type=\"submit\" size=\"lg\" className=\"w-full\" loading={loading}>\n          {loading ? \"Creating account\" : \"Create account\"}\n        </Button>\n        {onLogIn && (\n          <p className=\"text-center text-muted-foreground text-sm\">\n            Already have an account?{\" \"}\n            <Button type=\"button\" variant=\"link\" className=\"h-auto p-0\" onClick={onLogIn}>\n              Log in\n            </Button>\n          </p>\n        )}\n      </div>\n    </form>\n  );\n}\n\nexport { SignupForm };\n"
    }
  ]
}
