{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-combo-button",
  "type": "registry:ui",
  "title": "react-tw/combo-button.tsx",
  "description": "Carbon `ComboButton` as a React + Tailwind component, the look and rules of `<ui-combo-button>`: a Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-position",
    "@kanok-ui/tw-button",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-icon-button",
    "@kanok-ui/tw-menu",
    "@kanok-ui/tw-refs",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/combo-button.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/combo-button.tsx",
      "content": "import { useLayoutEffect, useRef, useState, type ReactNode, type ComponentProps } from 'react';\nimport type { Placement } from '../core/position.ts';\nimport { Button } from './button.tsx';\nimport { IconButton } from './icon-button.tsx';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\nimport { Menu as MenuPrimitive } from '@purpurabog/ui/headless';\nimport { MenuPopup, menuChevron, type MenuOpenProps } from './menu.tsx';\nimport { useMergedRefs } from './lib/refs.ts';\n\nexport interface ComboButtonProps extends Omit<ComponentProps<'span'>, 'label' | 'onClick' | 'size' | 'placement' | 'tooltipPlacement' | 'triggerLabel' | 'disabled' | 'lang' | 'className' | 'children' | keyof MenuOpenProps>, MenuOpenProps {\n    /** The primary action's text. */\n    label: string;\n    /** The primary action (not the chevron or a menu item). */\n    onClick?: () => void;\n    size?: 'sm' | 'md' | 'lg';\n    /** Where the menu opens; `bottom` / `top` make it as wide as the whole control. */\n    placement?: Placement;\n    tooltipPlacement?: Placement;\n    /** Name of the chevron button (default: the translation's \"Additional actions\"). */\n    triggerLabel?: string;\n    disabled?: boolean;\n    lang?: string;\n    className?: string;\n    /** `<MenuItem>`s: the secondary actions. */\n    children: ReactNode;\n}\n\n/** The primary button leaves room for the chevron: together at least 160px (literal class names, so Tailwind generates them). */\nconst TRIGGER_WIDTH = { sm: '[--_t:32px]', md: '[--_t:40px]', lg: '[--_t:48px]' } as const;\n\n/**\n * Carbon `ComboButton` as a React + Tailwind component, the look and rules of `<ui-combo-button>`: a\n * primary action button next to a chevron that opens a Menu of secondary actions (↓ / ↑ open it on\n * the first / last item, as a menu button).\n */\nexport function ComboButton({ label, onClick, size = 'lg', placement = 'bottom', tooltipPlacement = 'bottom', triggerLabel, disabled = false, lang, open, defaultOpen, onOpenChange, className, children, ref, ...rest }: Readonly<ComboButtonProps>) {\n    const t = useTranslation(lang).common;\n    const name = triggerLabel || t.additionalActions;\n    const box = useRef<HTMLSpanElement>(null);\n    const boxRef = useMergedRefs(box, ref);\n    // the menu sits beside the whole control, whose ref is set only after the menu's first effects: open on mount waits one render\n    const [mounted, setMounted] = useState(false);\n    // once, after the first commit (the refs are set by then), before paint\n    // eslint-disable-next-line react-hooks/set-state-in-effect\n    useLayoutEffect(() => setMounted(true), []);\n    return (\n        <span {...rest} ref={boxRef} className={cn('inline-flex gap-x-px font-sans', className)}>\n            <MenuPrimitive.Root open={mounted ? open : false} defaultOpen={defaultOpen} onOpenChange={onOpenChange}>\n                <span className={cn('block min-w-[calc(160px-1px-var(--_t))]', TRIGGER_WIDTH[size])}>\n                    <Button kind=\"primary\" size={size} disabled={disabled} title={label} onClick={onClick} className=\"w-full max-w-[239px] min-w-[111px] truncate rounded-e-none\">\n                        {label}\n                    </Button>\n                </span>\n                <MenuPrimitive.Trigger\n                    disabled={disabled}\n                    render={(props, { open: shown }) => (\n                        <IconButton {...props} kind=\"primary\" size={size} label={name} tooltipPlacement={tooltipPlacement} className=\"rounded-s-none\">\n                            {menuChevron(shown)}\n                        </IconButton>\n                    )}\n                />\n                <MenuPopup anchor={box} label={name} size={size} placement={placement} matchWidth={placement === 'bottom' || placement === 'top'}>\n                    {children}\n                </MenuPopup>\n            </MenuPrimitive.Root>\n        </span>\n    );\n}\n"
    }
  ]
}
