{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "split-button",
  "type": "registry:ui",
  "title": "Split Button",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "A primary action fused with a chevron trigger that reveals related actions in a spring-timed dropdown, sharing a single pill silhouette.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/split-button.tsx",
      "content": "'use client';\n\nimport React, {\n  useCallback,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from 'react';\nimport { AnimatePresence, motion, useReducedMotion } from 'framer-motion';\nimport { ChevronDown } from 'lucide-react';\nimport { cn } from '@/lib/utils';\n\n// -----------------------------------------------------------------------------\n// Motion\n// -----------------------------------------------------------------------------\n\nconst springSnappy = {\n  type: 'spring' as const,\n  stiffness: 400,\n  damping: 25,\n  mass: 0.5,\n};\n\n// -----------------------------------------------------------------------------\n// Types\n// -----------------------------------------------------------------------------\n\nexport type SplitButtonSize = 'sm' | 'md' | 'lg';\n\nexport interface SplitButtonOption {\n  value: string;\n  label: string;\n  icon?: React.ReactNode;\n  disabled?: boolean;\n  onSelect?: () => void;\n}\n\nexport interface SplitButtonProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {\n  /** Label for the primary (left) action. */\n  label?: string;\n\n  /** Called when the primary action is pressed. */\n  onClick?: () => void;\n\n  /** Dropdown options revealed by the chevron trigger. */\n  options?: SplitButtonOption[];\n\n  size?: SplitButtonSize;\n\n  /**\n   * `primary` matches the light accent CTA.\n   * `secondary` matches the raised control style.\n   */\n  variant?: 'primary' | 'secondary' | 'danger' | 'info';\n\n  disabled?: boolean;\n  className?: string;\n}\n\n// -----------------------------------------------------------------------------\n// Styles\n// -----------------------------------------------------------------------------\n\nconst SIZE_STYLES: Record<\n  SplitButtonSize,\n  {\n    primary: string;\n    chevron: string;\n    radius: string;\n    menuText: string;\n  }\n> = {\n  sm: {\n    primary: 'gap-1.5 px-3.5 py-1.5 text-xs',\n    chevron: 'px-2 py-1.5',\n    radius: 'rounded-[8px]',\n    menuText: 'text-xs',\n  },\n\n  md: {\n    primary: 'gap-2 px-5 py-2.5 text-sm',\n    chevron: 'px-2.5 py-2.5',\n    radius: 'rounded-[8px]',\n    menuText: 'text-sm',\n  },\n\n  lg: {\n    primary: 'gap-2.5 px-7 py-3.5 text-base',\n    chevron: 'px-3 py-3.5',\n    radius: 'rounded-[10px]',\n    menuText: 'text-sm',\n  },\n};\n\nconst TRANSITION =\n  'transition-[background-color,border-color,box-shadow,transform] duration-200 ease-out ' +\n  'active:translate-y-0 active:scale-[0.98]';\n\nconst VARIANT_STYLES: Record<'primary' | 'secondary' | 'danger' | 'info', string> = {\n  primary:\n    // light: dark pill on a light canvas · dark: light pill on a dark canvas (mirrors your existing button)\n    'bg-[#151515] text-[#F5F5F5] hover:bg-black ' +\n    'dark:bg-[#F5F5F5] dark:text-[#050505] dark:hover:bg-white ' +\n    'shadow-[0_1px_2px_rgba(0,0,0,0.08)] hover:shadow-[0_8px_20px_-6px_rgba(0,0,0,0.25)] ' +\n    'dark:shadow-[0_0_20px_-3px_rgba(255,255,255,0.15)] dark:hover:shadow-[0_0_28px_-4px_rgba(255,255,255,0.28)] ' +\n    TRANSITION,\n\n  secondary:\n    'border border-neutral-200 bg-neutral-100 text-black hover:border-neutral-300 hover:bg-neutral-200 ' +\n    'dark:border-[#262626] dark:bg-[#141414] dark:text-white ' +\n    'dark:hover:border-neutral-600 dark:hover:bg-[#1F1F1F] ' +\n    'shadow-[0_1px_2px_rgba(0,0,0,0.04)] hover:shadow-[0_6px_16px_-8px_rgba(0,0,0,0.15)] ' +\n    'dark:shadow-none dark:hover:shadow-[0_6px_16px_-8px_rgba(0,0,0,0.5)] ' +\n    TRANSITION,\n\n  danger:\n    'bg-[#DC2626] text-white hover:bg-[#E23F3F] ' +\n    'dark:bg-[#DC2626]/90 dark:hover:bg-[#EF4444] ' +\n    'shadow-[0_0_0_1px_rgba(220,38,38,0.15)] hover:shadow-[0_8px_20px_-6px_rgba(220,38,38,0.4)] ' +\n    'dark:shadow-[0_0_18px_-4px_rgba(220,38,38,0.35)] dark:hover:shadow-[0_0_26px_-6px_rgba(220,38,38,0.5)] ' +\n    TRANSITION,\n\n  info:\n    'bg-[#3B82F6] text-white hover:bg-[#529BF8] ' +\n    'dark:bg-[#3B82F6]/90 dark:hover:bg-[#60A5FA] ' +\n    'shadow-[0_0_0_1px_rgba(59,130,246,0.15)] hover:shadow-[0_8px_20px_-6px_rgba(59,130,246,0.4)] ' +\n    'dark:shadow-[0_0_18px_-4px_rgba(59,130,246,0.35)] dark:hover:shadow-[0_0_26px_-6px_rgba(59,130,246,0.5)] ' +\n    TRANSITION,\n};\n\n// -----------------------------------------------------------------------------\n// Component\n// -----------------------------------------------------------------------------\n\n/**\n * SplitButton\n *\n * A primary action fused with a secondary chevron trigger.\n *\n * Features:\n * - Primary + dropdown action split\n * - Keyboard accessible menu navigation\n * - Outside-click dismissal\n * - Escape-to-close\n * - Home / End navigation\n * - Viewport-aware dropdown placement\n * - Reduced-motion support\n * - Disabled options\n * - Framer Motion transitions\n */\nconst DEFAULT_SPLIT_OPTIONS: SplitButtonOption[] = [\n  { value: 'preview', label: 'Deploy Preview' },\n  { value: 'staging', label: 'Promote to Staging' },\n  { value: 'rollback', label: 'Rollback Production' },\n];\n\nexport function SplitButton({\n  label = 'Deploy Release',\n  onClick,\n  options = DEFAULT_SPLIT_OPTIONS,\n  size = 'md',\n  variant = 'primary',\n  disabled = false,\n  className,\n  ...props\n}: SplitButtonProps) {\n  const reduceMotion = useReducedMotion();\n\n  const [open, setOpen] = useState(false);\n  const [placement, setPlacement] = useState<'bottom' | 'top'>('bottom');\n  const [activeIndex, setActiveIndex] = useState(0);\n\n  const rootRef = useRef<HTMLDivElement>(null);\n  const chevronRef = useRef<HTMLButtonElement>(null);\n  const menuRef = useRef<HTMLDivElement>(null);\n\n  const sizeStyles = SIZE_STYLES[size];\n\n  // ---------------------------------------------------------------------------\n  // Derived state\n  // ---------------------------------------------------------------------------\n\n  const enabledIndices = options.reduce<number[]>((indices, option, index) => {\n    if (!option.disabled) {\n      indices.push(index);\n    }\n\n    return indices;\n  }, []);\n\n  const menuTransition = reduceMotion\n    ? { duration: 0 }\n    : springSnappy;\n\n  // ---------------------------------------------------------------------------\n  // Menu helpers\n  // ---------------------------------------------------------------------------\n\n  const closeMenu = useCallback(() => {\n    setOpen(false);\n    chevronRef.current?.focus();\n  }, []);\n\n  const selectOption = useCallback(\n    (option: SplitButtonOption) => {\n      if (option.disabled) {\n        return;\n      }\n\n      option.onSelect?.();\n      closeMenu();\n    },\n    [closeMenu],\n  );\n\n  // ---------------------------------------------------------------------------\n  // Outside click\n  // ---------------------------------------------------------------------------\n\n  useEffect(() => {\n    if (!open) {\n      return;\n    }\n\n    const handlePointerDown = (event: PointerEvent) => {\n      const target = event.target as Node;\n\n      if (!rootRef.current?.contains(target)) {\n        setOpen(false);\n      }\n    };\n\n    document.addEventListener('pointerdown', handlePointerDown);\n\n    return () => {\n      document.removeEventListener('pointerdown', handlePointerDown);\n    };\n  }, [open]);\n\n  // ---------------------------------------------------------------------------\n  // Viewport-aware placement\n  // ---------------------------------------------------------------------------\n\n  useLayoutEffect(() => {\n    if (!open || !chevronRef.current) {\n      return;\n    }\n\n    const triggerRect = chevronRef.current.getBoundingClientRect();\n\n    // Approximate menu height:\n    // option height + menu vertical padding.\n    const estimatedMenuHeight = options.length * 36 + 16;\n\n    const spaceBelow = window.innerHeight - triggerRect.bottom;\n    const spaceAbove = triggerRect.top;\n\n    const shouldFlip =\n      spaceBelow < estimatedMenuHeight &&\n      spaceAbove > estimatedMenuHeight;\n\n    setPlacement(shouldFlip ? 'top' : 'bottom');\n  }, [open, options.length]);\n\n  // ---------------------------------------------------------------------------\n  // Reset active option when opening\n  // ---------------------------------------------------------------------------\n\n  useEffect(() => {\n    if (!open) {\n      return;\n    }\n\n    setActiveIndex(enabledIndices[0] ?? 0);\n  }, [open, enabledIndices]);\n\n  // ---------------------------------------------------------------------------\n  // Focus menu when opened\n  // ---------------------------------------------------------------------------\n\n  useEffect(() => {\n    if (!open) {\n      return;\n    }\n\n    requestAnimationFrame(() => {\n      menuRef.current?.focus();\n    });\n  }, [open]);\n\n  // ---------------------------------------------------------------------------\n  // Keyboard navigation\n  // ---------------------------------------------------------------------------\n\n  const handleMenuKeyDown = useCallback(\n    (event: React.KeyboardEvent<HTMLDivElement>) => {\n      if (!enabledIndices.length) {\n        if (event.key === 'Escape' || event.key === 'Tab') {\n          event.preventDefault();\n\n          if (event.key === 'Escape') {\n            closeMenu();\n          } else {\n            setOpen(false);\n          }\n        }\n\n        return;\n      }\n\n      const currentPosition = enabledIndices.indexOf(activeIndex);\n\n      switch (event.key) {\n        case 'ArrowDown': {\n          event.preventDefault();\n\n          const nextPosition =\n            currentPosition < 0\n              ? 0\n              : (currentPosition + 1) % enabledIndices.length;\n\n          setActiveIndex(enabledIndices[nextPosition]);\n          break;\n        }\n\n        case 'ArrowUp': {\n          event.preventDefault();\n\n          const previousPosition =\n            currentPosition < 0\n              ? enabledIndices.length - 1\n              : (currentPosition - 1 + enabledIndices.length) %\n                enabledIndices.length;\n\n          setActiveIndex(enabledIndices[previousPosition]);\n          break;\n        }\n\n        case 'Home': {\n          event.preventDefault();\n          setActiveIndex(enabledIndices[0]);\n          break;\n        }\n\n        case 'End': {\n          event.preventDefault();\n          setActiveIndex(enabledIndices[enabledIndices.length - 1]);\n          break;\n        }\n\n        case 'Enter':\n        case ' ': {\n          event.preventDefault();\n\n          const activeOption = options[activeIndex];\n\n          if (activeOption) {\n            selectOption(activeOption);\n          }\n\n          break;\n        }\n\n        case 'Escape': {\n          event.preventDefault();\n          closeMenu();\n          break;\n        }\n\n        case 'Tab': {\n          setOpen(false);\n          break;\n        }\n\n        default:\n          break;\n      }\n    },\n    [\n      activeIndex,\n      closeMenu,\n      enabledIndices,\n      options,\n      selectOption,\n    ],\n  );\n\n  // ---------------------------------------------------------------------------\n  // Render\n  // ---------------------------------------------------------------------------\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn('relative inline-flex', className)}\n    >\n      {/* ---------------------------------------------------------------------\n          Button group\n      --------------------------------------------------------------------- */}\n\n      <div\n        className={cn(\n          'inline-flex overflow-hidden',\n          sizeStyles.radius,\n          disabled && 'pointer-events-none opacity-30',\n        )}\n      >\n        {/* -------------------------------------------------------------------\n            Primary action\n        ------------------------------------------------------------------- */}\n\n        <button\n          type=\"button\"\n          onClick={onClick}\n          disabled={disabled}\n          className={cn(\n            'relative inline-flex items-center justify-center',\n            'select-none font-medium',\n            'cursor-pointer',\n            'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:focus-visible:ring-white',\n            'transition-colors duration-200',\n            'disabled:cursor-not-allowed',\n            sizeStyles.primary,\n            VARIANT_STYLES[variant],\n          )}\n          {...props}\n        >\n          {label}\n        </button>\n\n        {/* -------------------------------------------------------------------\n            Divider\n        ------------------------------------------------------------------- */}\n\n        <span\n          aria-hidden=\"true\"\n          className={cn(\n            'my-1.5 w-px self-stretch',\n            variant === 'primary'\n              ? 'bg-white/20 dark:bg-black/15'\n              : 'bg-neutral-300 dark:bg-[#262626]',\n          )}\n        />\n\n        {/* -------------------------------------------------------------------\n            Dropdown trigger\n        ------------------------------------------------------------------- */}\n\n        <button\n          ref={chevronRef}\n          type=\"button\"\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          aria-label={`More ${label} options`}\n          disabled={disabled}\n          onClick={() => setOpen((previous) => !previous)}\n          className={cn(\n            'relative inline-flex items-center justify-center',\n            'select-none',\n            'cursor-pointer',\n            'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:focus-visible:ring-white',\n            'transition-colors duration-200',\n            'disabled:cursor-not-allowed',\n            sizeStyles.chevron,\n            VARIANT_STYLES[variant],\n          )}\n        >\n          <motion.span\n            aria-hidden=\"true\"\n            animate={{\n              rotate: open ? 180 : 0,\n            }}\n            transition={menuTransition}\n            className=\"flex items-center justify-center\"\n          >\n            <ChevronDown\n              className=\"h-4 w-4\"\n              strokeWidth={2}\n            />\n          </motion.span>\n        </button>\n      </div>\n\n      {/* -----------------------------------------------------------------------\n          Dropdown menu\n      ----------------------------------------------------------------------- */}\n\n      <AnimatePresence>\n        {open && (\n          <motion.div\n            ref={menuRef}\n            role=\"menu\"\n            aria-label={`${label} options`}\n            tabIndex={-1}\n            onKeyDown={handleMenuKeyDown}\n            initial={{\n              opacity: 0,\n              scale: 0.96,\n              y: placement === 'bottom' ? -4 : 4,\n            }}\n            animate={{\n              opacity: 1,\n              scale: 1,\n              y: 0,\n            }}\n            exit={{\n              opacity: 0,\n              scale: 0.97,\n              transition: reduceMotion\n                ? { duration: 0 }\n                : { duration: 0.12 },\n            }}\n            transition={menuTransition}\n            className={cn(\n              'absolute right-0 z-30',\n              'min-w-[11rem]',\n              'rounded-xl',\n              'border border-neutral-200 dark:border-[#262626]',\n              'bg-white dark:bg-[#0A0A0A]',\n              'p-1',\n              'shadow-xl',\n              'origin-top-right',\n              placement === 'bottom'\n                ? 'top-[calc(100%+8px)]'\n                : 'bottom-[calc(100%+8px)]',\n            )}\n          >\n            {options.map((option, index) => {\n              const isActive =\n                index === activeIndex && !option.disabled;\n\n              return (\n                <button\n                  key={option.value}\n                  type=\"button\"\n                  role=\"menuitem\"\n                  disabled={option.disabled}\n                  aria-disabled={\n                    option.disabled || undefined\n                  }\n                  onClick={() => selectOption(option)}\n                  onMouseEnter={() => {\n                    if (!option.disabled) {\n                      setActiveIndex(index);\n                    }\n                  }}\n                  className={cn(\n                    'flex w-full items-center gap-2',\n                    'rounded-lg',\n                    'px-3 py-2',\n                    'text-left',\n                    'font-medium',\n                    'select-none',\n                    'transition-colors duration-150',\n                    sizeStyles.menuText,\n\n                    option.disabled\n                      ? [\n                          'cursor-not-allowed',\n                          'text-neutral-400 dark:text-neutral-600',\n                        ]\n                      : [\n                          'cursor-pointer',\n                          'text-neutral-600 dark:text-neutral-400',\n                          'hover:bg-neutral-100 dark:hover:bg-[#141414]',\n                          'hover:text-black dark:hover:text-white',\n                        ],\n\n                    isActive && [\n                      'bg-neutral-100 dark:bg-[#141414]',\n                      'text-black dark:text-white',\n                    ],\n                  )}\n                >\n                  {option.icon && (\n                    <span\n                      aria-hidden=\"true\"\n                      className={cn(\n                        'flex shrink-0 items-center justify-center',\n                        '[&_svg]:h-3.5',\n                        '[&_svg]:w-3.5',\n                      )}\n                    >\n                      {option.icon}\n                    </span>\n                  )}\n\n                  <span className=\"min-w-0 truncate\">\n                    {option.label}\n                  </span>\n                </button>\n              );\n            })}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default SplitButton;",
      "type": "registry:ui",
      "target": "components/ui/split-button.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
