{"version":3,"file":"chunk-Button2.mjs","names":["Menu.Root","Menu.Trigger","Menu.Content","Menu.Separator","Menu.CheckboxItem","_Fragment","Menu.ItemGroup","Menu.ItemGroupLabel","Menu.RadioItemGroup","Menu.RadioItem","Menu.ItemIndicator","Menu.ItemText"],"sources":["../../src/components/MenuButton/MenuButton.tsx","../../src/namespaces/Button.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { forwardRef } from 'react';\n\nimport { type Size } from '../../sizes.ts';\nimport { Button, type ButtonProps } from '../Button/Button.tsx';\nimport * as Menu from '../Menu/Menu.tsx';\n\n/**\n * One entry in a {@link MenuButton}'s menu: a caller describes the menu it wants instead of assembling the Menu parts.\n */\nexport type MenuButtonItem =\n  /** Heading over the entries that follow, up to the next heading or separator; not selectable. */\n  | { type: 'group'; label: string }\n  | { type: 'separator' }\n  /** Single-select entry; consecutive options form one radio group, checked while `selected`. */\n  | { type: 'option'; label: string; selected: boolean; onSelect: () => void; testId?: string }\n  | { type: 'checkbox'; label: string; checked: boolean; onCheckedChange: (checked: boolean) => void; testId?: string };\n\ntype OptionItem = Extract<MenuButtonItem, { type: 'option' }>;\ntype CheckboxItem = Extract<MenuButtonItem, { type: 'checkbox' }>;\n\n/** A run of the menu between separators: its optional heading, then runs of options and single checkboxes. */\ntype Section = {\n  label?: string;\n  entries: (\n    | { type: 'options'; options: OptionItem[]; start: number }\n    | { type: 'checkbox'; item: CheckboxItem; index: number }\n  )[];\n};\n\n/** Splits the flat item list into sections, so headings and option runs become Ark groups (and zag owns their ARIA). */\nconst toSections = (items: MenuButtonItem[]): Section[] => {\n  const sections: Section[] = [];\n  let section: Section | undefined;\n  const current = () => {\n    section ??= { entries: [] };\n    return section;\n  };\n  const close = () => {\n    if (section) {\n      sections.push(section);\n      section = undefined;\n    }\n  };\n  items.forEach((item, index) => {\n    switch (item.type) {\n      case 'separator':\n        close();\n        sections.push({ entries: [] });\n        break;\n      case 'group':\n        close();\n        section = { label: item.label, entries: [] };\n        break;\n      case 'option': {\n        const entries = current().entries;\n        const last = entries.at(-1);\n        if (last?.type === 'options') {\n          last.options.push(item);\n        } else {\n          entries.push({ type: 'options', options: [item], start: index });\n        }\n        break;\n      }\n      case 'checkbox':\n        current().entries.push({ type: 'checkbox', item, index });\n        break;\n    }\n  });\n  close();\n  return sections;\n};\n\nexport type MenuButtonProps = Omit<ButtonProps, 'onSelect'> & {\n  items: MenuButtonItem[];\n  /** The menu's size; `md` by default. */\n  menuSize?: Size;\n};\n\n/**\n * A Button that opens a menu of options and checkboxes: the composite behind every \"options\" caret in the app. The\n * button is the trigger and nothing else; a caller that wants a primary action pairs it with a Button of its own.\n */\nexport const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(\n  ({ items, menuSize, ...props }, forwardedRef) => (\n    <Menu.Root>\n      <Menu.Trigger asChild>\n        <Button {...props} ref={forwardedRef} />\n      </Menu.Trigger>\n      <Menu.Content size={menuSize}>\n        {toSections(items).map((section, index) =>\n          section.entries.length === 0 && section.label === undefined ? (\n            index > 0 && <Menu.Separator key={index} />\n          ) : (\n            <MenuButtonSection key={index} section={section} />\n          ),\n        )}\n      </Menu.Content>\n    </Menu.Root>\n  ),\n);\n\nMenuButton.displayName = 'MenuButton';\n\nconst MenuButtonSection = ({ section }: { section: Section }) => {\n  const [only] = section.entries;\n  // A heading over one run of options names that radio group itself, rather than a group around it.\n  if (section.entries.length === 1 && only.type === 'options') {\n    return <OptionGroup label={section.label} options={only.options} start={only.start} />;\n  }\n\n  const entries = section.entries.map((entry, index) =>\n    entry.type === 'options' ? (\n      <OptionGroup key={index} options={entry.options} start={entry.start} />\n    ) : (\n      <Menu.CheckboxItem\n        key={index}\n        item={{ value: `checkbox-${entry.index}`, label: entry.item.label }}\n        checked={entry.item.checked}\n        onCheckedChange={entry.item.onCheckedChange}\n        data-testid={entry.item.testId}\n      />\n    ),\n  );\n  return section.label === undefined ? (\n    <>{entries}</>\n  ) : (\n    <Menu.ItemGroup>\n      <Menu.ItemGroupLabel>{section.label}</Menu.ItemGroupLabel>\n      {entries}\n    </Menu.ItemGroup>\n  );\n};\n\n/** Consecutive options as one radio group, whose value is the selected option's position in the item list. */\nconst OptionGroup = ({ label, options, start }: { label?: string; options: OptionItem[]; start: number }) => {\n  const value = (index: number) => `option-${start + index}`;\n  const selected = options.findIndex((option) => option.selected);\n  return (\n    <Menu.RadioItemGroup\n      value={selected === -1 ? '' : value(selected)}\n      onValueChange={({ value: next }) => options.find((_, index) => value(index) === next)?.onSelect()}\n    >\n      {label !== undefined && <Menu.ItemGroupLabel>{label}</Menu.ItemGroupLabel>}\n      {options.map((option, index) => (\n        <Menu.RadioItem key={index} item={{ value: value(index), label: option.label }} data-testid={option.testId}>\n          <Menu.ItemIndicator />\n          <Menu.ItemText />\n        </Menu.RadioItem>\n      ))}\n    </Menu.RadioItemGroup>\n  );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nexport {\n  type ButtonContentProps as ContentProps,\n  type ButtonHue as Hue,\n  Button as Root,\n  type ButtonProps as RootProps,\n  type ButtonValence as Valence,\n  type ButtonVariant as Variant,\n  type ButtonVariantProps as VariantProps,\n} from '../components/Button/Button.tsx';\nexport { Group, type GroupProps } from '../components/Group/Group.tsx';\nexport {\n  MenuButton as Menu,\n  type MenuButtonItem as MenuItem,\n  type MenuButtonProps as MenuProps,\n} from '../components/MenuButton/MenuButton.tsx';\nexport { Toggle, type ToggleProps } from '../components/Toggle/Toggle.tsx';\n"],"mappings":";;;;;;;;;AAkCA,IAAM,cAAc,UAAuC;CACzD,MAAM,WAAsB,CAAC;CAC7B,IAAI;CACJ,MAAM,gBAAgB;EACpB,YAAY,EAAE,SAAS,CAAC,EAAE;EAC1B,OAAO;CACT;CACA,MAAM,cAAc;EAClB,IAAI,SAAS;GACX,SAAS,KAAK,OAAO;GACrB,UAAU,KAAA;EACZ;CACF;CACA,MAAM,SAAS,MAAM,UAAU;EAC7B,QAAQ,KAAK,MAAb;GACE,KAAK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