{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menu-button",
  "type": "registry:ui",
  "title": "<ui-menu-button>",
  "description": "Carbon `MenuButton`: a labelled button with a chevron that opens a `<ui-menu>` of the slotted items. Kinds primary / tertiary / ghost (`kind`, Carbon's name; `variant` still works), sizes sm / md / lg (menu rows follow the size). With `placement=\"bottom\"` / `\"top\"` the menu is as wide as the button; `-start` / `-end` align an edge instead. Non-ghost buttons are at least 192px wide. 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": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/button",
    "@kanok-ui/menu",
    "@kanok-ui/shared-align",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-events",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/menu-button/menu-button.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/menu-button/menu-button.ts",
      "content": "import { LitElement, html, css } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport type { ButtonSize, UiButton } from '../button/button.ts';\nimport { openMenuFromKey, type MenuPlacement, type UiMenu, type MenuSelectDetail } from '../menu/menu.ts';\nimport '../button/button.ts';\nimport '../menu/menu.ts';\nimport { isOwnEvent, type OpenDetail } from '../shared/events.ts';\nimport { WithAlign } from '../shared/align.ts';\nimport { UiElement } from '../shared/element.ts';\n\nexport type MenuButtonKind = 'primary' | 'tertiary' | 'ghost';\n/** Same as `MenuButtonKind` (for code written with `variant`). */\nexport type MenuButtonVariant = MenuButtonKind; // NOSONAR S6564: public alias for teams used to `variant` (shadcn, MUI)\n\n/**\n * Carbon `MenuButton`: a labelled button with a chevron that opens a `<ui-menu>` of the slotted\n * items. Kinds primary / tertiary / ghost (`kind`, Carbon's name; `variant` still works), sizes sm / md / lg (menu rows follow the size).\n * With `placement=\"bottom\"` / `\"top\"` the menu is as wide as the button; `-start` / `-end`\n * align an edge instead. Non-ghost buttons are at least 192px wide.\n *\n * @slot - `<ui-menu-item>`, `<ui-menu-divider>`, `<ui-menu-group>`\n * @fires ui-select - bubbles from the activated item: detail { value, label, checked }\n * @fires ui-toggle - detail: { open }\n * @csspart trigger - The `<ui-button>`\n * @csspart menu - The `<ui-menu>`\n * @attr align - Carbon's name for `placement` (same values)\n * @attr variant - Same as `kind`, kept for teams used to `variant` (shadcn, MUI); `kind` is Carbon's name and the one in the docs\n */\n@customElement('ui-menu-button')\nexport class UiMenuButton extends WithAlign(UiElement) {\n    /** `el.focus()` lands on the control inside. */\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static override readonly styles = css`\n        :host {\n            display: inline-block;\n        }\n\n        ui-button:not([kind='ghost']) {\n            min-width: 192px;\n        }\n\n        /* Carbon: the chevron takes the button's text colour (white on primary) */\n        .chevron {\n            fill: currentColor;\n            transition: transform var(--ui-duration-moderate) var(--ui-easing);\n        }\n\n        :host([open]) .chevron {\n            transform: rotate(180deg);\n        }\n\n        @media (forced-colors: active) {\n            .chevron {\n                fill: CanvasText;\n            }\n        }\n\n    `;\n\n    @property() label = '';\n\n    /** Carbon `kind`: primary, tertiary or ghost. */\n    @property({ reflect: true }) kind: MenuButtonKind = 'primary';\n\n    /** Same as `kind` (permanent alias for teams used to `variant`); a `variant` attribute works too. */\n    get variant(): MenuButtonKind {\n        return this.kind;\n    }\n\n    set variant(value: MenuButtonKind) {\n        this.kind = value;\n        if (this.hasAttribute('variant')) this.setAttribute('variant', value); // no stale attribute next to `kind`\n    }\n\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'variant'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        if (name !== 'variant') super.attributeChangedCallback(name, old, value);\n        else if (value !== null) this.kind = value as MenuButtonKind;\n    }\n\n    /** sm 32 / md 40 / lg 48px (Carbon has no xl / 2xl here). */\n    @property({ reflect: true }) size: Exclude<ButtonSize, 'xl' | '2xl'> = 'lg';\n\n    @property() placement: MenuPlacement = 'bottom';\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    @property({ type: Boolean, reflect: true }) open = false;\n\n    @query('ui-button') private readonly button!: UiButton;\n\n    @query('ui-menu') private readonly menu!: UiMenu;\n\n    protected override updated(changed: Map<string, unknown>) {\n        if (changed.has('open') && this.menu.open !== this.open) {\n            this.menu.anchor = this.button;\n            this.menu.open = this.open;\n        }\n    }\n\n    private onTriggerKeydown(event: KeyboardEvent) {\n        openMenuFromKey(event, this.menu, this.button);\n    }\n\n    private toggle() {\n        if (this.open) this.menu.hide();\n        else this.menu.show(this.button);\n    }\n\n    override render() {\n        const fullWidth = this.placement === 'bottom' || this.placement === 'top';\n        return html`\n            <ui-button\n                part=\"trigger\"\n                kind=${this.kind}\n                size=${this.size}\n                haspopup=\"menu\"\n                ?expanded=${this.open}\n                ?disabled=${this.disabled}\n                @click=${this.toggle}\n                @keydown=${this.onTriggerKeydown}\n            >\n                ${this.label}\n                <svg slot=\"suffix\" class=\"chevron\" viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M8 11 3 6l.7-.7L8 9.6l4.3-4.3.7.7z\" /></svg>\n            </ui-button>\n            <ui-menu\n                part=\"menu\"\n                label=${this.label}\n                size=${this.size}\n                placement=${this.placement}\n                ?match-width=${fullWidth}\n                @ui-toggle=${(e: CustomEvent<{ open: boolean }>) => { if (isOwnEvent(e)) this.open = e.detail.open; }}\n            >\n                <slot></slot>\n            </ui-menu>\n        `;\n    }\n}\n\nexport interface UiMenuButtonEventMap extends HTMLElementEventMap {\n    'ui-select': CustomEvent<MenuSelectDetail>;\n    'ui-toggle': CustomEvent<OpenDetail>;\n}\n\n/** Typed listeners for UiMenuButton's events (declaration merging with the class). */\nexport interface UiMenuButton {\n    addEventListener<K extends keyof UiMenuButtonEventMap>(type: K, listener: (this: UiMenuButton, event: UiMenuButtonEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiMenuButtonEventMap>(type: K, listener: (this: UiMenuButton, event: UiMenuButtonEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;\n    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-menu-button': UiMenuButton;\n    }\n}\n"
    }
  ]
}
