{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"login-form","type":"registry:ui","title":"Login Form","description":"A polished sign-in card with social buttons, password reveal, remember me, animated inline validation, a shake on error and a loading-to-success flow.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/login-form.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useId, useState, type FormEvent, type ReactNode } from \"react\";\nimport { AnimatePresence, motion, useAnimationControls, useReducedMotion } from \"motion/react\";\nimport { ArrowRight, Check, CircleAlert, Eye, EyeOff, LoaderCircle, Lock, Mail } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface LoginValues {\n  email: string;\n  password: string;\n  remember: boolean;\n}\n\nexport type SocialProvider = \"github\" | \"google\";\n\nexport interface LoginFormProps {\n  title?: string;\n  description?: string;\n  /** Show the GitHub / Google buttons. */\n  showSocial?: boolean;\n  /** Show the \"Remember me\" checkbox. */\n  showRemember?: boolean;\n  /** Minimum password length accepted by client-side validation. */\n  minPasswordLength?: number;\n  submitLabel?: string;\n  /** Called with valid values. Throw (or reject) with an Error to show its message as a form error. */\n  onSubmit?: (values: LoginValues) => void | Promise<void>;\n  /** Called when a social button is pressed. The button spins until the promise settles. */\n  onSocial?: (provider: SocialProvider) => void | Promise<void>;\n  /** Content under the card, e.g. a sign-up link. */\n  footer?: ReactNode;\n  className?: string;\n}\n\ntype Errors = Partial<Record<\"email\" | \"password\", string>>;\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\nconst wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));\n\nfunction validate(email: string, password: string, min: number): Errors {\n  const e: Errors = {};\n  if (!email.trim()) e.email = \"Email is required.\";\n  else if (!EMAIL.test(email.trim())) e.email = \"Enter a valid email address.\";\n  if (!password) e.password = \"Password is required.\";\n  else if (password.length < min) e.password = `Use at least ${min} characters.`;\n  return e;\n}\n\nconst GitHubMark = () => (\n  <svg viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden className=\"size-4\">\n    <path d=\"M12 .5a11.5 11.5 0 0 0-3.64 22.41c.58.1.79-.25.79-.56v-2c-3.2.7-3.88-1.37-3.88-1.37-.52-1.33-1.28-1.69-1.28-1.69-1.05-.72.08-.7.08-.7 1.16.08 1.77 1.19 1.77 1.19 1.03 1.77 2.7 1.26 3.36.96.1-.75.4-1.26.73-1.55-2.55-.29-5.24-1.28-5.24-5.68 0-1.26.45-2.28 1.19-3.09-.12-.29-.52-1.46.11-3.05 0 0 .97-.31 3.17 1.18a11 11 0 0 1 5.77 0c2.2-1.49 3.17-1.18 3.17-1.18.63 1.59.23 2.76.11 3.05.74.81 1.19 1.83 1.19 3.09 0 4.41-2.69 5.38-5.26 5.67.41.36.78 1.06.78 2.14v3.17c0 .31.21.67.8.56A11.5 11.5 0 0 0 12 .5Z\" />\n  </svg>\n);\n\nconst GoogleMark = () => (\n  <svg viewBox=\"0 0 24 24\" aria-hidden className=\"size-4\">\n    <path fill=\"#4285F4\" d=\"M23.5 12.27c0-.85-.08-1.66-.22-2.45H12v4.63h6.46a5.52 5.52 0 0 1-2.4 3.62v3h3.88c2.27-2.09 3.56-5.17 3.56-8.8Z\" />\n    <path fill=\"#34A853\" d=\"M12 24c3.24 0 5.96-1.07 7.94-2.9l-3.88-3.01c-1.07.72-2.45 1.15-4.06 1.15-3.13 0-5.78-2.11-6.72-4.95H1.27v3.1A12 12 0 0 0 12 24Z\" />\n    <path fill=\"#FBBC05\" d=\"M5.28 14.29a7.2 7.2 0 0 1 0-4.58v-3.1H1.27a12 12 0 0 0 0 10.78l4.01-3.1Z\" />\n    <path fill=\"#EA4335\" d=\"M12 4.77c1.76 0 3.34.61 4.59 1.8l3.44-3.44A11.97 11.97 0 0 0 1.27 6.61l4.01 3.1C6.22 6.88 8.87 4.77 12 4.77Z\" />\n  </svg>\n);\n\nconst inputCls = cn(\n  \"peer h-11 w-full rounded-xl border border-input bg-background/60 pl-10 text-sm text-foreground shadow-xs outline-none\",\n  \"placeholder:text-muted-foreground/70 transition-[border-color,box-shadow,background-color] duration-200\",\n  \"hover:border-foreground/20 focus:border-ring focus:bg-background focus:ring-[3px] focus:ring-ring/25\",\n  \"aria-invalid:border-destructive aria-invalid:focus:ring-destructive/25 disabled:opacity-60\",\n);\n\nfunction FieldError({ id, children }: { id: string; children?: string }) {\n  return (\n    <AnimatePresence initial={false}>\n      {children && (\n        <motion.p\n          key=\"err\"\n          id={id}\n          initial={{ height: 0, opacity: 0 }}\n          animate={{ height: \"auto\", opacity: 1 }}\n          exit={{ height: 0, opacity: 0 }}\n          transition={{ duration: 0.2 }}\n          className=\"overflow-hidden text-xs text-destructive\"\n        >\n          <span className=\"flex items-center gap-1.5 pt-1.5\">\n            <CircleAlert className=\"size-3.5 shrink-0\" aria-hidden />\n            {children}\n          </span>\n        </motion.p>\n      )}\n    </AnimatePresence>\n  );\n}\n\nexport function LoginForm({\n  title = \"Welcome back\",\n  description = \"Sign in to continue to your workspace.\",\n  showSocial = true,\n  showRemember = true,\n  minPasswordLength = 8,\n  submitLabel = \"Sign in\",\n  onSubmit = () => wait(1400),\n  onSocial = () => wait(1200),\n  footer,\n  className,\n}: LoginFormProps) {\n  const id = useId();\n  const reduce = useReducedMotion();\n  const shake = useAnimationControls();\n  const [email, setEmail] = useState(\"\");\n  const [password, setPassword] = useState(\"\");\n  const [remember, setRemember] = useState(true);\n  const [reveal, setReveal] = useState(false);\n  const [touched, setTouched] = useState<Record<string, boolean>>({});\n  const [status, setStatus] = useState<\"idle\" | \"loading\" | \"success\">(\"idle\");\n  const [formError, setFormError] = useState(\"\");\n  const [social, setSocial] = useState<SocialProvider | null>(null);\n\n  const errors = validate(email, password, minPasswordLength);\n  const show = (k: keyof Errors) => (touched[k] ? errors[k] : undefined);\n  const busy = status === \"loading\" || social !== null;\n\n  const submit = async (e: FormEvent<HTMLFormElement>) => {\n    e.preventDefault();\n    setTouched({ email: true, password: true });\n    setFormError(\"\");\n    if (errors.email || errors.password) {\n      if (!reduce) shake.start({ x: [0, -10, 9, -6, 4, 0], transition: { duration: 0.4 } });\n      e.currentTarget.querySelector<HTMLInputElement>(\"[aria-invalid=true]\")?.focus();\n      return;\n    }\n    setStatus(\"loading\");\n    try {\n      await onSubmit({ email: email.trim(), password, remember });\n      setStatus(\"success\");\n    } catch (err) {\n      setStatus(\"idle\");\n      setFormError(err instanceof Error ? err.message : \"Something went wrong. Try again.\");\n      if (!reduce) shake.start({ x: [0, -10, 9, -6, 4, 0], transition: { duration: 0.4 } });\n    }\n  };\n\n  const pressSocial = async (p: SocialProvider) => {\n    setSocial(p);\n    try {\n      await onSocial(p);\n    } finally {\n      setSocial(null);\n    }\n  };\n\n  const reset = () => {\n    setStatus(\"idle\");\n    setPassword(\"\");\n    setTouched({});\n  };\n\n  return (\n    <motion.div\n      animate={shake}\n      className={cn(\n        \"relative w-full max-w-sm overflow-hidden rounded-3xl border border-border bg-card p-7 text-card-foreground shadow-2xl shadow-black/20\",\n        className,\n      )}\n    >\n      {/* soft brand glow along the top edge */}\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-x-0 -top-24 h-48 bg-[radial-gradient(closest-side,color-mix(in_oklch,var(--primary)_28%,transparent),transparent)]\"\n      />\n      <AnimatePresence mode=\"wait\" initial={false}>\n        {status === \"success\" ? (\n          <motion.div\n            key=\"done\"\n            initial={{ opacity: 0, scale: 0.96 }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0 }}\n            className=\"relative grid place-items-center py-8 text-center\"\n            role=\"status\"\n          >\n            <motion.span\n              initial={reduce ? false : { scale: 0, rotate: -45 }}\n              animate={{ scale: 1, rotate: 0 }}\n              transition={{ type: \"spring\", stiffness: 380, damping: 18, delay: 0.05 }}\n              className=\"grid size-14 place-items-center rounded-full bg-primary text-primary-foreground shadow-lg shadow-primary/30\"\n            >\n              <Check className=\"size-7\" strokeWidth={3} aria-hidden />\n            </motion.span>\n            <h2 className=\"mt-5 text-xl font-semibold tracking-tight\">You&apos;re signed in</h2>\n            <p className=\"mt-1 text-sm text-muted-foreground\">\n              Welcome back, <span className=\"font-medium text-foreground\">{email.trim()}</span>\n            </p>\n            <button\n              type=\"button\"\n              onClick={reset}\n              className=\"mt-6 rounded-lg px-3 py-1.5 text-sm font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n            >\n              Sign out\n            </button>\n          </motion.div>\n        ) : (\n          <motion.form\n            key=\"form\"\n            noValidate\n            onSubmit={submit}\n            aria-labelledby={`${id}-t`}\n            aria-busy={busy}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0, scale: 0.98 }}\n            className=\"relative\"\n          >\n            <div className=\"mb-6\">\n              <div\n                aria-hidden\n                className=\"mb-5 grid size-10 place-items-center rounded-xl bg-gradient-to-br from-primary to-primary/50 text-primary-foreground shadow-md shadow-primary/25\"\n              >\n                <Lock className=\"size-4.5\" />\n              </div>\n              <h2 id={`${id}-t`} className=\"text-2xl font-semibold tracking-tight\">\n                {title}\n              </h2>\n              {description && <p className=\"mt-1 text-sm text-muted-foreground\">{description}</p>}\n            </div>\n\n            <fieldset disabled={busy} className=\"grid gap-4\">\n              {showSocial && (\n                <>\n                  <div className=\"grid grid-cols-2 gap-2.5\">\n                    {([\"github\", \"google\"] as const).map((p) => (\n                      <button\n                        key={p}\n                        type=\"button\"\n                        onClick={() => pressSocial(p)}\n                        className=\"inline-flex h-10 items-center justify-center gap-2 rounded-xl border border-border bg-background/60 text-sm font-medium outline-none transition-[background-color,scale] hover:bg-muted focus-visible:ring-[3px] focus-visible:ring-ring/50 active:scale-[0.97] disabled:opacity-60\"\n                      >\n                        {social === p ? (\n                          <LoaderCircle className=\"size-4 animate-spin\" aria-hidden />\n                        ) : p === \"github\" ? (\n                          <GitHubMark />\n                        ) : (\n                          <GoogleMark />\n                        )}\n                        {p === \"github\" ? \"GitHub\" : \"Google\"}\n                      </button>\n                    ))}\n                  </div>\n                  <div className=\"flex items-center gap-3 text-[11px] font-medium tracking-wider text-muted-foreground uppercase\">\n                    <span className=\"h-px flex-1 bg-border\" />\n                    or with email\n                    <span className=\"h-px flex-1 bg-border\" />\n                  </div>\n                </>\n              )}\n\n              <AnimatePresence initial={false}>\n                {formError && (\n                  <motion.div\n                    role=\"alert\"\n                    initial={{ opacity: 0, y: -6 }}\n                    animate={{ opacity: 1, y: 0 }}\n                    exit={{ opacity: 0, y: -6 }}\n                    className=\"flex items-start gap-2 rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-2.5 text-sm text-destructive\"\n                  >\n                    <CircleAlert className=\"mt-0.5 size-4 shrink-0\" aria-hidden />\n                    {formError}\n                  </motion.div>\n                )}\n              </AnimatePresence>\n\n              <div>\n                <label htmlFor={`${id}-e`} className=\"mb-1.5 block text-sm font-medium\">\n                  Email\n                </label>\n                <div className=\"relative\">\n                  <input\n                    id={`${id}-e`}\n                    type=\"email\"\n                    autoComplete=\"email\"\n                    placeholder=\"you@company.com\"\n                    value={email}\n                    onChange={(e) => setEmail(e.target.value)}\n                    onBlur={() => setTouched((t) => ({ ...t, email: true }))}\n                    aria-invalid={!!show(\"email\")}\n                    aria-describedby={show(\"email\") ? `${id}-ee` : undefined}\n                    className={cn(inputCls, \"pr-3\")}\n                  />\n                  <Mail className=\"pointer-events-none absolute top-1/2 left-3.5 size-4 -translate-y-1/2 text-muted-foreground transition-colors peer-focus:text-foreground\" aria-hidden />\n                </div>\n                <FieldError id={`${id}-ee`}>{show(\"email\")}</FieldError>\n              </div>\n\n              <div>\n                <div className=\"mb-1.5 flex items-center justify-between\">\n                  <label htmlFor={`${id}-p`} className=\"text-sm font-medium\">\n                    Password\n                  </label>\n                  <a href=\"#\" onClick={(e) => e.preventDefault()} className=\"rounded text-xs font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\">\n                    Forgot password?\n                  </a>\n                </div>\n                <div className=\"relative\">\n                  <input\n                    id={`${id}-p`}\n                    type={reveal ? \"text\" : \"password\"}\n                    autoComplete=\"current-password\"\n                    placeholder=\"••••••••\"\n                    value={password}\n                    onChange={(e) => setPassword(e.target.value)}\n                    onBlur={() => setTouched((t) => ({ ...t, password: true }))}\n                    aria-invalid={!!show(\"password\")}\n                    aria-describedby={show(\"password\") ? `${id}-pe` : undefined}\n                    className={cn(inputCls, \"pr-11\")}\n                  />\n                  <Lock className=\"pointer-events-none absolute top-1/2 left-3.5 size-4 -translate-y-1/2 text-muted-foreground transition-colors peer-focus:text-foreground\" aria-hidden />\n                  <button\n                    type=\"button\"\n                    onClick={() => setReveal((v) => !v)}\n                    aria-label={reveal ? \"Hide password\" : \"Show password\"}\n                    aria-pressed={reveal}\n                    className=\"absolute top-1/2 right-1.5 grid size-8 -translate-y-1/2 place-items-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\"\n                  >\n                    <AnimatePresence mode=\"wait\" initial={false}>\n                      <motion.span\n                        key={reveal ? \"off\" : \"on\"}\n                        initial={{ opacity: 0, rotate: -30, scale: 0.7 }}\n                        animate={{ opacity: 1, rotate: 0, scale: 1 }}\n                        exit={{ opacity: 0, rotate: 30, scale: 0.7 }}\n                        transition={{ duration: 0.15 }}\n                      >\n                        {reveal ? <EyeOff className=\"size-4\" aria-hidden /> : <Eye className=\"size-4\" aria-hidden />}\n                      </motion.span>\n                    </AnimatePresence>\n                  </button>\n                </div>\n                <FieldError id={`${id}-pe`}>{show(\"password\")}</FieldError>\n              </div>\n\n              {showRemember && (\n                <label className=\"flex w-fit cursor-pointer items-center gap-2.5 text-sm text-muted-foreground select-none\">\n                  <input\n                    type=\"checkbox\"\n                    checked={remember}\n                    onChange={(e) => setRemember(e.target.checked)}\n                    className=\"size-4 cursor-pointer rounded accent-primary outline-none focus-visible:ring-2 focus-visible:ring-ring/50\"\n                  />\n                  Remember me for 30 days\n                </label>\n              )}\n\n              <button\n                type=\"submit\"\n                className=\"group relative mt-1 inline-flex h-11 items-center justify-center gap-2 overflow-hidden rounded-xl bg-primary text-sm font-semibold text-primary-foreground shadow-md shadow-primary/25 outline-none transition-[background-color,scale,box-shadow] hover:bg-primary/90 hover:shadow-lg hover:shadow-primary/30 focus-visible:ring-[3px] focus-visible:ring-ring/50 active:scale-[0.98] disabled:opacity-80\"\n              >\n                <AnimatePresence mode=\"wait\" initial={false}>\n                  {status === \"loading\" ? (\n                    <motion.span key=\"l\" className=\"inline-flex items-center gap-2\" initial={{ y: 12, opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={{ y: -12, opacity: 0 }}>\n                      <LoaderCircle className=\"size-4 animate-spin\" aria-hidden />\n                      Signing in…\n                    </motion.span>\n                  ) : (\n                    <motion.span key=\"i\" className=\"inline-flex items-center gap-2\" initial={{ y: 12, opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={{ y: -12, opacity: 0 }}>\n                      {submitLabel}\n                      <ArrowRight className=\"size-4 transition-transform group-hover:translate-x-0.5\" aria-hidden />\n                    </motion.span>\n                  )}\n                </AnimatePresence>\n              </button>\n            </fieldset>\n            {footer && <div className=\"mt-5 text-center text-sm text-muted-foreground\">{footer}</div>}\n          </motion.form>\n        )}\n      </AnimatePresence>\n    </motion.div>\n  );\n}\n"}]}