{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button",
  "title": "Button",
  "description": "A button that animates what changes inside it: a label keeps the letters it shares with the next one, an icon becomes a spinner and then a tick, and the width follows.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/swap.json",
    "https://kinoui.com/r/theme.json",
    "https://kinoui.com/r/spinner.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/button.tsx",
      "content": "'use client'\n\nimport { Spinner, useSpinner } from '@/registry/components/kino/spinner'\nimport { Swap, SwapText, flattenChildren, swapIconClassName } from '@/registry/lib/swap'\nimport { Button as ButtonPrimitive } from '@ui-sdk/react/button'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { type ComponentProps, isValidElement, type ReactNode } from 'react'\n\nimport { cn } from '@/lib/utils'\n\nconst buttonVariants = cva(\n  // The press is quicker on the way down than on the way back, so a short tap\n  // still shows. A button that opens a popup stays still, so the popup doesn't\n  // open from a moving anchor.\n  \"group/button relative inline-flex max-w-full shrink-0 touch-manipulation items-center justify-center gap-(--button-gap) overflow-clip rounded-(--control-radius) border bg-clip-padding text-sm font-medium whitespace-nowrap select-none transition-[color,background-color,border-color,box-shadow,opacity,scale] duration-(--motion-press-duration) ease-[var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-easing)] focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-hidden active:duration-[calc(var(--motion-press-duration)*0.4)] motion-safe:active:not-data-disabled:not-aria-[haspopup]:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_var(--button-press-depth,1))] data-disabled:not-aria-disabled:pointer-events-none data-disabled:not-data-pending:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 forced-colors:aria-invalid:outline-2 forced-colors:aria-invalid:outline-offset-1 forced-colors:aria-invalid:outline-dashed dark:aria-invalid:border-destructive/70 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n  {\n    variants: {\n      // Each variant names its own border colour, so the classes also work on a\n      // link, without `cn()` to drop one of two.\n      variant: {\n        default:\n          'border-transparent bg-primary text-primary-foreground not-data-disabled:hover:bg-primary/80',\n        outline:\n          'border-border bg-background shadow-xs not-data-disabled:hover:bg-muted not-data-disabled:hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:not-data-disabled:hover:bg-input/50',\n        secondary:\n          'border-transparent bg-secondary text-secondary-foreground not-data-disabled:hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground',\n        // A ghost's hover darkens whatever it sits on, so it shows on a tinted surface too, such as a Kanban column.\n        ghost:\n          'border-transparent not-data-disabled:hover:bg-foreground/5 not-data-disabled:hover:text-foreground aria-expanded:bg-foreground/5 aria-expanded:text-foreground dark:not-data-disabled:hover:bg-foreground/8 dark:aria-expanded:bg-foreground/8',\n        // The destructive colour on its own tint reads at 4:1 in light mode;\n        // a fifth of the foreground mixed in takes the text past 4.5:1.\n        destructive:\n          'border-transparent bg-destructive/10 text-[color-mix(in_oklch,var(--destructive),var(--foreground)_20%)] not-data-disabled:hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:not-data-disabled:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40',\n        link: 'border-transparent text-primary underline-offset-4 not-data-disabled:hover:underline',\n      },\n      // The padding stays the same with or without an icon, so an icon that\n      // arrives moves the label by its own width and nothing snaps. A small\n      // target shrinks further when pressed, or the press can't be seen.\n      size: {\n        default:\n          'h-(--button-height) [--button-height:var(--control-height)] px-(--control-padding) [--button-gap:--spacing(1.5)]',\n        // An xs button's sides are four fifths of a control's: 8px at Balanced.\n        xs: \"h-(--button-height) [--button-height:var(--control-height-xs)] rounded-(--control-radius-xs) px-[calc(var(--control-padding)*0.8)] text-xs [--button-gap:--spacing(1)] [&_svg:not([class*='size-'])]:size-3.5\",\n        sm: 'h-(--button-height) [--button-height:var(--control-height-sm)] rounded-(--control-radius-sm) px-(--control-padding) [--button-gap:--spacing(1)]',\n        lg: 'h-(--button-height) [--button-height:var(--control-height-lg)] px-(--control-padding) [--button-gap:--spacing(1.5)]',\n        icon: 'size-(--button-height) [--button-height:var(--control-height)] [--button-press-depth:2.5]',\n        'icon-xs':\n          \"size-(--button-height) [--button-height:var(--control-height-xs)] rounded-(--control-radius-xs) [--button-press-depth:2.5] [&_svg:not([class*='size-'])]:size-3.5\",\n        'icon-sm':\n          'size-(--button-height) [--button-height:var(--control-height-sm)] rounded-(--control-radius-sm) [--button-press-depth:2.5]',\n        'icon-lg':\n          'size-(--button-height) [--button-height:var(--control-height-lg)] [--button-press-depth:2.5]',\n      },\n    },\n    defaultVariants: {\n      variant: 'default',\n      size: 'default',\n    },\n  },\n)\n\n/** Where an icon or the spinner sits beside the label. Empty, it takes no room. */\nfunction ButtonSlot({ side, children }: { side: 'start' | 'end'; children: ReactNode }) {\n  return (\n    <Swap align={side} roll className={swapIconClassName}>\n      {children ? (\n        <span\n          className={cn(\n            'flex',\n            side === 'start' ? 'pe-(--button-gap)' : 'ps-(--button-gap)',\n          )}\n        >\n          {children}\n        </span>\n      ) : null}\n    </Swap>\n  )\n}\n\nfunction isIcon(node: ReactNode, place: 'inline-start' | 'inline-end'): boolean {\n  return (\n    isValidElement(node) && (node.props as Record<string, unknown>)['data-icon'] === place\n  )\n}\n\nfunction ButtonContent({\n  iconOnly,\n  busy,\n  children,\n}: {\n  iconOnly: boolean\n  busy: boolean\n  children: ReactNode\n}) {\n  const spinning = useSpinner(busy)\n  // An icon button has nowhere to make room: its icon gives way to the spinner.\n  if (iconOnly) {\n    return (\n      <Swap roll className={swapIconClassName}>\n        {spinning ? <Spinner /> : children}\n      </Swap>\n    )\n  }\n  const parts = flattenChildren(children)\n  const last = parts.length - 1\n  const start = isIcon(parts[0], 'inline-start') ? parts[0] : null\n  const end = last > 0 && isIcon(parts[last], 'inline-end') ? parts[last] : null\n  const label = parts.slice(start ? 1 : 0, end ? last : undefined)\n  return (\n    <>\n      <ButtonSlot side='start'>{spinning ? <Spinner /> : start}</ButtonSlot>\n      {label.every((part) => typeof part === 'string' || typeof part === 'number') ? (\n        <SwapText text={label.join('')} />\n      ) : (\n        <Swap bleed className='[--swap-gap:var(--button-gap)]'>\n          {label}\n        </Swap>\n      )}\n      <ButtonSlot side='end'>{end}</ButtonSlot>\n    </>\n  )\n}\n\n/**\n * ui-sdk's Button: a promise returned from `onClick` keeps it pending, and\n * `loading` shows the same state when the caller owns it. Either way the\n * spinner shows only once it lasts 200ms, and then for at least 300ms.\n */\nfunction Button({\n  className,\n  variant = 'default',\n  size = 'default',\n  loading = false,\n  disabled,\n  focusableWhenDisabled,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof ButtonPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n} & VariantProps<typeof buttonVariants> & {\n    /** Blocks presses at once and keeps focus, as a pending press does. */\n    loading?: boolean\n  }) {\n  return (\n    <ButtonPrimitive\n      data-variant={variant}\n      // ui-sdk has no prop for a pending state the caller owns, so `loading` writes its attributes.\n      data-pending={loading ? '' : undefined}\n      aria-busy={loading || undefined}\n      disabled={disabled || loading}\n      focusableWhenDisabled={focusableWhenDisabled || loading}\n      // The slots carry the gap, so an empty one takes no room.\n      className={cn(buttonVariants({ variant, size }), 'gap-0', className)}\n      {...props}\n    >\n      {(state) => (\n        <ButtonContent\n          iconOnly={size?.startsWith('icon') ?? false}\n          busy={loading || state.pending}\n        >\n          {children}\n        </ButtonContent>\n      )}\n    </ButtonPrimitive>\n  )\n}\n\nexport { Button, buttonVariants }\n",
      "type": "registry:component",
      "target": "@components/kino/button.tsx"
    }
  ],
  "type": "registry:component"
}