{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sign-in-card",
  "type": "registry:block",
  "title": "Sign-in Card",
  "description": "Email and password sign-in with a peek toggle, a one-tap switch to magic links, passkey and SSO buttons, a gentle shake on errors and a calm check-your-inbox state.",
  "categories": [
    "block",
    "Auth"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/input.json",
    "https://coss.com/ui/r/input-group.json",
    "https://coss.com/ui/r/spinner.json"
  ],
  "files": [
    {
      "path": "registry/devl/sign-in-card.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ArrowLeftIcon,\n  CheckIcon,\n  CircleAlertIcon,\n  EyeIcon,\n  EyeOffIcon,\n  type LucideIcon,\n  MailIcon,\n  MailOpenIcon,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useAnimationControls, useReducedMotion } from \"motion/react\";\nimport { type FormEvent, type ReactNode, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { InputGroup, InputGroupAddon, InputGroupInput } from \"@/components/ui/input-group\";\nimport { Spinner } from \"@/components/ui/spinner\";\nimport { cn } from \"@/lib/utils\";\n\nexport type SignInMethod = \"password\" | \"link\";\n\nexport interface SignInProvider {\n  id: string;\n  label: string;\n  icon: LucideIcon;\n}\n\nexport type SignInResult = { ok: true; name?: string } | { ok: false; error: string };\n\nexport interface SignInCardProps {\n  product?: string;\n  logo?: ReactNode;\n  providers?: SignInProvider[];\n  defaultEmail?: string;\n  defaultMethod?: SignInMethod;\n  resendAfter?: number;\n  onPasswordSignIn?: (email: string, password: string) => Promise<SignInResult>;\n  onSendLink?: (email: string) => Promise<void>;\n  onProvider?: (provider: SignInProvider) => void;\n  onForgotPassword?: (email: string) => void;\n  onCreateAccount?: () => void;\n  className?: string;\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst press = \"transition-[box-shadow,scale,background-color] duration-150 active:scale-[0.97]\";\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\n\nfunction useMeasuredHeight<T extends HTMLElement>() {\n  const ref = useRef<T>(null);\n  const [height, setHeight] = useState<number | \"auto\">(\"auto\");\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setHeight(el.offsetHeight));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, height] as const;\n}\n\nfunction MethodSwitch({ value, onChange }: { value: SignInMethod; onChange: (m: SignInMethod) => void }) {\n  const reduce = useReducedMotion();\n  const layoutId = useId();\n  const options: { value: SignInMethod; label: string }[] = [\n    { value: \"password\", label: \"Password\" },\n    { value: \"link\", label: \"Email link\" },\n  ];\n  return (\n    <div aria-label=\"Sign-in method\" className=\"grid grid-cols-2 rounded-lg bg-muted p-0.5\" role=\"radiogroup\">\n      {options.map((o) => {\n        const active = o.value === value;\n        return (\n          <button\n            aria-checked={active}\n            className={cn(\n              \"relative h-8 cursor-pointer rounded-[calc(var(--radius-lg)-2px)] font-medium text-sm outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-ring\",\n              active ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n            )}\n            key={o.value}\n            onClick={() => onChange(o.value)}\n            onKeyDown={(e) => {\n              if (e.key === \"ArrowLeft\" || e.key === \"ArrowRight\") {\n                e.preventDefault();\n                const next = o.value === \"password\" ? \"link\" : \"password\";\n                onChange(next);\n                (e.currentTarget.parentElement?.querySelector(`[data-value=${next}]`) as HTMLElement | null)?.focus();\n              }\n            }}\n            data-value={o.value}\n            role=\"radio\"\n            tabIndex={active ? 0 : -1}\n            type=\"button\"\n          >\n            {active && (\n              <motion.span\n                className=\"absolute inset-0 rounded-[inherit] bg-background shadow-xs/5 dark:bg-accent\"\n                layoutId={layoutId}\n                transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 40 }}\n              />\n            )}\n            <span className=\"relative\">{o.label}</span>\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n\nfunction FieldMessage({ id, children }: { id: string; children?: string }) {\n  return (\n    <AnimatePresence initial={false}>\n      {children && (\n        <motion.p\n          animate={{ height: \"auto\", opacity: 1 }}\n          className=\"overflow-hidden text-destructive-foreground text-xs\"\n          exit={{ height: 0, opacity: 0 }}\n          id={id}\n          initial={{ height: 0, opacity: 0 }}\n          transition={{ duration: 0.18, ease }}\n        >\n          <span className=\"block pt-1.5\">{children}</span>\n        </motion.p>\n      )}\n    </AnimatePresence>\n  );\n}\n\nfunction formatClock(s: number) {\n  return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, \"0\")}`;\n}\n\nexport function SignInCard({\n  product = \"Larkspur\",\n  logo,\n  providers = [],\n  defaultEmail = \"\",\n  defaultMethod = \"password\",\n  resendAfter = 30,\n  onPasswordSignIn = async () => ({ ok: true }),\n  onSendLink = async () => {},\n  onProvider,\n  onForgotPassword,\n  onCreateAccount,\n  className,\n}: SignInCardProps) {\n  const reduce = useReducedMotion();\n  const uid = useId();\n  const [contentRef, height] = useMeasuredHeight<HTMLDivElement>();\n  const shake = useAnimationControls();\n  const passwordRef = useRef<HTMLInputElement>(null);\n\n  const [view, setView] = useState<\"form\" | \"sent\" | \"done\">(\"form\");\n  const [method, setMethod] = useState<SignInMethod>(defaultMethod);\n  const [email, setEmail] = useState(defaultEmail);\n  const [password, setPassword] = useState(\"\");\n  const [showPassword, setShowPassword] = useState(false);\n  const [busy, setBusy] = useState(false);\n  const [emailError, setEmailError] = useState<string>();\n  const [passwordError, setPasswordError] = useState<string>();\n  const [formError, setFormError] = useState<string>();\n  const [welcome, setWelcome] = useState<string>();\n  const [cooldown, setCooldown] = useState(0);\n\n  useEffect(() => {\n    if (cooldown <= 0) return;\n    const t = setTimeout(() => setCooldown((c) => c - 1), 1000);\n    return () => clearTimeout(t);\n  }, [cooldown]);\n\n  const fail = (message: string) => {\n    setFormError(message);\n    if (!reduce) shake.start({ x: [0, -6, 6, -3, 3, 0], transition: { duration: 0.32, ease: \"easeOut\" } });\n  };\n\n  const sendLink = async () => {\n    setBusy(true);\n    await onSendLink(email.trim());\n    setBusy(false);\n    setCooldown(resendAfter);\n    setView(\"sent\");\n  };\n\n  const submit = async (event: FormEvent) => {\n    event.preventDefault();\n    setFormError(undefined);\n    const trimmed = email.trim();\n    const badEmail = !trimmed ? \"Enter your email address.\" : !EMAIL.test(trimmed) ? \"That doesn't look like an email address.\" : undefined;\n    const badPassword = method === \"password\" && !password ? \"Enter your password.\" : undefined;\n    setEmailError(badEmail);\n    setPasswordError(badPassword);\n    if (badEmail || badPassword) {\n      if (!reduce) shake.start({ x: [0, -4, 4, 0], transition: { duration: 0.24, ease: \"easeOut\" } });\n      return;\n    }\n    if (method === \"link\") return sendLink();\n    setBusy(true);\n    const result = await onPasswordSignIn(trimmed, password);\n    setBusy(false);\n    if (result.ok) {\n      setWelcome(result.name);\n      setView(\"done\");\n    } else {\n      fail(result.error);\n      setPassword(\"\");\n      passwordRef.current?.focus();\n    }\n  };\n\n  // `animate` stays identical with reduced motion so server and client render the same styles.\n  const viewMotion = {\n    initial: reduce ? { opacity: 0, y: 0, filter: \"blur(0px)\" } : { opacity: 0, y: 8, filter: \"blur(4px)\" },\n    animate: { opacity: 1, y: 0, filter: \"blur(0px)\" },\n    exit: reduce ? { opacity: 0, y: 0, filter: \"blur(0px)\" } : { opacity: 0, y: -8, filter: \"blur(4px)\" },\n  };\n\n  return (\n    <div className={cn(\"mx-auto w-full max-w-[400px]\", className)}>\n      <div className=\"overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-xs/5\">\n        <motion.div\n          animate={{ height }}\n          className=\"relative\"\n          initial={false}\n          transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 40 }}\n        >\n          <div ref={contentRef}>\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              {view === \"form\" && (\n                <motion.div key=\"form\" {...viewMotion} transition={{ duration: 0.22, ease }}>\n                  <div className=\"px-6 pt-7 pb-6 sm:px-8\">\n                    <header className=\"flex flex-col items-center text-center\">\n                      {logo ?? (\n                        <span className=\"flex size-10 items-center justify-center rounded-xl bg-primary text-primary-foreground shadow-xs/5\">\n                          <svg aria-hidden className=\"size-6\" fill=\"currentColor\" viewBox=\"0 0 24 24\">\n                            <circle cx=\"12\" cy=\"8.5\" r=\"4.75\" />\n                            <circle cx=\"7.75\" cy=\"15\" opacity=\".7\" r=\"4.75\" />\n                            <circle cx=\"16.25\" cy=\"15\" opacity=\".45\" r=\"4.75\" />\n                          </svg>\n                        </span>\n                      )}\n                      <h2 className=\"mt-4 text-balance font-semibold text-lg tracking-tight\">Sign in to {product}</h2>\n                      <p className=\"mt-1 text-pretty text-muted-foreground text-sm\">Welcome back. Pick up where you left off.</p>\n                    </header>\n\n                    {providers.length > 0 && (\n                      <>\n                        <div className={cn(\"mt-6 grid gap-2\", providers.length > 1 && \"grid-cols-2\")}>\n                          {providers.map((p) => (\n                            <Button className={press} key={p.id} onClick={() => onProvider?.(p)} variant=\"outline\">\n                              <p.icon />\n                              {p.label}\n                            </Button>\n                          ))}\n                        </div>\n                        <div className=\"my-5 flex items-center gap-3 text-muted-foreground text-xs\">\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                    <motion.form animate={shake} className={cn(!providers.length && \"mt-6\")} noValidate onSubmit={submit}>\n                      <MethodSwitch\n                        onChange={(m) => {\n                          setMethod(m);\n                          setFormError(undefined);\n                          setPasswordError(undefined);\n                        }}\n                        value={method}\n                      />\n\n                      <AnimatePresence initial={false}>\n                        {formError && (\n                          <motion.div\n                            animate={{ height: \"auto\", opacity: 1 }}\n                            className=\"overflow-hidden\"\n                            exit={{ height: 0, opacity: 0 }}\n                            initial={{ height: 0, opacity: 0 }}\n                            transition={{ duration: 0.2, ease }}\n                          >\n                            <div\n                              className=\"mt-4 flex gap-2.5 rounded-xl border border-destructive/20 bg-destructive/6 p-3 text-sm dark:bg-destructive/12\"\n                              role=\"alert\"\n                            >\n                              <CircleAlertIcon className=\"mt-0.5 size-4 shrink-0 text-destructive-foreground\" />\n                              <div className=\"min-w-0\">\n                                <p className=\"text-pretty text-foreground\">{formError}</p>\n                                <button\n                                  className=\"mt-1 cursor-pointer rounded font-medium text-destructive-foreground text-xs underline-offset-2 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                                  onClick={() => {\n                                    setMethod(\"link\");\n                                    setFormError(undefined);\n                                  }}\n                                  type=\"button\"\n                                >\n                                  Email me a sign-in link instead\n                                </button>\n                              </div>\n                            </div>\n                          </motion.div>\n                        )}\n                      </AnimatePresence>\n\n                      <div className=\"mt-4\">\n                        <label className=\"font-medium text-sm\" htmlFor={`${uid}-email`}>\n                          Email\n                        </label>\n                        <Input\n                          aria-describedby={emailError ? `${uid}-email-error` : undefined}\n                          aria-invalid={emailError ? true : undefined}\n                          autoComplete=\"email\"\n                          className=\"mt-2\"\n                          id={`${uid}-email`}\n                          onChange={(e) => {\n                            setEmail(e.target.value);\n                            if (emailError) setEmailError(undefined);\n                          }}\n                          placeholder=\"you@company.com\"\n                          type=\"email\"\n                          value={email}\n                        />\n                        <FieldMessage id={`${uid}-email-error`}>{emailError}</FieldMessage>\n                      </div>\n\n                      <AnimatePresence initial={false}>\n                        {method === \"password\" && (\n                          <motion.div\n                            animate={{ height: \"auto\", opacity: 1 }}\n                            className=\"-mx-1 -mb-1 overflow-hidden px-1\"\n                            exit={{ height: 0, opacity: 0 }}\n                            initial={{ height: 0, opacity: 0 }}\n                            transition={reduce ? { duration: 0 } : { duration: 0.22, ease }}\n                          >\n                            <div className=\"pt-4 pb-1\">\n                              <div className=\"flex items-center justify-between\">\n                                <label className=\"font-medium text-sm\" htmlFor={`${uid}-password`}>\n                                  Password\n                                </label>\n                                <button\n                                  className=\"relative -my-1 cursor-pointer rounded px-1 py-1 text-muted-foreground text-xs after:absolute after:-inset-x-1 after:-inset-y-1.5 outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n                                  onClick={() => onForgotPassword?.(email)}\n                                  type=\"button\"\n                                >\n                                  Forgot password?\n                                </button>\n                              </div>\n                              <InputGroup className=\"mt-2\">\n                                <InputGroupInput\n                                  aria-describedby={passwordError ? `${uid}-password-error` : undefined}\n                                  aria-invalid={passwordError || formError ? true : undefined}\n                                  autoComplete=\"current-password\"\n                                  id={`${uid}-password`}\n                                  onChange={(e) => {\n                                    setPassword(e.target.value);\n                                    if (passwordError) setPasswordError(undefined);\n                                  }}\n                                  placeholder=\"Your password\"\n                                  ref={passwordRef}\n                                  type={showPassword ? \"text\" : \"password\"}\n                                  value={password}\n                                />\n                                <InputGroupAddon align=\"inline-end\">\n                                  <Button\n                                    aria-label={showPassword ? \"Hide password\" : \"Show password\"}\n                                    aria-pressed={showPassword}\n                                    className=\"text-muted-foreground hover:text-foreground\"\n                                    onClick={() => setShowPassword((s) => !s)}\n                                    size=\"icon-xs\"\n                                    variant=\"ghost\"\n                                  >\n                                    <AnimatePresence initial={false} mode=\"popLayout\">\n                                      <motion.span\n                                        animate={{ opacity: 1, scale: 1 }}\n                                        className=\"flex\"\n                                        exit={{ opacity: 0, scale: 0.6 }}\n                                        initial={{ opacity: 0, scale: 0.6 }}\n                                        key={showPassword ? \"hide\" : \"show\"}\n                                        transition={{ duration: 0.14, ease }}\n                                      >\n                                        {showPassword ? <EyeOffIcon /> : <EyeIcon />}\n                                      </motion.span>\n                                    </AnimatePresence>\n                                  </Button>\n                                </InputGroupAddon>\n                              </InputGroup>\n                              <FieldMessage id={`${uid}-password-error`}>{passwordError}</FieldMessage>\n                            </div>\n                          </motion.div>\n                        )}\n                      </AnimatePresence>\n\n                      <AnimatePresence initial={false}>\n                        {method === \"link\" && (\n                          <motion.p\n                            animate={{ height: \"auto\", opacity: 1 }}\n                            className=\"overflow-hidden text-muted-foreground text-xs\"\n                            exit={{ height: 0, opacity: 0 }}\n                            initial={{ height: 0, opacity: 0 }}\n                            transition={reduce ? { duration: 0 } : { duration: 0.22, ease }}\n                          >\n                            <span className=\"block pt-2\">We’ll email you a link that signs you in. No password needed.</span>\n                          </motion.p>\n                        )}\n                      </AnimatePresence>\n\n                      <Button className={cn(\"mt-5 w-full\", press)} loading={busy} size=\"lg\" type=\"submit\">\n                        {method === \"password\" ? \"Sign in\" : \"Email me a link\"}\n                      </Button>\n                    </motion.form>\n                  </div>\n                  <footer className=\"border-t bg-muted/40 px-6 py-3.5 text-center text-muted-foreground text-sm sm:px-8\">\n                    New to {product}?{\" \"}\n                    <button\n                      className=\"cursor-pointer rounded font-medium text-foreground underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                      onClick={onCreateAccount}\n                      type=\"button\"\n                    >\n                      Create an account\n                    </button>\n                  </footer>\n                </motion.div>\n              )}\n\n              {view === \"sent\" && (\n                <motion.div className=\"px-6 py-8 text-center sm:px-8\" key=\"sent\" {...viewMotion} transition={{ duration: 0.24, ease }}>\n                  <Envelope />\n                  <h2 className=\"mt-5 text-balance font-semibold text-lg tracking-tight\">Check your inbox</h2>\n                  <p className=\"mx-auto mt-1.5 max-w-[30ch] text-pretty text-muted-foreground text-sm\">\n                    We sent a sign-in link to <span className=\"font-medium text-foreground\">{email.trim()}</span>. It expires in 15 minutes.\n                  </p>\n                  <div className=\"mt-6 grid gap-2\">\n                    <Button\n                      className={press}\n                      disabled={cooldown > 0 || busy}\n                      onClick={sendLink}\n                      variant=\"outline\"\n                    >\n                      {busy ? (\n                        <Spinner />\n                      ) : cooldown > 0 ? (\n                        <span className=\"tabular-nums\">Resend in {formatClock(cooldown)}</span>\n                      ) : (\n                        <>\n                          <MailIcon />\n                          Resend link\n                        </>\n                      )}\n                    </Button>\n                    <Button\n                      className={cn(\"text-muted-foreground\", press)}\n                      onClick={() => {\n                        setView(\"form\");\n                        setMethod(\"link\");\n                      }}\n                      variant=\"ghost\"\n                    >\n                      <ArrowLeftIcon />\n                      Use a different email\n                    </Button>\n                  </div>\n                  <p className=\"mt-5 text-pretty text-muted-foreground text-xs\">Can’t find it? Check spam, or search for “{product}”.</p>\n                </motion.div>\n              )}\n\n              {view === \"done\" && (\n                <motion.div className=\"px-6 py-10 text-center sm:px-8\" key=\"done\" {...viewMotion} transition={{ duration: 0.24, ease }}>\n                  <motion.span\n                    animate={{ scale: 1, opacity: 1 }}\n                    className=\"mx-auto flex size-12 items-center justify-center rounded-full bg-success/12 text-success-foreground\"\n                    initial={reduce ? false : { scale: 0.8, opacity: 0 }}\n                    transition={{ type: \"spring\", stiffness: 420, damping: 22, delay: 0.05 }}\n                  >\n                    <CheckIcon className=\"size-6\" />\n                  </motion.span>\n                  <h2 className=\"mt-4 font-semibold text-lg tracking-tight\">{welcome ? `Welcome back, ${welcome}` : \"You're signed in\"}</h2>\n                  <p className=\"mt-1 flex items-center justify-center gap-2 text-muted-foreground text-sm\">\n                    <Spinner className=\"size-3.5\" />\n                    Taking you to your workspace…\n                  </p>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n        </motion.div>\n      </div>\n    </div>\n  );\n}\n\nfunction Envelope() {\n  const reduce = useReducedMotion();\n  return (\n    <div className=\"relative mx-auto size-16\">\n      <motion.span\n        animate={{ scale: 1, opacity: 1, rotate: 0 }}\n        className=\"absolute inset-0 flex items-center justify-center rounded-2xl border bg-muted text-foreground\"\n        initial={reduce ? false : { scale: 0.85, opacity: 0, rotate: -6 }}\n        transition={{ type: \"spring\", stiffness: 380, damping: 22 }}\n      >\n        <MailOpenIcon className=\"size-7\" strokeWidth={1.5} />\n      </motion.span>\n      <motion.span\n        animate={{ scale: 1, opacity: 1 }}\n        className=\"absolute -top-1.5 -right-1.5 flex size-6 items-center justify-center rounded-full border-2 border-card bg-success text-white\"\n        initial={reduce ? false : { scale: 0.5, opacity: 0 }}\n        transition={{ type: \"spring\", stiffness: 500, damping: 24, delay: 0.18 }}\n      >\n        <CheckIcon className=\"size-3.5\" strokeWidth={3} />\n      </motion.span>\n    </div>\n  );\n}\n"
    }
  ]
}