{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "split-button",
  "title": "Split button",
  "description": "A main action joined to a menu of the actions next to it, such as Merge beside Squash and merge. It is a Button group and a Menu, so it looks and moves as they do.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/button-group.json",
    "https://kinoui.com/r/menu.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/split-button.tsx",
      "content": "'use client'\n\nimport { Button } from '@/registry/components/kino/button'\nimport { ButtonGroup } from '@/registry/components/kino/button-group'\nimport { MenuTrigger } from '@/registry/components/kino/menu'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type ComponentProps, createContext, use, useEffect, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype SplitButtonVariant = 'default' | 'secondary' | 'outline' | 'destructive'\ntype SplitButtonSize = 'xs' | 'sm' | 'default' | 'lg'\n\n/** The menu's button is square, the height of the action beside it. */\nconst triggerSize = {\n  xs: 'icon-xs',\n  sm: 'icon-sm',\n  default: 'icon',\n  lg: 'icon-lg',\n} as const\n\nconst SplitButtonContext = createContext<{\n  variant: SplitButtonVariant\n  size: SplitButtonSize\n  disabled: boolean\n  loading: boolean\n  /** The action tells the group it is loading, so the menu's button holds too. */\n  setActionLoading: (loading: boolean) => void\n}>({\n  variant: 'default',\n  size: 'default',\n  disabled: false,\n  loading: false,\n  setActionLoading: () => {},\n})\n\n/**\n * A main action joined to a menu of the actions next to it. The variant and\n * size are set here once, for both halves. Other props go to the Button group.\n */\nfunction SplitButton({\n  variant = 'default',\n  size = 'default',\n  disabled = false,\n  loading = false,\n  ...props\n}: Omit<ComponentProps<typeof ButtonGroup>, 'orientation'> & {\n  variant?: SplitButtonVariant\n  size?: SplitButtonSize\n  /** Disables the action and the menu's button. */\n  disabled?: boolean\n  /**\n   * The action is running: it shows the Button's spinner and blocks presses,\n   * and the menu's button is disabled, neither of them dimmed.\n   */\n  loading?: boolean\n}) {\n  const [actionLoading, setActionLoading] = useState(false)\n  return (\n    <SplitButtonContext\n      value={{\n        variant,\n        size,\n        disabled,\n        loading: loading || actionLoading,\n        setActionLoading,\n      }}\n    >\n      <ButtonGroup {...props} />\n    </SplitButtonContext>\n  )\n}\n\n/**\n * The main action. `loading` here, as a Copy button that waits for its value\n * sets it, holds the menu's button too, as the group's `loading` does.\n */\nfunction SplitButtonAction({\n  disabled,\n  loading = false,\n  ...props\n}: Omit<ComponentProps<typeof Button>, 'variant' | 'size'>) {\n  const context = use(SplitButtonContext)\n  const { setActionLoading } = context\n  useEffect(() => {\n    setActionLoading(loading)\n    return () => setActionLoading(false)\n  }, [loading, setActionLoading])\n  return (\n    <Button\n      data-split-button-action=''\n      variant={context.variant}\n      size={context.size}\n      loading={loading || context.loading}\n      disabled={disabled ?? context.disabled}\n      {...props}\n    />\n  )\n}\n\n/**\n * The button that opens the menu, with a chevron unless you give it another\n * icon. Put it in a `Menu`, beside its `MenuContent`.\n */\nfunction SplitButtonTrigger({\n  className,\n  disabled,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof MenuTrigger>, 'className' | 'render' | 'aria-label'> & {\n  className?: string\n  /** What the menu holds, such as \"Choose how to merge\": the button shows only an icon. */\n  'aria-label': string\n}) {\n  const context = use(SplitButtonContext)\n  // While loading, the menu won't open but its button keeps focus: a pick from\n  // the menu that starts the action hands focus back to it as the menu closes.\n  const held = context.loading && !(disabled ?? context.disabled)\n  return (\n    <MenuTrigger\n      data-split-button-trigger=''\n      disabled={held || (disabled ?? context.disabled)}\n      focusableWhenDisabled={held}\n      render={\n        <Button\n          data-pending={context.loading ? '' : undefined}\n          variant={context.variant}\n          size={triggerSize[context.size]}\n          className={cn('aria-disabled:pointer-events-none', className)}\n        />\n      }\n      {...props}\n    >\n      {children ?? (\n        <IconPlaceholder\n          lucide='ChevronDownIcon'\n          tabler='IconChevronDown'\n          hugeicons='ArrowDown01Icon'\n          phosphor='CaretDownIcon'\n          remixicon='RiArrowDownSLine'\n          aria-hidden\n        />\n      )}\n    </MenuTrigger>\n  )\n}\n\nexport { SplitButton, SplitButtonAction, SplitButtonTrigger }\n",
      "type": "registry:component",
      "target": "@components/kino/split-button.tsx"
    }
  ],
  "type": "registry:component"
}