{"version":3,"file":"chunk-ToggleGroup.mjs","names":["ToggleGroupPrimitive"],"sources":["../../src/components/ToggleGroup/ToggleGroup.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { ToggleGroup as ToggleGroupPrimitive } from '@ark-ui/react/toggle-group';\nimport React, { type ComponentPropsWithoutRef, forwardRef } from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nimport { recipes } from '../../recipes.ts';\nimport { Button } from '../Button/Button.tsx';\n\n//\n// Root\n//\n\ntype ToggleGroupCommonProps = ThemedClassName<\n  Omit<ComponentPropsWithoutRef<'div'>, 'defaultValue' | 'dir' | 'onChange'>\n> & {\n  disabled?: boolean;\n  orientation?: 'horizontal' | 'vertical';\n  /** Wrap arrow navigation at the ends. */\n  loop?: boolean;\n  /** Arrow keys move focus between the items; off when an enclosing Toolbar roves over them instead. */\n  rovingFocus?: boolean;\n};\n\ntype ToggleGroupSingleProps = ToggleGroupCommonProps & {\n  type: 'single';\n  value?: string;\n  defaultValue?: string;\n  /** The empty string when the pressed item is released. */\n  onValueChange?: (value: string) => void;\n};\n\ntype ToggleGroupMultipleProps = ToggleGroupCommonProps & {\n  type: 'multiple';\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n};\n\ntype ToggleGroupRootProps = ToggleGroupSingleProps | ToggleGroupMultipleProps;\n\n/** The machine speaks arrays; a single-select group speaks one value or none. */\nconst toMachineValue = (value: string | string[] | undefined): string[] | undefined =>\n  value === undefined ? undefined : Array.isArray(value) ? value : value ? [value] : [];\n\n/**\n * Ark toggle group: `single` is a `radiogroup` of `radio` items (`aria-checked`), `multiple` a `group` of pressed\n * toggles (`aria-pressed`), with roving focus between the items unless `rovingFocus={false}`.\n */\nconst ToggleGroupRoot = forwardRef<HTMLDivElement, ToggleGroupRootProps>((props, forwardedRef) => {\n  const { classNames, type, value, defaultValue, onValueChange: _, loop, rovingFocus = true, ...rootProps } = props;\n  return (\n    <ToggleGroupPrimitive.Root\n      {...rootProps}\n      multiple={type === 'multiple'}\n      value={toMachineValue(value)}\n      defaultValue={toMachineValue(defaultValue)}\n      onValueChange={({ value }) => {\n        if (props.type === 'single') {\n          props.onValueChange?.(value[0] ?? '');\n        } else {\n          props.onValueChange?.(value);\n        }\n      }}\n      loopFocus={loop}\n      rovingFocus={rovingFocus}\n      // zag makes the root a tab stop that forwards focus to an item; without roving the items are the tab stops.\n      {...(!rovingFocus && { tabIndex: -1 })}\n      className={mx(recipes.toggleGroup(), classNames)}\n      ref={forwardedRef}\n    />\n  );\n});\n\nToggleGroupRoot.displayName = 'ToggleGroup.Root';\n\n//\n// Item\n//\n\ntype ToggleGroupItemProps = ComponentPropsWithoutRef<typeof Button> & {\n  value: string;\n};\n\n/** A Button whose pressed state belongs to the group. */\nconst ToggleGroupItem = forwardRef<HTMLButtonElement, ToggleGroupItemProps>(\n  ({ value, disabled, ...props }, forwardedRef) => (\n    <ToggleGroupPrimitive.Item value={value} disabled={disabled} asChild>\n      <Button {...props} disabled={disabled} ref={forwardedRef} />\n    </ToggleGroupPrimitive.Item>\n  ),\n);\n\nToggleGroupItem.displayName = 'ToggleGroup.Item';\nexport type { ToggleGroupItemProps as ItemProps, ToggleGroupRootProps as RootProps };\n\nexport { ToggleGroupItem as Item, ToggleGroupRoot as Root };\n"],"mappings":";;;;;;;;;;;;;AAgDA,IAAM,kBAAkB,UACtB,UAAU,KAAA,IAAY,KAAA,IAAY,MAAM,QAAQ,KAAK,IAAI,QAAQ,QAAQ,CAAC,KAAK,IAAI,CAAC;;;;;AAMtF,IAAM,kBAAkB,YAAkD,OAAO,iBAAiB;CAChG,MAAM,EAAE,YAAY,MAAM,OAAO,cAAc,eAAe,GAAG,MAAM,cAAc,MAAM,GAAG,cAAc;CAC5G,OACE,oBAACA,YAAqB,MAAtB;EACE,GAAI;EACJ,UAAU,SAAS;EACnB,OAAO,eAAe,KAAK;EAC3B,cAAc,eAAe,YAAY;EACzC,gBAAgB,EAAE,YAAY;GAC5B,IAAI,MAAM,SAAS,UACjB,MAAM,gBAAgB,MAAM,MAAM,EAAE;QAEpC,MAAM,gBAAgB,KAAK;EAE/B;EACA,WAAW;EACE;EAEb,GAAK,CAAC,eAAe,EAAE,UAAU,GAAG;EACpC,WAAW,GAAG,QAAQ,YAAY,GAAG,UAAU;EAC/C,KAAK;CACN,CAAA;AAEL,CAAC;AAED,gBAAgB,cAAc;;AAW9B,IAAM,kBAAkB,YACrB,EAAE,OAAO,UAAU,GAAG,SAAS,iBAC9B,oBAACA,YAAqB,MAAtB;CAAkC;CAAiB;CAAU,SAAA;CAC3D,UAAA,oBAAC,QAAD;EAAQ,GAAI;EAAiB;EAAU,KAAK;CAAe,CAAA;AAClC,CAAA,CAE/B;AAEA,gBAAgB,cAAc"}