{"version":3,"file":"chunk-Select.mjs","names":["SelectPrimitive","Icon.Icon","_Fragment"],"sources":["../../src/components/Select/Select.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { createListCollection } from '@ark-ui/react/collection';\nimport { Portal } from '@ark-ui/react/portal';\nimport { Select as SelectPrimitive, useSelectContext } from '@ark-ui/react/select';\nimport React, { type ReactNode, type RefObject, createContext, forwardRef, useContext, useMemo } from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\nimport { composable, composableProps } from '../../util/slots.ts';\nimport * as Icon from '../Icon/Icon.tsx';\nimport { PopupScroll, popupPositioning, usePopupSize } from '../ScrollArea/PopupScroll.tsx';\nimport { Separator, type SeparatorProps } from '../Separator/Separator.tsx';\nimport { useToolbarItem } from '../Toolbar/toolbar-context.ts';\n\n/** Gap between trigger and popup, in px (positioning takes a number, not a CSS variable). */\nconst POPUP_GUTTER = 2;\n\ntype SelectOption = {\n  value: string;\n  label: string;\n  disabled?: boolean;\n  /** Leading icon, shown in the item and, once selected, in the trigger. */\n  icon?: string;\n  /** Colours the icon with a Tag hue (the current SelectField's `iconHue`). */\n  iconHue?: Icon.IconHue;\n};\n\n//\n// Root\n//\n\n/** Ark's positioning less `sameWidth`; an interface, so declarations name it rather than expanding floating-ui's types. */\ninterface SelectPositioning extends Omit<\n  NonNullable<SelectPrimitive.RootProps<SelectOption>['positioning']>,\n  'sameWidth'\n> {}\n\ntype SelectRootProps = ThemedClassName<Omit<SelectPrimitive.RootProps<SelectOption>, 'collection' | 'positioning'>> & {\n  items: SelectOption[];\n  /** Ark's positioning, less `sameWidth`: the popup is always at least the trigger's width and grows to its options. */\n  positioning?: SelectPositioning;\n};\n\n/**\n * Ark select over a flat option list (grouped in the popup with `ItemGroup`); the root takes no box so its trigger is\n * laid out as the parent's child. `multiple` keeps the popup open while choosing. The popup is at least as wide as\n * the trigger and grows to fit its widest option, up to the viewport's width.\n */\nconst SelectRoot = forwardRef<HTMLDivElement, SelectRootProps>(\n  (\n    {\n      classNames,\n      items,\n      positioning,\n      lazyMount = true,\n      unmountOnExit = true,\n      multiple,\n      closeOnSelect = !multiple,\n      children,\n      ...props\n    },\n    forwardedRef,\n  ) => {\n    const collection = useMemo(() => createListCollection<SelectOption>({ items }), [items]);\n    return (\n      <SelectPrimitive.Root\n        {...props}\n        multiple={multiple}\n        closeOnSelect={closeOnSelect}\n        // Mounting the popup on open keeps it out of a modal Dialog's one-time `aria-hidden` sweep of its siblings.\n        lazyMount={lazyMount}\n        unmountOnExit={unmountOnExit}\n        // Ark's 8px default reads as detached from the trigger.\n        positioning={popupPositioning(POPUP_GUTTER, positioning)}\n        collection={collection}\n        className={mx('dx-select', classNames)}\n        ref={forwardedRef}\n      >\n        {children}\n        <SelectPrimitive.HiddenSelect />\n      </SelectPrimitive.Root>\n    );\n  },\n);\n\nSelectRoot.displayName = 'Select.Root';\n\n//\n// Label\n//\n\ntype SelectLabelProps = ThemedClassName<SelectPrimitive.LabelProps>;\n\nconst SelectLabel = forwardRef<HTMLLabelElement, SelectLabelProps>(({ classNames, ...props }, forwardedRef) => (\n  <SelectPrimitive.Label {...props} className={mx(recipes.label(), classNames)} ref={forwardedRef} />\n));\n\nSelectLabel.displayName = 'Select.Label';\n\n//\n// Trigger\n//\n\ntype SelectTriggerProps = ThemedClassName<Omit<SelectPrimitive.TriggerProps, 'children'>> & {\n  placeholder?: string;\n  /** Options are still arriving (an async lookup): a spinner replaces the caret and the trigger is `aria-busy`. */\n  loading?: boolean;\n  /**\n   * By default the trigger stretches across its cell. `fixed` sizes it to the widest option's icon and label (or the\n   * placeholder, if wider), so choosing a different option never changes its width: the labels are laid out, hidden,\n   * in the value's cell, which CSS sizes without measuring.\n   */\n  fixed?: boolean;\n};\n\n/** Shows the chosen option (its icon when exactly one is chosen; `multiple` lists the labels) and a caret. */\nconst SelectTrigger = forwardRef<HTMLButtonElement, SelectTriggerProps>(\n  ({ classNames, placeholder, loading, fixed, ...props }, forwardedRef) => {\n    const toolbarItem = useToolbarItem(props.disabled);\n    const { selectedItems, collection } = useSelectContext();\n    const selected = selectedItems.length === 1 ? selectedItems[0] : undefined;\n    return (\n      <SelectPrimitive.Trigger\n        {...props}\n        {...toolbarItem}\n        aria-busy={loading || undefined}\n        onFocus={(event) => {\n          props.onFocus?.(event);\n          toolbarItem?.onFocus();\n        }}\n        data-fixed={fixed || undefined}\n        className={mx(recipes.selectTrigger(), classNames)}\n        ref={forwardedRef}\n      >\n        {selected?.icon && <Icon.Icon icon={selected.icon} hue={selected.iconHue} />}\n        <SelectPrimitive.ValueText placeholder={placeholder} />\n        {fixed && (\n          <span aria-hidden data-scope='select' data-part='value-sizer' className={recipes.selectValueSizer()}>\n            {placeholder && <span>{placeholder}</span>}\n            {collection.items.map((item) => (\n              <span key={item.value}>\n                {item.icon && <Icon.Icon icon={item.icon} />}\n                {item.label}\n              </span>\n            ))}\n          </span>\n        )}\n        <SelectPrimitive.Indicator>\n          {loading ? (\n            <Icon.Icon icon='ph--spinner-gap--regular' spin />\n          ) : (\n            <Icon.Icon icon='ph--caret-up-down--regular' />\n          )}\n        </SelectPrimitive.Indicator>\n      </SelectPrimitive.Trigger>\n    );\n  },\n);\n\nSelectTrigger.displayName = 'Select.Trigger';\n\n//\n// Content\n//\n\ntype SelectContentProps = ThemedClassName<SelectPrimitive.ContentProps> & {\n  /** Overrides the size inherited from the trigger's nearest sized ancestor (Phase 4 decision 2). */\n  size?: Size;\n  /** Portals into this element instead of the body (e.g. a sized scope, AUDIT 2.2). */\n  container?: RefObject<HTMLElement | null>;\n};\n\n/**\n * Ark's content as a composable part, so the ScrollArea viewport slot merges onto it (a plain Ark part gets the dev\n * warning wrapper, which breaks the frame's child rules); it restates Ark's scope and part, which the slot's replace.\n */\nconst SelectViewport = composable<HTMLDivElement, SelectPrimitive.ContentProps>((props, forwardedRef) => (\n  <SelectPrimitive.Content {...composableProps(props)} data-scope='select' data-part='content' ref={forwardedRef} />\n));\n\n/** Portalled listbox at `level='popup'`, scrolling in a thin ScrollArea whose viewport is the listbox itself. */\nconst SelectContent = forwardRef<HTMLDivElement, SelectContentProps>(\n  ({ classNames, size, container, children, ...props }, forwardedRef) => {\n    const select = useSelectContext();\n    const popupSize = usePopupSize(size, select.open, [select.getTriggerProps().id]);\n    // With nothing to choose (a trigger still loading its options) the popup would open as an empty frame.\n    if (select.collection.items.length === 0) {\n      return null;\n    }\n\n    return (\n      <Portal container={container}>\n        <SelectPrimitive.Positioner>\n          <PopupScroll size={popupSize} classNames={mx(classNames)}>\n            <SelectViewport {...props} ref={forwardedRef}>\n              {children}\n            </SelectViewport>\n          </PopupScroll>\n        </SelectPrimitive.Positioner>\n      </Portal>\n    );\n  },\n);\n\nSelectContent.displayName = 'Select.Content';\n\n//\n// Item\n//\n\n// The option an Item renders, so its parts default to the option's icon and label.\nconst ItemContext = createContext<SelectOption | undefined>(undefined);\n\nconst useItem = (part: string) => {\n  const item = useContext(ItemContext);\n  if (!item) {\n    throw new Error(`Select.${part} must be inside Select.Item`);\n  }\n  return item;\n};\n\ntype SelectItemProps = ThemedClassName<Omit<SelectPrimitive.ItemProps, 'item' | 'children'>> & {\n  item: SelectOption;\n  /** Replaces the whole row, composed from `ItemIcon`, `ItemText` and `ItemIndicator`; the trigger still shows the label. */\n  children?: ReactNode;\n};\n\n/** A block-tall row: without children, the option's icon, its label and the check shown while it is selected. */\nconst SelectItem = forwardRef<HTMLDivElement, SelectItemProps>(\n  ({ classNames, item, children, ...props }, forwardedRef) => (\n    <ItemContext.Provider value={item}>\n      <SelectPrimitive.Item {...props} item={item} className={mx(recipes.selectItem(), classNames)} ref={forwardedRef}>\n        {children ?? (\n          <>\n            {item.icon && <SelectItemIcon />}\n            <SelectItemText />\n            <SelectItemIndicator />\n          </>\n        )}\n      </SelectPrimitive.Item>\n    </ItemContext.Provider>\n  ),\n);\n\nSelectItem.displayName = 'Select.Item';\n\n//\n// ItemIcon\n//\n\ntype SelectItemIconProps = Omit<Icon.IconProps, 'icon'> & {\n  /** Defaults to the option's `icon`. */\n  icon?: string;\n};\n\n/** The leading icon, in the option's `iconHue` unless given a `hue`. */\nconst SelectItemIcon = forwardRef<SVGSVGElement, SelectItemIconProps>(({ icon, hue, ...props }, forwardedRef) => {\n  const item = useItem('ItemIcon');\n  const glyph = icon ?? item.icon;\n  return glyph ? <Icon.Icon {...props} icon={glyph} hue={hue ?? item.iconHue} ref={forwardedRef} /> : null;\n});\n\nSelectItemIcon.displayName = 'Select.ItemIcon';\n\n//\n// ItemText\n//\n\ntype SelectItemTextProps = ThemedClassName<SelectPrimitive.ItemTextProps>;\n\n/** The row's label, taking the free space; the option's `label` by default. */\nconst SelectItemText = forwardRef<HTMLDivElement, SelectItemTextProps>(\n  ({ classNames, children, ...props }, forwardedRef) => {\n    const item = useItem('ItemText');\n    return (\n      <SelectPrimitive.ItemText {...props} className={mx(classNames)} ref={forwardedRef}>\n        {children ?? item.label}\n      </SelectPrimitive.ItemText>\n    );\n  },\n);\n\nSelectItemText.displayName = 'Select.ItemText';\n\n//\n// ItemIndicator\n//\n\ntype SelectItemIndicatorProps = ThemedClassName<SelectPrimitive.ItemIndicatorProps>;\n\n/** Shown while its item is selected: a check by default. */\nconst SelectItemIndicator = forwardRef<HTMLDivElement, SelectItemIndicatorProps>(\n  ({ classNames, children, ...props }, forwardedRef) => (\n    <SelectPrimitive.ItemIndicator {...props} className={mx(classNames)} ref={forwardedRef}>\n      {children ?? <Icon.Icon icon='ph--check--regular' />}\n    </SelectPrimitive.ItemIndicator>\n  ),\n);\n\nSelectItemIndicator.displayName = 'Select.ItemIndicator';\n\n//\n// ItemGroup\n//\n\ntype SelectItemGroupProps = ThemedClassName<SelectPrimitive.ItemGroupProps>;\n\n/** A `group` of options, named by the `ItemGroupLabel` inside it. */\nconst SelectItemGroup = forwardRef<HTMLDivElement, SelectItemGroupProps>(({ classNames, ...props }, forwardedRef) => (\n  <SelectPrimitive.ItemGroup {...props} className={mx(classNames)} ref={forwardedRef} />\n));\n\nSelectItemGroup.displayName = 'Select.ItemGroup';\n\n//\n// ItemGroupLabel\n//\n\ntype SelectItemGroupLabelProps = ThemedClassName<SelectPrimitive.ItemGroupLabelProps>;\n\n/** A small caption naming the group, like `Menu.ItemGroupLabel`. */\nconst SelectItemGroupLabel = forwardRef<HTMLDivElement, SelectItemGroupLabelProps>(\n  ({ classNames, ...props }, forwardedRef) => (\n    <SelectPrimitive.ItemGroupLabel\n      {...props}\n      className={mx(recipes.popupGroupLabel(), classNames)}\n      ref={forwardedRef}\n    />\n  ),\n);\n\nSelectItemGroupLabel.displayName = 'Select.ItemGroupLabel';\n\n//\n// Separator\n//\n\ntype SelectSeparatorProps = Omit<SeparatorProps, 'orientation' | 'decorative'>;\n\n/** A decorative rule between options: a listbox admits only options and groups, so it takes no separator role. */\nconst SelectSeparator = composable<HTMLDivElement, SelectSeparatorProps>((props, forwardedRef) => (\n  <Separator {...props} decorative ref={forwardedRef} />\n));\n\nSelectSeparator.displayName = 'Select.Separator';\nexport type {\n  SelectContentProps as ContentProps,\n  SelectItemGroupLabelProps as ItemGroupLabelProps,\n  SelectItemGroupProps as ItemGroupProps,\n  SelectItemIconProps as ItemIconProps,\n  SelectItemIndicatorProps as ItemIndicatorProps,\n  SelectItemProps as ItemProps,\n  SelectItemTextProps as ItemTextProps,\n  SelectLabelProps as LabelProps,\n  SelectPositioning as Positioning,\n  SelectRootProps as RootProps,\n  SelectSeparatorProps as SeparatorProps,\n  SelectTriggerProps as TriggerProps,\n};\n\nexport {\n  SelectContent as Content,\n  SelectItem as Item,\n  SelectItemGroup as ItemGroup,\n  SelectItemGroupLabel as ItemGroupLabel,\n  SelectItemIcon as ItemIcon,\n  SelectItemIndicator as ItemIndicator,\n  SelectItemText as ItemText,\n  SelectLabel as Label,\n  SelectRoot as Root,\n  SelectSeparator as Separator,\n  SelectTrigger as Trigger,\n};\nexport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