{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-screen",
  "title": "Auth screen",
  "description": "What the Sign in and Sign up blocks share, so the two screens look, move and read as one: the screen with your logo and the card, the email box, the \"or\" line, the Google, GitHub and Apple buttons, the screen that ends the card, and a resend that counts down.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/icon-tile.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/card.json",
    "https://kinoui.com/r/input.json",
    "https://kinoui.com/r/input-group.json",
    "https://kinoui.com/r/separator.json",
    "https://kinoui.com/r/social-sign-in.json",
    "https://kinoui.com/r/announce.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/swap.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/auth-screen.tsx",
      "content": "'use client'\n\nimport { Button } from '@/registry/components/kino/button'\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from '@/registry/components/kino/card'\nimport { IconTile } from '@/registry/components/kino/icon-tile'\nimport type { InputControl } from '@/registry/components/kino/input'\nimport {\n  InputGroup,\n  InputGroupAddon,\n  InputGroupInput,\n} from '@/registry/components/kino/input-group'\nimport { Separator } from '@/registry/components/kino/separator'\nimport {\n  providers,\n  SocialSignIn,\n  SocialSignInButton,\n  type SocialProvider,\n  type SocialSignInLayout,\n} from '@/registry/components/kino/social-sign-in'\nimport { announce } from '@/registry/lib/announce'\nimport { markMounted } from '@/registry/lib/refs'\nimport { Swap } from '@/registry/lib/swap'\nimport {\n  type ComponentProps,\n  type ReactNode,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * What the Sign in and Sign up blocks share, so the two screens look, move\n * and read as one: the screen with your logo and the card, the email box,\n * the \"or\" line, the Google, GitHub and Apple buttons, the screen that ends\n * the card, and a resend that counts down.\n */\n\n/**\n * Your product's logo, at the top of the screen. Replace the mark and the\n * name with your own; it's drawn in the text colour, in `--font-logo` when\n * you set it and the page's font when you don't.\n */\nfunction AuthLogo({ className }: { className?: string }) {\n  const id = useId()\n  return (\n    <span\n      className={cn(\n        'inline-flex shrink-0 items-baseline gap-[0.33em] font-[family-name:var(--font-logo,inherit)] text-[26px] leading-none font-semibold tracking-[-0.025em] lowercase',\n        className,\n      )}\n    >\n      <svg viewBox='0 0 84.6 90' aria-hidden className='h-[0.73em] w-auto shrink-0'>\n        <mask id={id}>\n          <g fill='none' strokeWidth='18' strokeLinecap='round' strokeLinejoin='round'>\n            <path\n              d='M75.6 9 L39.6 45 L75.6 81'\n              className='stroke-[#727272] dark:stroke-[#4d4d4d]'\n            />\n            <path\n              d='M60.3 9 L24.3 45 L60.3 81'\n              className='stroke-[#bcbcbc] dark:stroke-[#959595]'\n            />\n            <path d='M45 9 L9 45 L45 81' stroke='white' />\n          </g>\n        </mask>\n        <rect width='84.6' height='90' fill='currentColor' mask={`url(#${id})`} />\n      </svg>\n      <span>Kino</span>\n    </span>\n  )\n}\n\ntype AuthHeading = 'h1' | 'h2' | 'h3'\n\n/**\n * The screen: the logo, the card with its heading and the form, and what\n * sits under the card. Given `end`, the card gives way to it, taking its\n * height, and focus moves to it once it has arrived; without, the form\n * comes back and focus goes to its first field.\n */\nfunction AuthScreen({\n  title,\n  description,\n  heading: Heading = 'h1',\n  footer,\n  end,\n  slot,\n  className,\n  children,\n}: {\n  /** The screen's `data-slot`, such as `sign-in`, so each block can be styled and found on its own. */\n  slot: string\n  title: string\n  description?: ReactNode\n  heading?: AuthHeading\n  footer?: ReactNode\n  /** What ends the screen, such as who is signed in; the form goes while it shows. */\n  end?: ReactNode\n  className?: string\n  children: ReactNode\n}) {\n  const ended = end != null && end !== false\n  const focusRef = useFocusStep<HTMLDivElement>(ended ? 'end' : 'form')\n\n  return (\n    <div\n      data-slot={slot}\n      ref={markMounted}\n      className={cn('@container flex min-h-full w-full flex-col items-center', className)}\n    >\n      {/* Held at the top, so the card grows and shrinks downward and the logo never\n          moves. A container query reads the page, so this column takes the padding. */}\n      <div className='flex w-full max-w-sm flex-col items-center gap-6 @md:py-16'>\n        {/* Narrower than a small tablet, the card drops its frame, as a phone's sign-in does. */}\n        <Card\n          ref={focusRef}\n          className='w-full @max-md:border-transparent @max-md:bg-transparent @max-md:shadow-none'\n        >\n          <div className='px-(--surface-padding)'>\n            <AuthLogo />\n          </div>\n          <Swap fill block wait id={ended ? 'end' : 'form'}>\n            {ended ? (\n              <CardContent className='w-full'>{end}</CardContent>\n            ) : (\n              <div className='flex w-full min-w-0 flex-col gap-(--surface-gap)'>\n                <CardHeader>\n                  {/* oxlint-disable-next-line jsx-a11y/heading-has-content -- the title's text goes in through the part's props. */}\n                  <CardTitle render={<Heading />}>{title}</CardTitle>\n                  {description ? <CardDescription>{description}</CardDescription> : null}\n                </CardHeader>\n                {/* Each part brings the space above it, so one that folds takes it away. */}\n                <CardContent className='-mt-(--surface-gap) flex flex-col'>\n                  {children}\n                </CardContent>\n              </div>\n            )}\n          </Swap>\n        </Card>\n        {footer ? (\n          <div className='text-muted-foreground text-center text-sm'>{footer}</div>\n        ) : null}\n      </div>\n    </div>\n  )\n}\n\n/**\n * What ends the card: a mark, a heading that takes focus as it arrives, a\n * line under it, and what the person can do next.\n */\nfunction AuthEnd({\n  icon,\n  title,\n  description,\n  heading: Heading = 'h1',\n  children,\n}: {\n  /** Drawn in a success Icon tile, such as a tick or an envelope. */\n  icon: ReactNode\n  title: ReactNode\n  description?: ReactNode\n  heading?: AuthHeading\n  children?: ReactNode\n}) {\n  return (\n    <div className='flex flex-col items-center gap-3 py-2 text-center'>\n      <IconTile size='lg' tone='success'>\n        {icon}\n      </IconTile>\n      <div className='flex flex-col gap-1'>\n        <Heading\n          data-autofocus=''\n          tabIndex={-1}\n          className='text-base font-medium focus:outline-hidden'\n        >\n          {title}\n        </Heading>\n        {description ? (\n          <p className='text-muted-foreground text-sm wrap-break-word'>{description}</p>\n        ) : null}\n      </div>\n      {children}\n    </div>\n  )\n}\n\n/**\n * Moves focus to a new step's first field once it has arrived, but never on\n * load, where focus belongs to the page. A step's field marks itself\n * `data-autofocus`; content still leaving is inert and passed over. Given\n * `field`, the input of that name takes focus whenever it changes, such as\n * a field the person has to fill.\n */\nfunction useFocusStep<Element extends HTMLElement>(\n  step: string,\n  field: string | null = null,\n) {\n  const ref = useRef<Element>(null)\n  // The step focus last followed: an effect that runs again for the same\n  // step, as React's Strict Mode runs it, moves nothing.\n  const followed = useRef(step)\n  useLayoutEffect(() => {\n    if (followed.current === step) return\n    followed.current = step\n    const target = [\n      ...(ref.current?.querySelectorAll<HTMLElement>('[data-autofocus]') ?? []),\n    ].find((element) => !element.closest('[inert]'))\n    const focusable = target?.matches('input, button, [tabindex]')\n      ? target\n      : target?.querySelector<HTMLElement>('input, button')\n    focusable?.focus({ preventScroll: true })\n  }, [step])\n  useLayoutEffect(() => {\n    if (!field) return\n    ref.current?.querySelector<HTMLInputElement>(`input[name=${field}]`)?.focus()\n  }, [field])\n  return ref\n}\n\n/**\n * The email box. Text with an email keyboard, so the screen's own check\n * speaks rather than the browser's, in another voice; an address reads left\n * to right in any language. `end` sits at the end of the box, such as a\n * Change button once the address is in use.\n */\nfunction AuthEmailInput({\n  end,\n  className,\n  ...props\n}: ComponentProps<typeof InputControl> & { end?: ReactNode }) {\n  return (\n    <InputGroup>\n      <InputGroupInput\n        type='text'\n        autoCapitalize='none'\n        autoCorrect='off'\n        spellCheck={false}\n        inputMode='email'\n        placeholder='name@company.com'\n        dir='ltr'\n        className={cn('text-ellipsis rtl:text-end', className)}\n        {...props}\n      />\n      {end ? <InputGroupAddon align='inline-end'>{end}</InputGroupAddon> : null}\n    </InputGroup>\n  )\n}\n\n/** \"or\", between two ways in. */\nfunction AuthDivider({ children = 'or' }: { children?: ReactNode }) {\n  return (\n    <div className='text-muted-foreground flex items-center gap-3 text-xs'>\n      <Separator className='flex-1' />\n      {children}\n      <Separator className='flex-1' />\n    </div>\n  )\n}\n\n/**\n * Google, GitHub and Apple, with the one used last first. A press opens\n * the provider; one that can't be reached goes back to rest and says so\n * under the buttons.\n */\nfunction AuthSocial({\n  label,\n  onOpen,\n  lastUsed,\n  layout,\n}: {\n  /** Names the group, such as \"Sign in with Google, GitHub or Apple\". */\n  label: string\n  /** Opens the provider. A throw or a rejected promise says it couldn't be reached. */\n  onOpen?: (provider: SocialProvider) => unknown\n  lastUsed?: SocialProvider\n  layout?: SocialSignInLayout\n}) {\n  const [unreachable, setUnreachable] = useState<SocialProvider | null>(null)\n  return (\n    <>\n      <SocialSignIn\n        aria-label={label}\n        layout={layout}\n        lastUsed={lastUsed}\n        onSignIn={async (provider) => {\n          setUnreachable(null)\n          try {\n            await onOpen?.(provider)\n          } catch (error) {\n            setUnreachable(provider)\n            throw error\n          }\n        }}\n      >\n        <SocialSignInButton provider='google' />\n        <SocialSignInButton provider='github' />\n        <SocialSignInButton provider='apple' />\n      </SocialSignIn>\n      <AuthMessage>\n        {unreachable\n          ? `We couldn’t reach ${providers[unreachable].name}. Try again in a moment.`\n          : null}\n      </AuthMessage>\n    </>\n  )\n}\n\n/**\n * Something that went wrong away from any field, such as a server that\n * couldn't be reached. The region is there before the message, so a screen\n * reader reads it as it arrives, and the line opens to fit it.\n */\nfunction AuthMessage({ children }: { children?: ReactNode }) {\n  return (\n    <div role='status'>\n      <Swap fill block>\n        {children ? <p className='text-destructive pt-2 text-sm'>{children}</p> : null}\n      </Swap>\n    </div>\n  )\n}\n\n/**\n * Didn't get it? Another can go once the wait is over; until then the\n * button counts down. One that's sent is announced, in `sent`'s words.\n */\nfunction AuthResend({\n  left,\n  busy = false,\n  onResend,\n  sent,\n  question = 'Didn’t get it?',\n  children,\n  className,\n}: {\n  /** Seconds before another can go. */\n  left: number\n  busy?: boolean\n  /** Sends another, resolving with whether it went. */\n  onResend: () => Promise<boolean>\n  /** What a screen reader hears once another has gone. */\n  sent: string\n  question?: ReactNode\n  /** The button's label once the wait is over. */\n  children: ReactNode\n  className?: string\n}) {\n  const waiting = left > 0\n  return (\n    <div\n      className={cn(\n        'text-muted-foreground flex flex-wrap items-center gap-x-1 text-sm',\n        className,\n      )}\n    >\n      <span>{question}</span>\n      <Button\n        type='button'\n        variant='link'\n        size='sm'\n        className='h-auto min-h-6 px-0 tabular-nums'\n        disabled={waiting}\n        // Still found by Tab while it counts down, so the wait can be read.\n        focusableWhenDisabled\n        loading={busy}\n        onClick={async () => {\n          if (await onResend()) announce(sent)\n        }}\n      >\n        {waiting ? `Resend in ${countdownLabel(left)}` : children}\n      </Button>\n    </div>\n  )\n}\n\n/** Seconds left of a wait that restarts each time `key` changes, ticking once a second, from `initial` at first. */\nfunction useCountdown(key: number, seconds: number, initial = seconds) {\n  const [left, setLeft] = useState(initial)\n  const [last, setLast] = useState(key)\n  if (key !== last) {\n    setLast(key)\n    setLeft(seconds)\n  }\n  useEffect(() => {\n    if (left <= 0) return\n    const timer = setTimeout(() => setLeft((now) => now - 1), 1000)\n    return () => clearTimeout(timer)\n  }, [left])\n  return { left, end: () => setLeft(0) }\n}\n\n/** Seconds as minutes and seconds, as a countdown reads: 0:09. */\nfunction countdownLabel(seconds: number) {\n  const whole = Math.max(0, Math.ceil(seconds))\n  return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, '0')}`\n}\n\n/** Whether `email` reads as an address: something, an @, and a domain with a dot. */\nfunction looksLikeEmail(email: string) {\n  return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email.trim())\n}\n\nexport {\n  AuthDivider,\n  AuthEmailInput,\n  AuthEnd,\n  AuthLogo,\n  AuthMessage,\n  AuthResend,\n  AuthScreen,\n  AuthSocial,\n  useCountdown,\n  useFocusStep,\n}\nexport { countdownLabel, looksLikeEmail }\nexport type { AuthHeading }\n",
      "type": "registry:lib",
      "target": "@lib/auth-screen.tsx"
    }
  ],
  "type": "registry:lib"
}