{"version":3,"names":["dynamic","omit","useDirection","composeRefs","userRef","CompositeRootContext","CompositeList","useCompositeRoot","createControlledState","mergeRootProps","resolveClassStyle","createStableCallback","ToggleGroupContext","EMPTY","Object","freeze","ToggleGroup","props","disabled","multiple","orientation","loopFocus","direction","value","setUncontrolledValue","controlled","default","defaultValue","fallback","name","state","isValueInitialized","undefined","setGroupValue","newValue","nextPressed","details","current","nextGroupValue","slice","push","idx","indexOf","splice","onValueChange","isCanceled","composite","enableHomeAndEndKeys","rootContext","highlightedIndex","onHighlightedIndexChange","highlightItemOnHover","relayKeyboardEvent","present","contextValue","userStyling","userProps","internalSlot","role","data-disabled","data-multiple","data-orientation","styledUserProps","merged","Tag","as","rootRef","elementsRef","onMapChange","children"],"sources":["toggle-group.tsx"],"sourcesContent":["import type { JSX, ValidComponent } from \"@solidjs/web\";\nimport { dynamic } from \"@solidjs/web\";\nimport { omit } from \"solid-js\";\nimport { useDirection } from \"../direction-provider/direction-provider-context.ts\";\nimport type { BaseUIEventReasons } from \"../internals/change-event-details\";\nimport { composeRefs, userRef } from \"../internals/compose-refs\";\nimport {\n\tCompositeRootContext,\n\ttype CompositeRootContextValue,\n} from \"../internals/composite/composite-context.ts\";\nimport { CompositeList } from \"../internals/composite/composite-list.tsx\";\nimport { useCompositeRoot } from \"../internals/composite/composite-root.ts\";\nimport { createControlledState } from \"../internals/create-controlled-state\";\nimport { mergeRootProps } from \"../internals/merge-root-props\";\nimport { resolveClassStyle } from \"../internals/resolve-class-style\";\nimport { createStableCallback } from \"../internals/stable-callback\";\nimport type { BaseUIComponentProps, Orientation } from \"../internals/types\";\nimport {\n\ttype ToggleGroupChangeEventDetails,\n\tToggleGroupContext,\n\ttype ToggleGroupContextValue,\n} from \"./toggle-group-context.ts\";\n\nexport type ToggleGroupChangeEventReason = BaseUIEventReasons[\"none\"];\nexport type { ToggleGroupChangeEventDetails };\n\n/**\n * State projected to `data-*` attributes. `orientation` projects via the\n * default mapping as `data-orientation=\"horizontal\"` / `\"vertical\"`.\n * `disabled` + `multiple` are emitted as presence-only attrs.\n */\nexport interface ToggleGroupState {\n\t/** Whether the group ignores user interaction. */\n\tdisabled: boolean;\n\t/** `true` when any subset of children can be pressed simultaneously. */\n\tmultiple: boolean;\n\t/** Keyboard-navigation orientation. */\n\torientation: Orientation;\n}\n\nexport interface ToggleGroupProps<Value extends string = string>\n\textends BaseUIComponentProps<\"div\", ToggleGroupState> {\n\t/**\n\t * Tag/component to render. Defaults to `\"div\"`. Replaces the\n\t * pre-spike `render` prop (axis G).\n\t */\n\tas?: ValidComponent;\n\t/**\n\t * Controlled pressed-state array. When provided (not `undefined`), the\n\t * consumer owns the state — pair with {@link onValueChange}. When\n\t * omitted, the group manages its own value (seeded from\n\t * {@link defaultValue}). An empty array IS a controlled value.\n\t */\n\tvalue?: readonly Value[] | undefined;\n\t/**\n\t * Initial pressed-state array when uncontrolled. Read once at mount.\n\t * @default []\n\t */\n\tdefaultValue?: readonly Value[] | undefined;\n\t/**\n\t * Fires when the set of pressed values changes. Consumer may call\n\t * `details.cancel()` to veto the write.\n\t */\n\tonValueChange?:\n\t\t| ((groupValue: Value[], details: ToggleGroupChangeEventDetails) => void)\n\t\t| undefined;\n\t/**\n\t * Whether the group (and every descendant toggle) ignores user interaction.\n\t * @default false\n\t */\n\tdisabled?: boolean | undefined;\n\t/**\n\t * Navigation orientation — drives arrow-key dispatch and the\n\t * `data-orientation` attribute.\n\t * @default \"horizontal\"\n\t */\n\torientation?: Orientation | undefined;\n\t/**\n\t * Whether arrow-key navigation loops focus at the ends.\n\t * @default true\n\t */\n\tloopFocus?: boolean | undefined;\n\t/**\n\t * When `true`, multiple toggles can be pressed simultaneously.\n\t * @default false\n\t */\n\tmultiple?: boolean | undefined;\n}\n\nconst EMPTY: readonly string[] = Object.freeze([]);\n\n/**\n * Groups a series of `<Toggle>` elements, coordinating their pressed state\n * through a single `value` array. Renders a `<div role=\"group\">` (or `as`\n * override).\n *\n * §1 wave 2: replaces `renderElement` with `dynamic(() => props.as ?? \"div\")`.\n * The state-attr projection (`data-disabled`, `data-multiple`,\n * `data-orientation`) is emitted via inline reactive getters; the composite\n * root's `props` bag (aria-orientation, onKeyDown, onFocus) is composed via\n * `mergeRootProps`.\n */\nexport function ToggleGroup<Value extends string = string>(\n\tprops: ToggleGroupProps<Value>,\n): JSX.Element {\n\tconst disabled = (): boolean => props.disabled === true;\n\tconst multiple = (): boolean => props.multiple === true;\n\tconst orientation = (): Orientation => props.orientation ?? \"horizontal\";\n\tconst loopFocus = (): boolean => props.loopFocus ?? true;\n\n\tconst direction = useDirection();\n\n\t// Controlled / uncontrolled group value (Base UI `value` / `defaultValue`\n\t// contract, mirroring React's `useControlled` in `ToggleGroup`): the\n\t// `value` prop wins while defined (an empty array IS controlled);\n\t// otherwise an internal signal (seeded once from `defaultValue`, else\n\t// `[]`) backs the state.\n\tconst [value, setUncontrolledValue] = createControlledState<readonly Value[]>(\n\t\t{\n\t\t\tcontrolled: () => props.value,\n\t\t\tdefault: () => props.defaultValue,\n\t\t\tfallback: EMPTY as readonly Value[],\n\t\t\tname: \"<ToggleGroup>\",\n\t\t\tstate: \"value\",\n\t\t},\n\t);\n\n\tconst isValueInitialized = (): boolean =>\n\t\tprops.value !== undefined || props.defaultValue !== undefined;\n\n\tconst setGroupValue = createStableCallback<\n\t\t(\n\t\t\tnewValue: Value,\n\t\t\tnextPressed: boolean,\n\t\t\tdetails: ToggleGroupChangeEventDetails,\n\t\t) => void\n\t>(() => (newValue, nextPressed, details) => {\n\t\tconst current = value();\n\t\tlet nextGroupValue: Value[];\n\t\tif (multiple()) {\n\t\t\tnextGroupValue = current.slice();\n\t\t\tif (nextPressed) {\n\t\t\t\tnextGroupValue.push(newValue);\n\t\t\t} else {\n\t\t\t\tconst idx = nextGroupValue.indexOf(newValue);\n\t\t\t\tif (idx > -1) nextGroupValue.splice(idx, 1);\n\t\t\t}\n\t\t} else {\n\t\t\tnextGroupValue = nextPressed ? [newValue] : [];\n\t\t}\n\t\t// Base UI change flow: fire onValueChange first, honor\n\t\t// `details.cancel()`, then write the uncontrolled state (a no-op for\n\t\t// reads while the `value` prop is controlled).\n\t\tprops.onValueChange?.(nextGroupValue, details);\n\t\tif (details.isCanceled) {\n\t\t\treturn;\n\t\t}\n\t\tsetUncontrolledValue(nextGroupValue);\n\t});\n\n\tconst composite = useCompositeRoot({\n\t\tget orientation() {\n\t\t\treturn orientation();\n\t\t},\n\t\tget loopFocus() {\n\t\t\treturn loopFocus();\n\t\t},\n\t\tdirection,\n\t\tenableHomeAndEndKeys: true,\n\t});\n\n\tconst rootContext: CompositeRootContextValue = {\n\t\thighlightedIndex: composite.highlightedIndex,\n\t\tonHighlightedIndexChange: composite.onHighlightedIndexChange,\n\t\thighlightItemOnHover: () => false,\n\t\trelayKeyboardEvent: composite.relayKeyboardEvent,\n\t\tpresent: true,\n\t};\n\n\tconst contextValue: ToggleGroupContextValue<Value> = {\n\t\tvalue,\n\t\tsetGroupValue,\n\t\tdisabled,\n\t\tget orientation() {\n\t\t\treturn orientation();\n\t\t},\n\t\tmultiple,\n\t\tisValueInitialized,\n\t\tpresent: true,\n\t};\n\n\t// Strip wrapper-owned API keys + `as` + `children` (re-injected wrapped\n\t// in providers below).\n\tconst userStyling = resolveClassStyle(props, () => ({\n\t\tdisabled: disabled(),\n\t\tmultiple: multiple(),\n\t\torientation: orientation(),\n\t}));\n\n\tconst userProps = omit(\n\t\tprops,\n\t\t\"class\",\n\t\t\"style\",\n\t\t\"attrs\",\n\t\t\"as\",\n\t\t\"children\",\n\t\t\"defaultValue\",\n\t\t\"disabled\",\n\t\t\"loopFocus\",\n\t\t\"multiple\",\n\t\t\"onValueChange\",\n\t\t\"orientation\",\n\t\t\"value\",\n\t);\n\n\t// Internal slot bag: role + state-attr getters + composite props\n\t// (aria-orientation, onKeyDown, onFocus). Inline reactive getters keep\n\t// the data-attrs live across upstream signal flips.\n\tconst internalSlot = {\n\t\trole: \"group\" as const,\n\t\tget \"data-disabled\"(): \"\" | undefined {\n\t\t\treturn disabled() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-multiple\"(): \"\" | undefined {\n\t\t\treturn multiple() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-orientation\"(): string {\n\t\t\treturn orientation();\n\t\t},\n\t};\n\n\tconst styledUserProps = mergeRootProps(userStyling, userProps);\n\n\tlet merged: Record<string, unknown> = mergeRootProps(\n\t\tinternalSlot,\n\t\tcomposite.props,\n\t);\n\tmerged = mergeRootProps(merged, styledUserProps);\n\n\tconst Tag = dynamic(() => props.as ?? \"div\");\n\treturn (\n\t\t<Tag {...merged} ref={composeRefs(composite.rootRef, userRef(props))}>\n\t\t\t<ToggleGroupContext value={contextValue}>\n\t\t\t\t<CompositeRootContext value={rootContext}>\n\t\t\t\t\t<CompositeList\n\t\t\t\t\t\telementsRef={composite.elementsRef}\n\t\t\t\t\t\tonMapChange={composite.onMapChange}\n\t\t\t\t\t>\n\t\t\t\t\t\t{props.children}\n\t\t\t\t\t</CompositeList>\n\t\t\t\t</CompositeRootContext>\n\t\t\t</ToggleGroupContext>\n\t\t</Tag>\n\t);\n}\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,cAAc;AACtC,SAASC,IAAI,QAAQ,UAAU;AAC/B,SAASC,YAAY,QAAQ,qDAAqD;AAElF,SAASC,WAAW,EAAEC,OAAO,QAAQ,2BAA2B;AAChE,SACCC,oBAAoB,QAEd,6CAA6C;AACpD,SAASC,aAAa,QAAQ,2CAA2C;AACzE,SAASC,gBAAgB,QAAQ,0CAA0C;AAC3E,SAASC,qBAAqB,QAAQ,sCAAsC;AAC5E,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,oBAAoB,QAAQ,8BAA8B;AAEnE,SAECC,kBAAkB,QAEZ,2BAA2B;;AAKlC;AACA;AACA;AACA;AACA;;AA2DA,MAAMC,KAAwB,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;;AAElD;AAC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