{
  "name": "button",
  "type": "ui",
  "description": "Primary, secondary, outline, and ghost variants",
  "tier": "free",
  "dependencies": [
    "@radix-ui/react-slot",
    "class-variance-authority",
    "lucide-react"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "control-size",
    "utils"
  ],
  "files": [
    {
      "path": "button/Button.tsx",
      "content": "import * as React from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { Loader2 } from 'lucide-react'\nimport { cn } from '@/lib/utils'\nimport { buttonVariants, plainButtonClasses, type ButtonVariants } from './Button.variants'\n\ntype IconButtonSize = 'icon' | 'icon-sm' | 'icon-lg'\n\ninterface ButtonBaseProps\n  extends React.ButtonHTMLAttributes<HTMLButtonElement>, Omit<ButtonVariants, 'size'> {\n  /**\n   * Render as a child component (polymorphic)\n   * Useful for wrapping links: <Button asChild><Link href=\"/\">Home</Link></Button>\n   */\n  asChild?: boolean\n  /**\n   * Show loading spinner and disable interaction\n   */\n  loading?: boolean\n  /**\n   * Accessible label for loading state\n   */\n  loadingText?: string\n  /**\n   * Icon to display before the label\n   */\n  leftIcon?: React.ReactNode\n  /**\n   * Icon to display after the label\n   */\n  rightIcon?: React.ReactNode\n}\n\n/**\n * Icon-only sizes have no visible text, so they must carry an accessible name\n * (`aria-label` or `aria-labelledby`). Enforced at compile time.\n */\nexport type ButtonProps = ButtonBaseProps &\n  (\n    | { size?: Exclude<NonNullable<ButtonVariants['size']>, IconButtonSize> | null }\n    | ({ size: IconButtonSize } & ({ 'aria-label': string } | { 'aria-labelledby': string }))\n  )\n\n/**\n * Button component with multiple variants and sizes.\n *\n * @example\n * // Primary button\n * <Button>Click me</Button>\n *\n * @example\n * // Loading state\n * <Button loading loadingText=\"Saving...\">Save</Button>\n *\n * @example\n * // As a link\n * <Button asChild variant=\"link\">\n * <Link href=\"/about\">About</Link>\n * </Button>\n *\n * @example\n * // With icons\n * <Button leftIcon={<PlusIcon />}>Add item</Button>\n */\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n  (\n    {\n      className,\n      variant,\n      size,\n      fullWidth,\n      asChild = false,\n      loading = false,\n      loadingText,\n      leftIcon,\n      rightIcon,\n      disabled,\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const Comp = asChild ? Slot : 'button'\n    const isDisabled = disabled || loading\n    const classes =\n      variant === 'plain'\n        ? cn(plainButtonClasses, fullWidth && 'w-full', className)\n        : cn(buttonVariants({ variant, size, fullWidth }), className)\n\n    // When using asChild with icons, we need to wrap the child's content\n    // to avoid passing className to a Fragment\n    const renderContent = () => {\n      if (loading) {\n        return (\n          <>\n            <Loader2 className=\"animate-spin\" aria-hidden=\"true\" />\n            <span>{loadingText ?? children}</span>\n          </>\n        )\n      }\n\n      // When asChild is true and we have icons, clone the child element\n      // and inject the icons into its children\n      if (asChild && (leftIcon || rightIcon) && React.isValidElement(children)) {\n        const child = children as React.ReactElement<{ children?: React.ReactNode }>\n        return React.cloneElement(child, {\n          ...child.props,\n          children: (\n            <>\n              {leftIcon && (\n                <span className=\"inline-flex items-center\" aria-hidden=\"true\">\n                  {leftIcon}\n                </span>\n              )}\n              {child.props.children}\n              {rightIcon && (\n                <span className=\"inline-flex items-center\" aria-hidden=\"true\">\n                  {rightIcon}\n                </span>\n              )}\n            </>\n          ),\n        })\n      }\n\n      // asChild without icons: Slot must receive the child element itself.\n      // Wrapping it in a Fragment would put className on the Fragment.\n      if (asChild) return children\n\n      // Standard rendering without asChild\n      return (\n        <>\n          {leftIcon && (\n            <span className=\"inline-flex items-center\" aria-hidden=\"true\">\n              {leftIcon}\n            </span>\n          )}\n          {children}\n          {rightIcon && (\n            <span className=\"inline-flex items-center\" aria-hidden=\"true\">\n              {rightIcon}\n            </span>\n          )}\n        </>\n      )\n    }\n\n    // When asChild with icons, we've already handled the content in renderContent\n    // so we need to render differently\n    if (asChild && (leftIcon || rightIcon) && React.isValidElement(children)) {\n      const content = renderContent()\n      return (\n        <Slot\n          ref={ref}\n          className={classes}\n          aria-disabled={isDisabled}\n          aria-busy={loading}\n          {...props}\n        >\n          {content}\n        </Slot>\n      )\n    }\n\n    return (\n      <Comp\n        ref={ref}\n        className={classes}\n        disabled={isDisabled}\n        aria-disabled={isDisabled}\n        aria-busy={loading}\n        {...props}\n      >\n        {renderContent()}\n      </Comp>\n    )\n  }\n)\n\nButton.displayName = 'Button'\n\nexport { Button, buttonVariants }\n"
    },
    {
      "path": "button/Button.variants.ts",
      "content": "import { cva, type VariantProps } from 'class-variance-authority'\nimport { controlRadius, controlSize } from '@/lib/control-size'\n\nexport const buttonVariants = cva(\n  // Base styles (always applied)\n  [\n    'inline-flex items-center justify-center gap-2',\n    'whitespace-nowrap',\n    'font-semibold',\n    'cursor-pointer',\n    'transition-all duration-200',\n    // Focus ring (WCAG 2.4.7)\n    'focus-visible:outline-none focus-visible:ring-2',\n    'focus-visible:ring-indigo-500 focus-visible:ring-offset-2',\n    'focus-visible:ring-offset-background-default',\n    // Disabled state\n    'disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed',\n    // Icon sizing\n    '[&_svg]:pointer-events-none [&_svg]:shrink-0',\n  ],\n  {\n    variants: {\n      variant: {\n        primary: [\n          'bg-primary-default text-primary-foreground',\n          'hover:bg-primary-hover',\n          'active:bg-primary-active',\n        ],\n        secondary: [\n          'bg-primary-muted text-foreground-secondary',\n          'hover:bg-primary-emphasis',\n          'active:bg-primary-emphasis',\n        ],\n        inverse: [\n          'bg-white text-primary-default',\n          'hover:bg-primary-muted',\n          'active:bg-primary-emphasis',\n          'dark:bg-white dark:text-indigo-700',\n          'dark:hover:bg-indigo-50 dark:active:bg-indigo-100',\n        ],\n        ghost: [\n          'bg-transparent text-foreground-secondary',\n          'hover:bg-background-muted',\n          'active:bg-background-emphasis',\n          'dark:hover:bg-slate-700',\n          'dark:active:bg-slate-600',\n        ],\n        destructive: [\n          'bg-danger-default text-danger-foreground',\n          'hover:bg-danger-hover',\n          'active:bg-danger-active',\n        ],\n        'destructive-secondary': [\n          'bg-danger-muted text-danger-hover',\n          'hover:bg-danger-emphasis',\n          'active:bg-danger-emphasis',\n        ],\n        link: [\n          'bg-transparent text-primary-default underline-offset-4',\n          'hover:underline hover:text-primary-hover',\n          'active:text-indigo-800',\n          'dark:active:text-indigo-200',\n        ],\n        // Composite click targets (cards, rows, list options, panel headers).\n        // Button.tsx skips the base and size classes for this variant, so the\n        // className passed in is the whole look; see plainButtonClasses.\n        plain: [],\n      },\n      size: {\n        sm: [controlSize.sm, 'px-3', '[&_svg]:size-4'],\n        md: [controlSize.md, 'px-4', '[&_svg]:size-4'],\n        lg: [controlSize.lg, 'px-6', '[&_svg]:size-5'],\n        icon: ['size-10', controlRadius, '[&_svg]:size-4'],\n        'icon-sm': ['size-8', controlRadius, '[&_svg]:size-4'],\n        'icon-lg': ['size-12', controlRadius, '[&_svg]:size-5'],\n      },\n      fullWidth: {\n        true: 'w-full',\n      },\n    },\n    compoundVariants: [],\n    defaultVariants: {\n      variant: 'primary',\n      size: 'md',\n    },\n  }\n)\n\n/**\n * Classes for variant=\"plain\": no fill, no fixed height, no centering or\n * nowrap, so a card or row keeps its own layout. Keeps the pointer cursor,\n * the visible focus ring and the disabled state of the other variants.\n */\nexport const plainButtonClasses = [\n  'cursor-pointer',\n  'focus-visible:outline-none focus-visible:ring-2',\n  'focus-visible:ring-indigo-500 focus-visible:ring-offset-2',\n  'focus-visible:ring-offset-background-default',\n  'disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed',\n].join(' ')\n\nexport type ButtonVariants = VariantProps<typeof buttonVariants>\n"
    },
    {
      "path": "button/index.ts",
      "content": "export { Button, buttonVariants } from './Button'\nexport type { ButtonProps } from './Button'\nexport type { ButtonVariants } from './Button.variants'\n"
    }
  ]
}
