{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth",
  "title": "Auth",
  "description": "Primitives for signing in and joining a workspace: a full-page frame with one narrow centred card, the icon over a page's title, a one-time code input with a box per digit that handles paste, autofill and Backspace, a password input you can show, a password strength meter with the rules it still needs, a row of sign-in providers, a send-again button that counts down, the row at the bottom that leads to another way in, a square workspace avatar with a logo, a mark or initials, and an email masking helper.",
  "registryDependencies": [
    "button",
    "card",
    "input",
    "input-group",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/rolling-text.json",
    "https://www.dashboardblocks.com/r/radix/team.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/auth.tsx",
      "content": "'use client'\n\nimport { RollingText } from '@/registry/components/dashboardblocks/rolling-text'\nimport { getAvatarColor, getInitials } from '@/registry/components/dashboardblocks/team'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCountdown, formatList } from '@/registry/lib/dashboardblocks/format'\nimport {\n  type ClipboardEvent,\n  type ComponentProps,\n  type KeyboardEvent,\n  type ReactNode,\n  startTransition,\n  useEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\nimport { Input } from '@/components/ui/input'\nimport {\n  InputGroup,\n  InputGroupAddon,\n  InputGroupButton,\n  InputGroupInput,\n} from '@/components/ui/input-group'\n\nimport { cn } from '@/lib/utils'\n\ninterface AuthLayoutProps {\n  children: ReactNode\n  className?: string\n  description?: ReactNode\n  /** Above the title, such as an `AuthIcon` or the workspace's avatar. */\n  media?: ReactNode\n  title: ReactNode\n}\n\nfunction AuthLayout({ children, className, description, media, title }: AuthLayoutProps) {\n  return (\n    <div className={cn('@container/page flex min-h-svh flex-col', className)}>\n      <main className='flex flex-1 flex-col items-center justify-center px-4 py-12 sm:px-6'>\n        <Card className='w-full max-w-sm'>\n          <CardContent className='flex flex-col gap-6'>\n            <div className='flex flex-col items-start gap-4'>\n              {media}\n              <div className='flex flex-col gap-2'>\n                <h1 className='text-2xl font-semibold tracking-tight text-balance'>\n                  {title}\n                </h1>\n                {description && (\n                  <p className='text-muted-foreground text-pretty'>{description}</p>\n                )}\n              </div>\n            </div>\n            {children}\n          </CardContent>\n        </Card>\n      </main>\n    </div>\n  )\n}\n\n/** The icon above an auth page's title. `waiting` pulses while the page waits on the person, such as for a passkey; `done` draws a tick for a step that just finished. */\nfunction AuthIcon({\n  children,\n  className,\n  tone = 'default',\n}: {\n  children?: ReactNode\n  className?: string\n  /** @default 'default' */\n  tone?: 'default' | 'waiting' | 'done'\n}) {\n  return (\n    <span\n      data-slot='auth-icon'\n      data-tone={tone}\n      className={cn(\n        'relative flex size-12 shrink-0 items-center justify-center rounded-xl transition-colors duration-200 [&_svg]:size-6',\n        tone === 'done'\n          ? 'animate-in zoom-in-75 fade-in bg-emerald-500/10 text-emerald-700 duration-300 ease-out motion-reduce:animate-none dark:text-emerald-400'\n          : tone === 'waiting'\n            ? 'bg-muted text-foreground'\n            : 'bg-muted text-muted-foreground',\n        className,\n      )}\n    >\n      {tone === 'waiting' && (\n        <span className='absolute -end-1 -top-1 flex size-2.5 text-(--color-chart-2)'>\n          <span className='absolute inline-flex size-full animate-ping rounded-full bg-current opacity-60 motion-reduce:animate-none' />\n          <span className='relative inline-flex size-full rounded-full bg-current' />\n        </span>\n      )}\n      {tone === 'done' ? (\n        <IconPlaceholder\n          lucide='CircleCheckIcon'\n          tabler='IconCircleCheck'\n          hugeicons='CheckmarkCircle02Icon'\n          phosphor='CheckCircleIcon'\n          remixicon='RiCheckboxCircleLine'\n          aria-hidden\n        />\n      ) : (\n        children\n      )}\n    </span>\n  )\n}\n\ntype WorkspaceAvatarSize = 'sm' | 'default' | 'lg'\n\nconst workspaceAvatarSize: Record<WorkspaceAvatarSize, string> = {\n  default: 'size-9 rounded-lg text-xs',\n  lg: 'size-12 rounded-xl text-base',\n  sm: 'size-6 rounded-md text-xs',\n}\n\nfunction WorkspaceAvatar({\n  className,\n  logo,\n  mark,\n  name,\n  size = 'default',\n}: {\n  className?: string\n  /** An image of the workspace's logo. */\n  logo?: string\n  /** The workspace's mark, drawn in the primary colour, such as an SVG with `fill='currentColor'`. */\n  mark?: ReactNode\n  name: string\n  /** @default 'default' */\n  size?: WorkspaceAvatarSize\n}) {\n  const [failed, setFailed] = useState(false)\n  const image = logo && !failed\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        'flex shrink-0 items-center justify-center overflow-hidden font-semibold [&_svg]:size-1/2',\n        workspaceAvatarSize[size],\n        image\n          ? 'bg-muted'\n          : mark\n            ? 'bg-primary text-primary-foreground'\n            : getAvatarColor(name),\n        className,\n      )}\n    >\n      {image ? (\n        // oxlint-disable-next-line nextjs/no-img-element -- blocks install into any React project\n        <img\n          src={logo}\n          alt=''\n          className='size-full object-cover'\n          onError={() => setFailed(true)}\n        />\n      ) : (\n        (mark ?? getInitials(name))\n      )}\n    </span>\n  )\n}\n\ninterface OtpInputProps {\n  'aria-label'?: string\n  'aria-describedby'?: string\n  focusOnMount?: boolean\n  className?: string\n  disabled?: boolean\n  invalid?: boolean\n  /** @default 6 */\n  length?: number\n  onChange: (value: string) => void\n  /** Called once every box is filled, such as to submit. */\n  onComplete?: (value: string) => void\n  value: string\n}\n\nfunction resolveTypedDigits(current: string, entered: string) {\n  if (!current || entered.length !== 2) return entered\n  return entered.startsWith(current) ? entered[1] : entered[0]\n}\n\nfunction OtpInput({\n  'aria-describedby': describedBy,\n  'aria-label': label = 'Verification code',\n  focusOnMount = false,\n  className,\n  disabled = false,\n  invalid = false,\n  length = 6,\n  onChange,\n  onComplete,\n  value,\n}: OtpInputProps) {\n  const inputs = useRef<(HTMLInputElement | null)[]>([])\n  const digits = Array.from({ length }, (_, index) => value[index] ?? '')\n\n  useEffect(() => {\n    if (focusOnMount) inputs.current[0]?.focus()\n  }, [focusOnMount])\n\n  const set = (next: string, focus: number) => {\n    const clean = next.replace(/\\D/g, '').slice(0, length)\n    onChange(clean)\n    inputs.current[Math.min(focus, length - 1)]?.focus()\n    if (clean.length === length) onComplete?.(clean)\n  }\n\n  const isDigitInvalid = (index: number) =>\n    invalid && (value.length === length || index >= value.length)\n\n  const type = (index: number, typed: string) => {\n    const entered = resolveTypedDigits(digits[index], typed.replace(/\\D/g, ''))\n    if (!entered) return\n    if (entered.length > 1) return set(entered, entered.length)\n    const next = [...digits]\n    next[index] = entered\n    set(next.join(''), index + 1)\n  }\n\n  const keyDown = (index: number, event: KeyboardEvent<HTMLInputElement>) => {\n    if (event.key === 'Backspace') {\n      event.preventDefault()\n      const at = digits[index] ? index : index - 1\n      if (at < 0) return\n      set(digits.slice(0, at).join(''), at)\n    } else if (event.key === 'ArrowLeft') {\n      event.preventDefault()\n      inputs.current[Math.max(0, index - 1)]?.focus()\n    } else if (event.key === 'ArrowRight') {\n      event.preventDefault()\n      inputs.current[Math.min(value.length, index + 1, length - 1)]?.focus()\n    }\n  }\n\n  const paste = (event: ClipboardEvent<HTMLInputElement>) => {\n    event.preventDefault()\n    const pasted = event.clipboardData.getData('text').replace(/\\D/g, '')\n    if (pasted) set(pasted, pasted.length)\n  }\n\n  return (\n    <div\n      role='group'\n      aria-label={label}\n      aria-describedby={describedBy}\n      className={cn('flex justify-center gap-2', className)}\n    >\n      {digits.map((digit, index) => (\n        <Input\n          key={index}\n          ref={(node) => {\n            inputs.current[index] = node\n          }}\n          aria-label={`Digit ${index + 1} of ${length}`}\n          aria-invalid={isDigitInvalid(index) || undefined}\n          autoComplete={index === 0 ? 'one-time-code' : 'off'}\n          inputMode='numeric'\n          pattern='[0-9]*'\n          disabled={disabled}\n          value={digit}\n          tabIndex={index <= value.length ? 0 : -1}\n          onChange={(event) => type(index, event.target.value)}\n          onKeyDown={(event) => keyDown(index, event)}\n          onPaste={paste}\n          onFocus={(event) => event.target.select()}\n          className='h-11 w-11 min-w-0 shrink p-0 text-center font-mono text-base tabular-nums'\n        />\n      ))}\n    </div>\n  )\n}\n\nfunction maskEmail(email: string) {\n  const [name, domain] = email.split('@')\n  if (!domain) return email\n  return `${name[0]}${'•'.repeat(Math.min(3, Math.max(1, name.length - 1)))}@${domain}`\n}\n\n/** Unfolds what it holds, such as the fields only signing up needs, and keeps it out of the tab order while folded. */\nfunction AuthReveal({\n  children,\n  className,\n  open,\n}: {\n  children: ReactNode\n  className?: string\n  open: boolean\n}) {\n  return (\n    <div\n      data-slot='auth-reveal'\n      data-open={open || undefined}\n      inert={!open}\n      className={cn(\n        '-mx-4 grid grid-cols-[minmax(0,1fr)] transition-[grid-template-rows,opacity] duration-300 ease-[cubic-bezier(0.2,0,0,1)] motion-reduce:transition-none',\n        open ? 'grid-rows-[1fr] opacity-100' : 'grid-rows-[0fr] opacity-0',\n      )}\n    >\n      <div className='min-h-0 overflow-clip'>\n        <div className={cn('px-4 pt-1', className)}>{children}</div>\n      </div>\n    </div>\n  )\n}\n\nfunction PasswordInput({ className, ...props }: Omit<ComponentProps<'input'>, 'type'>) {\n  const [shown, setShown] = useState(false)\n  return (\n    <InputGroup className={className}>\n      <InputGroupInput type={shown ? 'text' : 'password'} {...props} />\n      <InputGroupAddon align='inline-end'>\n        <InputGroupButton\n          size='icon-xs'\n          aria-label='Show password'\n          aria-pressed={shown}\n          disabled={props.disabled}\n          onClick={() => setShown((current) => !current)}\n        >\n          {shown ? (\n            <IconPlaceholder\n              lucide='EyeOffIcon'\n              tabler='IconEyeOff'\n              hugeicons='ViewOffSlashIcon'\n              phosphor='EyeSlashIcon'\n              remixicon='RiEyeOffLine'\n            />\n          ) : (\n            <IconPlaceholder\n              lucide='EyeIcon'\n              tabler='IconEye'\n              hugeicons='ViewIcon'\n              phosphor='EyeIcon'\n              remixicon='RiEyeLine'\n            />\n          )}\n        </InputGroupButton>\n      </InputGroupAddon>\n    </InputGroup>\n  )\n}\n\ninterface PasswordRule {\n  /** What the password still needs, read as part of a sentence: \"a number\". */\n  label: string\n  test: (password: string) => boolean\n}\n\nconst passwordRules: PasswordRule[] = [\n  { label: '8 or more characters', test: (password) => password.length >= 8 },\n  { label: 'a number', test: (password) => /\\d/.test(password) },\n  { label: 'an uppercase letter', test: (password) => /[A-Z]/.test(password) },\n]\n\nfunction getMissingPasswordRules(password: string, rules = passwordRules) {\n  return rules.filter((rule) => !rule.test(password))\n}\n\nfunction describeMissingPasswordRules(password: string, rules = passwordRules) {\n  const missing = getMissingPasswordRules(password, rules)\n  return missing.length ? `Add ${formatList(missing.map((rule) => rule.label))}.` : ''\n}\n\nconst strengthWords = ['Too weak', 'Weak', 'Good', 'Strong']\n\nfunction PasswordStrength({\n  className,\n  id,\n  password,\n  rules = passwordRules,\n}: {\n  className?: string\n  id?: string\n  password: string\n  rules?: PasswordRule[]\n}) {\n  const met = rules.length - getMissingPasswordRules(password, rules).length\n  const word =\n    strengthWords[\n      Math.round((met / Math.max(rules.length, 1)) * (strengthWords.length - 1))\n    ]\n  return (\n    <div data-slot='password-strength' className={cn('flex flex-col gap-2', className)}>\n      <div\n        aria-hidden\n        className='grid gap-1.5'\n        style={{\n          gridTemplateColumns: `repeat(${rules.length}, minmax(0, 1fr))`,\n        }}\n      >\n        {rules.map((rule, index) => (\n          <span key={rule.label} className='bg-muted h-1 overflow-hidden rounded-full'>\n            <span\n              className='block h-full origin-left rounded-full bg-(--color-chart-2) transition-transform duration-500 ease-out motion-reduce:transition-none'\n              style={{ transform: `scaleX(${index < met ? 1 : 0})` }}\n            />\n          </span>\n        ))}\n      </div>\n      <p id={id} className='text-muted-foreground text-sm text-pretty'>\n        {password ? (\n          <>\n            <span className='text-foreground font-medium'>{word}.</span>{' '}\n            {describeMissingPasswordRules(password, rules) || 'Good to go.'}\n          </>\n        ) : (\n          `Use ${formatList(rules.map((rule) => rule.label))}.`\n        )}\n      </p>\n    </div>\n  )\n}\n\ninterface AuthProvider {\n  icon: ReactNode\n  id: string\n  name: string\n}\n\ninterface AuthProviderButtonsProps {\n  className?: string\n  disabled?: boolean\n  /** Send the person to the provider. A throw shows that the provider couldn't be reached. */\n  onSelect?: (id: string) => void | Promise<void>\n  providers: AuthProvider[]\n}\n\nfunction AuthProviderButtons({\n  className,\n  disabled = false,\n  onSelect,\n  providers,\n}: AuthProviderButtonsProps) {\n  const [pending, setPending] = useState<string | null>(null)\n  const [failed, setFailed] = useState<string | null>(null)\n\n  const select = async (provider: AuthProvider) => {\n    if (pending) return\n    setPending(provider.id)\n    setFailed(null)\n    try {\n      await onSelect?.(provider.id)\n    } catch {\n      startTransition(() => {\n        setPending(null)\n        setFailed(`We couldn’t reach ${provider.name}. Try again.`)\n      })\n    }\n  }\n\n  return (\n    <div\n      data-slot='auth-provider-buttons'\n      className={cn('flex flex-col gap-2', className)}\n    >\n      <div\n        className='grid gap-2'\n        style={{\n          gridTemplateColumns: `repeat(${providers.length}, minmax(0, 1fr))`,\n        }}\n      >\n        {providers.map((provider) => {\n          const isPending = pending === provider.id\n          return (\n            <button\n              key={provider.id}\n              type='button'\n              aria-label={`Continue with ${provider.name}`}\n              aria-disabled={disabled || (pending !== null && !isPending) || undefined}\n              data-pending={isPending || undefined}\n              onClick={() => {\n                if (!disabled) void select(provider)\n              }}\n              className='border-input bg-background hover:bg-muted focus-visible:border-ring focus-visible:ring-ring/50 dark:bg-input/30 dark:hover:bg-input/50 flex h-10 min-w-0 items-center justify-center rounded-lg border outline-none transition-[background-color,opacity] duration-200 focus-visible:ring-3 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-pending:bg-muted [&_svg]:size-5'\n            >\n              <span aria-hidden className='flex size-5 items-center justify-center'>\n                {isPending ? (\n                  <IconPlaceholder\n                    lucide='Loader2Icon'\n                    tabler='IconLoader2'\n                    hugeicons='Loading03Icon'\n                    phosphor='CircleNotchIcon'\n                    remixicon='RiLoader4Line'\n                    className='animate-spin motion-reduce:animate-none'\n                  />\n                ) : (\n                  provider.icon\n                )}\n              </span>\n            </button>\n          )\n        })}\n      </div>\n      {failed && (\n        <p role='alert' className='text-destructive text-sm'>\n          {failed}\n        </p>\n      )}\n    </div>\n  )\n}\n\nfunction AuthDivider({ children = 'or' }: { children?: ReactNode }) {\n  return (\n    <div className='text-muted-foreground flex items-center gap-3 text-xs'>\n      <span aria-hidden className='bg-border h-px flex-1' />\n      {children}\n      <span aria-hidden className='bg-border h-px flex-1' />\n    </div>\n  )\n}\n\nfunction CountdownRing({ seconds, total }: { seconds: number; total: number }) {\n  const circumference = 2 * Math.PI * 7\n  return (\n    <svg viewBox='0 0 18 18' aria-hidden className='size-4 -rotate-90'>\n      <circle cx='9' cy='9' r='7' fill='none' strokeWidth='2' className='stroke-muted' />\n      <circle\n        cx='9'\n        cy='9'\n        r='7'\n        fill='none'\n        strokeWidth='2'\n        strokeLinecap='round'\n        strokeDasharray={circumference}\n        strokeDashoffset={circumference * (1 - seconds / Math.max(total, 1))}\n        className='stroke-(--color-chart-2) transition-[stroke-dashoffset] duration-1000 ease-linear motion-reduce:transition-none'\n      />\n    </svg>\n  )\n}\n\ninterface AuthResendButtonProps {\n  className?: string\n  /** Seconds left before it can send again; a ring counts them down. */\n  cooldown: number\n  onClick: () => void\n  pending?: boolean\n  /** The full wait in seconds, so the ring starts full. */\n  total: number\n}\n\n/** Sends an email again, once its wait has run out. */\nfunction AuthResendButton({\n  className,\n  cooldown,\n  onClick,\n  pending = false,\n  total,\n}: AuthResendButtonProps) {\n  const waiting = cooldown > 0\n  return (\n    <Button\n      type='button'\n      variant='ghost'\n      size='sm'\n      className={cn('tabular-nums aria-disabled:opacity-100', className)}\n      aria-disabled={waiting || pending || undefined}\n      onClick={() => {\n        if (!waiting && !pending) onClick()\n      }}\n    >\n      {waiting ? (\n        <CountdownRing seconds={cooldown} total={total} />\n      ) : (\n        <IconPlaceholder\n          lucide='SendIcon'\n          tabler='IconSend'\n          hugeicons='SentIcon'\n          phosphor='PaperPlaneTiltIcon'\n          remixicon='RiSendPlaneLine'\n          data-icon='inline-start'\n        />\n      )}\n      {waiting\n        ? `Send again in ${formatCountdown(cooldown * 1000)}`\n        : pending\n          ? 'Sending'\n          : 'Send again'}\n    </Button>\n  )\n}\n\ninterface AuthSwitchProps {\n  className?: string\n  description: string\n  /** A link to another page; leave it out and pass `onClick` to switch in place. */\n  href?: string\n  onClick?: () => void\n  title: string\n}\n\n/** The last row of an auth page, leading to the other way in: from signing in to signing up, or back to sign-in. */\nfunction AuthSwitch({ className, description, href, onClick, title }: AuthSwitchProps) {\n  const content = (\n    <>\n      <span className='flex min-w-0 flex-1 flex-col gap-0.5'>\n        <RollingText text={title} wrap className='text-sm font-medium' />\n        <RollingText text={description} wrap className='text-muted-foreground text-sm' />\n      </span>\n      <span\n        aria-hidden\n        className='bg-primary text-primary-foreground flex size-8 shrink-0 items-center justify-center rounded-full transition-transform duration-200 ease-out group-hover/switch:translate-x-0.5 motion-reduce:transition-none [&_svg]:size-4'\n      >\n        <IconPlaceholder\n          lucide='ArrowRightIcon'\n          tabler='IconArrowRight'\n          hugeicons='ArrowRight01Icon'\n          phosphor='ArrowRightIcon'\n          remixicon='RiArrowRightLine'\n        />\n      </span>\n    </>\n  )\n  const rowClassName =\n    'group/switch hover:bg-muted/60 focus-visible:ring-ring/50 -mx-3 flex w-[calc(100%+1.5rem)] items-center gap-3 rounded-lg px-3 py-2.5 text-start outline-none transition-colors duration-200 focus-visible:ring-3'\n  return (\n    <div data-slot='auth-switch' className={cn('border-t pt-3', className)}>\n      {href ? (\n        <a href={href} className={rowClassName}>\n          {content}\n        </a>\n      ) : (\n        <button type='button' onClick={onClick} className={rowClassName}>\n          {content}\n        </button>\n      )}\n    </div>\n  )\n}\n\nexport {\n  AuthDivider,\n  AuthIcon,\n  AuthLayout,\n  AuthProviderButtons,\n  AuthResendButton,\n  AuthReveal,\n  AuthSwitch,\n  OtpInput,\n  PasswordInput,\n  PasswordStrength,\n  WorkspaceAvatar,\n  describeMissingPasswordRules,\n  getMissingPasswordRules,\n  maskEmail,\n  passwordRules,\n}\n\nexport type {\n  AuthLayoutProps,\n  AuthProvider,\n  AuthProviderButtonsProps,\n  AuthResendButtonProps,\n  AuthSwitchProps,\n  OtpInputProps,\n  PasswordRule,\n  WorkspaceAvatarSize,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/auth.tsx"
    }
  ],
  "type": "registry:component"
}
