{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sign-in-methods",
  "type": "registry:ui",
  "title": "Sign In Methods",
  "description": "The \"ways you can sign in\" list on an account page: one row per method (Google, Apple, email…), each with its mark, what it is linked to, and a Connect or Disconnect button. Disconnecting asks once more in place (\"Disconnect\" → \"Yes, disconnect\" /…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "form",
    "pattern"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/button.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/social-sign-in.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/sign-in-methods.tsx",
      "target": "components/ui/patterns/sign-in-methods.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/sign-in-methods v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/sign-in-methods\n// What changed since: https://ds.interlace.tools/c/sign-in-methods#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — SignInMethods\n *\n * The \"ways you can sign in\" list on an account page: one row per method\n * (Google, Apple, email…), each with its mark, what it is linked to, and a\n * Connect or Disconnect button. Disconnecting asks once more in place\n * (\"Disconnect\" → \"Yes, disconnect\" / \"Cancel\"), and the last connected\n * method cannot be disconnected, with the reason said next to it, so nobody\n * locks themselves out.\n *\n * The pattern draws and reports. The consumer links and unlinks identities\n * in its auth library inside `onConnect` / `onDisconnect`; a returned promise\n * keeps that row's button busy until it settles.\n *\n * ## Anatomy\n *\n *   SignInMethods                    (ul — data-slot=\"sign-in-methods\")\n *     └─ li × methods                (data-slot=\"sign-in-method\", data-method, data-connected)\n *         ├─ span                    (the mark, in a bordered square)\n *         ├─ div                     (name + detail, such as the linked address or \"Not connected\")\n *         └─ div                     (Connect | Disconnect | Yes, disconnect + Cancel)\n *     └─ p                           (data-slot=\"sign-in-methods-hint\" — why the last one is locked)\n *\n * Built-in ids (`google`, `apple`, `x`…) take their name and mark from\n * SocialSignIn; `email` gets a mail icon. Anything else passes `name` and\n * `icon`.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Rows wrap: on a narrow screen the buttons drop under the name.\n *\n * | Rule | Concept                 | Where in this file                                      |\n * | ---- | ----------------------- | ------------------------------------------------------- |\n * | R4   | Extends native el       | `React.ComponentProps<'ul'>`                            |\n * | R6   | data-slot per part      | sign-in-methods / -method / -hint                       |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                       |\n * | R10  | Composition seam        | custom `name` / `icon` / `detail`; every label a prop   |\n * | R14  | Declares min viewport   | `data-min-viewport` + exported const                    |\n * | R18  | Tailwind only           | no inline style                                         |\n * | R19  | Tokens only             | `bg-card`, `border-border`, `text-muted-foreground`     |\n * | R25  | Client component        | confirm and busy state                                  |\n * | R26  | A11y                    | locked button described by the hint; confirm moves focus |\n */\n\nimport { Mail } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\nimport { Button } from '@/components/ui/button';\nimport { providerMark } from '@/components/ui/patterns/social-sign-in';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nexport type SignInMethod = {\n  /** `google`, `apple`, `email`… or your own id. Passed to the callbacks. */\n  id: string;\n  /** Defaults to the built-in name for known ids. */\n  name?: string;\n  /** Defaults to the built-in mark for known ids. */\n  icon?: React.ReactNode;\n  /** What it is linked to, such as the address. Shown under the name when connected. */\n  detail?: React.ReactNode;\n  connected: boolean;\n};\n\ntype SignInMethodsProps = React.ComponentProps<'ul'> & {\n  methods: readonly SignInMethod[];\n  onConnect?: (id: string) => void | Promise<unknown>;\n  onDisconnect?: (id: string) => void | Promise<unknown>;\n  /** @default 'Connect' */\n  connectLabel?: string;\n  /** @default 'Disconnect' */\n  disconnectLabel?: string;\n  /** @default 'Yes, disconnect' */\n  confirmLabel?: string;\n  /** @default 'Cancel' */\n  cancelLabel?: string;\n  /** @default 'Not connected' */\n  notConnectedLabel?: React.ReactNode;\n  /** Said when only one method is left. @default 'You need at least one way to sign in, so this one stays.' */\n  lastMethodHint?: React.ReactNode;\n};\n\nfunction SignInMethods({\n  className,\n  methods,\n  onConnect,\n  onDisconnect,\n  connectLabel = 'Connect',\n  disconnectLabel = 'Disconnect',\n  confirmLabel = 'Yes, disconnect',\n  cancelLabel = 'Cancel',\n  notConnectedLabel = 'Not connected',\n  lastMethodHint = 'You need at least one way to sign in, so this one stays.',\n  ...props\n}: SignInMethodsProps) {\n  const hintId = React.useId();\n  const [busy, setBusy] = React.useState<string | null>(null);\n  const [confirming, setConfirming] = React.useState<string | null>(null);\n  const confirmRef = React.useRef<HTMLButtonElement>(null);\n\n  const connectedCount = methods.filter((m) => m.connected).length;\n  const locked = connectedCount <= 1;\n\n  React.useEffect(() => {\n    if (confirming) confirmRef.current?.focus();\n  }, [confirming]);\n\n  const run = (id: string, work: void | Promise<unknown>) => {\n    setConfirming(null);\n    if (!(work instanceof Promise)) return;\n    setBusy(id);\n    // A rejection is the consumer's to report; it must not surface as an unhandled one here.\n    work.catch(() => {}).finally(() => setBusy((b) => (b === id ? null : b)));\n  };\n\n  return (\n    <>\n      <ul\n        data-slot=\"sign-in-methods\"\n        data-min-viewport={String(MIN_VIEWPORT)}\n        className={cn(\n          'bg-card text-card-foreground border-border divide-border divide-y rounded-xl border',\n          className,\n        )}\n        {...props}\n      >\n        {methods.map((m) => {\n          const known = m.id === 'email' ? { name: 'Email', icon: <Mail className=\"size-5\" aria-hidden=\"true\" /> } : providerMark(m.id);\n          const name = m.name ?? known?.name ?? m.id;\n          const icon = m.icon ?? known?.icon ?? null;\n          const isBusy = busy === m.id;\n          const isConfirming = confirming === m.id;\n          const isLocked = m.connected && locked;\n          return (\n            <li\n              key={m.id}\n              data-slot=\"sign-in-method\"\n              data-method={m.id}\n              data-connected={m.connected ? '' : undefined}\n              className=\"flex flex-wrap items-center gap-x-3 gap-y-2 p-4\"\n            >\n              <span className=\"border-border bg-background flex size-10 shrink-0 items-center justify-center rounded-lg border [&_svg]:size-5\">\n                {icon}\n              </span>\n              <div className=\"min-w-0 flex-1\">\n                <p className=\"text-foreground text-sm font-medium\">{name}</p>\n                <p className=\"text-muted-foreground truncate text-sm\">\n                  {m.connected ? (m.detail ?? null) : notConnectedLabel}\n                </p>\n              </div>\n              <div className=\"ms-auto flex items-center gap-2\">\n                {!m.connected ? (\n                  <Button\n                    type=\"button\"\n                    size=\"sm\"\n                    variant=\"outline\"\n                    loading={isBusy}\n                    disabled={busy !== null && !isBusy}\n                    aria-label={`${connectLabel} ${name}`}\n                    onClick={() => run(m.id, onConnect?.(m.id))}\n                  >\n                    {connectLabel}\n                  </Button>\n                ) : isConfirming ? (\n                  <>\n                    <Button type=\"button\" size=\"sm\" variant=\"ghost\" onClick={() => setConfirming(null)}>\n                      {cancelLabel}\n                    </Button>\n                    <Button\n                      ref={confirmRef}\n                      type=\"button\"\n                      size=\"sm\"\n                      variant=\"destructive\"\n                      onClick={() => run(m.id, onDisconnect?.(m.id))}\n                    >\n                      {confirmLabel}\n                    </Button>\n                  </>\n                ) : (\n                  <Button\n                    type=\"button\"\n                    size=\"sm\"\n                    variant=\"ghost\"\n                    loading={isBusy}\n                    disabled={isLocked || (busy !== null && !isBusy)}\n                    aria-label={`${disconnectLabel} ${name}`}\n                    aria-describedby={isLocked ? hintId : undefined}\n                    onClick={() => setConfirming(m.id)}\n                  >\n                    {disconnectLabel}\n                  </Button>\n                )}\n              </div>\n            </li>\n          );\n        })}\n      </ul>\n      {locked && connectedCount === 1 ? (\n        <p id={hintId} data-slot=\"sign-in-methods-hint\" className=\"text-muted-foreground mt-2 text-sm\">\n          {lastMethodHint}\n        </p>\n      ) : null}\n    </>\n  );\n}\n\nexport { SignInMethods };\nexport type { SignInMethodsProps };\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/sign-in-methods\n\nInstalled to `components/ui/patterns/sign-in-methods.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/sign-in-methods';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/sign-in-methods\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
