{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "social-button",
  "title": "Social Button",
  "description": "Sign-in button for an identity provider, single or grouped.",
  "dependencies": [
    "class-variance-authority@^0.7.1",
    "radix-ui@^1.6.7"
  ],
  "registryDependencies": [
    "@pestoui/button",
    "@pestoui/spinner",
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/ui/social-button.tsx",
      "content": "import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { Slot } from \"radix-ui\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Spinner } from \"@/components/ui/spinner\"\n\n/* An identity-provider button. Surface, radius, focus ring, press motion and\n   the disabled treatment all come from Button — restating any of them here\n   would fork the button contract for one call site. What is left, and all this\n   cva governs, is the mark and the label slot.\n *\n * The provider is passed in as an element rather than named by a `provider`\n * enum. An enum would couple this file to a set of marks and force every\n * consumer that copies it to ship the whole set for the one provider they use.\n * The system ships no third-party logos — they are their owners' trademarks —\n * so a real provider's mark comes from its own brand kit. There is deliberately\n * no solid brand-fill variant: a provider-coloured *surface* cannot come from an\n * SVG, so it would need a raw colour in this file, and it would put a second\n * full-weight CTA next to the form's real submit button. A brand-filled mark on\n * a neutral surface says the same thing. */\nconst socialButtonVariants = cva(\n  \"relative aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_[data-slot=social-button-label]]:min-w-0 [&_[data-slot=social-button-label]]:truncate\",\n  {\n    variants: {\n      tone: {\n        /* Trademark palette on a neutral surface — the canonical auth look. */\n        color: \"\",\n        /* Mark collapses to the inherited text colour. `--foreground`, never\n           `--muted-foreground`: a monochrome mark this small needs the full\n           contrast to stay legible. */\n        mono: \"[&_svg]:text-foreground\",\n      },\n      /* Covers plain icons handed in as children. Brand marks are sized by\n         injection instead — see `markSize`. */\n      size: {\n        sm: \"[&_svg:not([class*='size-'])]:size-4\",\n        default: \"[&_svg:not([class*='size-'])]:size-5\",\n        lg: \"[&_svg:not([class*='size-'])]:size-5\",\n        xl: \"[&_svg:not([class*='size-'])]:size-6\",\n      },\n    },\n    defaultVariants: {\n      tone: \"color\",\n      size: \"default\",\n    },\n  }\n)\n\ntype SocialButtonSize = \"sm\" | \"default\" | \"lg\" | \"xl\"\n\n/* A brand mark usually carries its own size class, which means Button's\n   `[&_svg:not([class*='size-'])]` guard never matches one and the mark renders\n   at its intrinsic size inside a smaller box. The class has to land on the\n   element itself, where the mark's own merge puts the passed value last and it\n   resolves. This is the only reliable way past that guard. */\nconst markSize: Record<SocialButtonSize, string> = {\n  sm: \"size-4\",\n  default: \"size-5\",\n  lg: \"size-5\",\n  xl: \"size-6\",\n}\n\nconst spinnerSize: Record<SocialButtonSize, \"xs\" | \"sm\" | \"default\"> = {\n  sm: \"xs\",\n  default: \"sm\",\n  lg: \"sm\",\n  xl: \"default\",\n}\n\n/* Button's square sizes stop one step below its tallest label size, so `xl`\n   clamps rather than restating the squircle radius from the outside. Those\n   radii are tuned to the box edge; a hand-written override would miss. */\nconst iconOnlySize: Record<SocialButtonSize, \"icon-sm\" | \"icon\" | \"icon-lg\"> = {\n  sm: \"icon-sm\",\n  default: \"icon\",\n  lg: \"icon-lg\",\n  xl: \"icon-lg\",\n}\n\n/* One duration and one easing per element per state. Neither token is numeric,\n   so the class merger cannot see `duration-exit` and `duration-spring-swap` as\n   a conflicting pair — layering them leaves both alive and hands the decision\n   to stylesheet order. A two-state swap has a single offset shared by both\n   directions, so the enter/exit asymmetry is carried entirely by the timing:\n   a spring on the way in, a shorter tween on the way out. */\nconst SWAP_BASE = \"transition-[translate,opacity]\"\nconst SWAP_SETTLED =\n  \"translate-y-0 opacity-100 duration-spring-swap ease-spring-swap\"\nconst SWAP_ABOVE = \"-translate-y-1.5 opacity-0 duration-exit ease-out-expo\"\nconst SWAP_BELOW = \"translate-y-1.5 opacity-0 duration-exit ease-out-expo\"\n\n/* Structural only — a provider's own mark, a lucide icon and a bare `<svg>` all\n   satisfy it, and `ui/` needs no runtime import from any mark module. */\nexport type SocialButtonMarkProps = {\n  className?: string\n  monochrome?: boolean\n  \"aria-hidden\"?: boolean | \"true\" | \"false\"\n  focusable?: boolean | \"true\" | \"false\"\n}\n\nexport type SocialButtonMark = React.ReactElement<SocialButtonMarkProps>\n\ntype SocialButtonBaseProps = Omit<\n  React.ComponentProps<typeof Button>,\n  \"size\" | \"variant\" | \"children\" | \"asChild\"\n> &\n  VariantProps<typeof socialButtonVariants> & {\n    /** Provider mark. Sized, hidden from assistive tech and switched to\n     *  monochrome by this component — pass it unstyled. */\n    icon: SocialButtonMark\n    /** Neutral outline is the default; `subtle` drops the hairline. */\n    variant?: \"outline\" | \"subtle\"\n    /** Redirect in flight: disables the control and swaps the label for a\n     *  spinner without letting the box change width. */\n    loading?: boolean\n    /** Announced while `loading`. */\n    loadingLabel?: string\n  }\n\n/* Discriminated so an icon-only button cannot compile without an accessible\n   name, and so `asChild` cannot be combined with icon-only — that pairing has\n   no label child for the slot to attach to. */\nexport type SocialButtonProps =\n  | (SocialButtonBaseProps & {\n      iconOnly?: false\n      children: React.ReactNode\n      /** Render as the passed child, e.g. an `<a>` for an OAuth redirect. */\n      asChild?: boolean\n    })\n  | (SocialButtonBaseProps & {\n      iconOnly: true\n      \"aria-label\": string\n      children?: never\n      asChild?: false\n    })\n\nfunction SocialButton({\n  className,\n  icon,\n  variant = \"outline\",\n  tone,\n  size,\n  iconOnly = false,\n  loading = false,\n  loadingLabel = \"Signing in\",\n  asChild = false,\n  disabled,\n  children,\n  ...props\n}: SocialButtonProps) {\n  const resolvedTone = tone ?? \"color\"\n  const resolvedSize = size ?? \"default\"\n  const isDisabled = disabled === true || loading\n\n  /* The mark carries the swap classes itself rather than sitting inside a\n     wrapper — one fewer element between Button's flex row and the icon, and\n     Button's own gap goes on spacing the mark against the label.\n     Keys are explicit throughout because `asChild` hands this whole child list\n     to the slot, which re-clones it as an array; unkeyed array children warn.\n     `monochrome` is set for `mono` only: a lucide icon forwards every prop to\n     its <svg>, so passing `false` would leak an unknown attribute to the DOM. */\n  const mark = React.cloneElement(icon, {\n    key: \"mark\",\n    className: cn(\n      markSize[resolvedSize],\n      SWAP_BASE,\n      loading ? SWAP_ABOVE : SWAP_SETTLED,\n      icon.props.className\n    ),\n    monochrome: resolvedTone === \"mono\" || undefined,\n    \"aria-hidden\": true,\n    focusable: \"false\",\n  })\n\n  return (\n    <Button\n      data-slot=\"social-button\"\n      data-tone={resolvedTone}\n      data-loading={loading || undefined}\n      asChild={asChild}\n      variant={variant === \"subtle\" ? \"ghost\" : \"outline\"}\n      size={iconOnly ? iconOnlySize[resolvedSize] : resolvedSize}\n      /* `disabled` is a button-only attribute; a slotted `<a>` gets the aria\n         form and the matching root variant instead. */\n      disabled={asChild ? undefined : isDisabled}\n      aria-disabled={isDisabled || undefined}\n      aria-busy={loading || undefined}\n      className={cn(\n        socialButtonVariants({ tone: resolvedTone, size: resolvedSize }),\n        className\n      )}\n      {...props}\n    >\n      {mark}\n      {iconOnly ? null : (\n        /* Marks the slot target when `asChild` is set, and renders as a plain\n           wrapper when it is not — the render form returns the same span\n           either way, so there is no second code path to keep in step. */\n        <Slot.Slottable key=\"label\" child={children}>\n          {(slotted) => (\n            <span\n              key=\"label\"\n              data-slot=\"social-button-label\"\n              className={cn(SWAP_BASE, loading ? SWAP_ABOVE : SWAP_SETTLED)}\n            >\n              {slotted}\n            </span>\n          )}\n        </Slot.Slottable>\n      )}\n      {/* Stacked over the label rather than replacing it, so the box never\n          reflows as the redirect starts. Hidden from assistive tech: the live\n          region below is the one that speaks. */}\n      <span\n        key=\"pending\"\n        data-slot=\"social-button-pending\"\n        aria-hidden=\"true\"\n        className={cn(\n          \"absolute inset-0 flex items-center justify-center\",\n          SWAP_BASE,\n          loading ? SWAP_SETTLED : SWAP_BELOW\n        )}\n      >\n        <Spinner size={spinnerSize[resolvedSize]} label=\"\" />\n      </span>\n      {/* `aria-busy` alone is not announced on a control that has just left the\n          tab order, which is exactly what a keyboard user hits mid-redirect. */}\n      <span\n        key=\"status\"\n        data-slot=\"social-button-status\"\n        role=\"status\"\n        aria-live=\"polite\"\n        className=\"sr-only\"\n      >\n        {loading ? loadingLabel : \"\"}\n      </span>\n    </Button>\n  )\n}\n\n/* A spaced stack of independent auth targets — deliberately not ButtonGroup.\n   That wrapper collapses shared borders into one seam, which reads as a single\n   segmented control; these are separate destinations and each needs its own\n   edge. Vertical and stretched is the auth-form default. */\nconst socialButtonGroupVariants = cva(\"flex gap-3\", {\n  variants: {\n    orientation: {\n      horizontal: \"flex-row flex-wrap items-center\",\n      vertical: \"flex-col\",\n    },\n    stretch: {\n      true: \"\",\n      false: \"\",\n    },\n  },\n  compoundVariants: [\n    {\n      orientation: \"horizontal\",\n      stretch: true,\n      class: \"[&>*]:min-w-0 [&>*]:flex-1 [&>*]:basis-0\",\n    },\n    { orientation: \"vertical\", stretch: true, class: \"items-stretch\" },\n    /* A column stretches its children by default, so opting out is the case\n       that needs a rule. */\n    { orientation: \"vertical\", stretch: false, class: \"items-start\" },\n  ],\n  defaultVariants: {\n    orientation: \"vertical\",\n    stretch: true,\n  },\n})\n\nexport type SocialButtonGroupProps = React.ComponentProps<\"div\"> &\n  VariantProps<typeof socialButtonGroupVariants> & {\n    orientation?: \"horizontal\" | \"vertical\"\n    /** Stretch every child to fill the track. */\n    stretch?: boolean\n  }\n\nfunction SocialButtonGroup({\n  className,\n  orientation = \"vertical\",\n  stretch = true,\n  ...props\n}: SocialButtonGroupProps) {\n  return (\n    <div\n      data-slot=\"social-button-group\"\n      data-orientation={orientation}\n      role=\"group\"\n      className={cn(\n        socialButtonGroupVariants({ orientation, stretch }),\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nexport {\n  SocialButton,\n  SocialButtonGroup,\n  socialButtonVariants,\n  socialButtonGroupVariants,\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}