{"version":3,"names":["dynamic","omit","createChangeEventDetails","REASONS","composeRefs","userRef","useCompositeRootContext","useCompositeListItem","createControlledState","readOption","mergeRootProps","resolveClassStyle","useButton","useToggleGroupContext","createToggle","Toggle","props","group","inGroup","present","ownDisabled","disabled","nativeButton","resolvedPressed","setUncontrolledPressed","controlled","v","value","includes","pressed","undefined","Boolean","default","defaultPressed","fallback","name","state","c","onPressedChange","next","event","details","none","setGroupValue","isCanceled","preventDefault","buttonProps","ref","buttonRef","native","composite","listItemRef","index","itemIndex","rootContext","groupTabIndex","highlightedIndex","onGroupFocus","i","onHighlightedIndexChange","compositeBag","tabIndex","onFocus","userStyling","userProps","step1","triggerBag","trigger","step2","styledUserProps","merged","Tag","as"],"sources":["toggle.tsx"],"sourcesContent":["import type { JSX, ValidComponent } from \"@solidjs/web\";\nimport { dynamic } from \"@solidjs/web\";\nimport { omit } from \"solid-js\";\nimport {\n\ttype BaseUIChangeEventDetails,\n\tcreateChangeEventDetails,\n\tREASONS,\n} from \"../internals/change-event-details\";\nimport { composeRefs, userRef } from \"../internals/compose-refs\";\nimport { useCompositeRootContext } from \"../internals/composite/composite-context.ts\";\nimport { useCompositeListItem } from \"../internals/composite/composite-list.tsx\";\nimport { createControlledState } from \"../internals/create-controlled-state\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport { mergeRootProps } from \"../internals/merge-root-props\";\nimport { resolveClassStyle } from \"../internals/resolve-class-style\";\nimport type {\n\tBaseUIComponentProps,\n\tNativeButtonProps,\n} from \"../internals/types\";\nimport { useButton } from \"../internals/use-button/use-button\";\nimport { useToggleGroupContext } from \"../toggle-group/toggle-group-context.ts\";\nimport { createToggle } from \"./create-toggle.tsx\";\n\n/**\n * The reason string attached to every `onPressedChange` event details object.\n * Matches Base UI React's `Toggle.ChangeEventReason`.\n */\nexport type ToggleChangeEventReason = typeof REASONS.none;\n\n/**\n * Shape of the details bag handed to `onPressedChange`.\n */\nexport type ToggleChangeEventDetails =\n\tBaseUIChangeEventDetails<ToggleChangeEventReason>;\n\n/**\n * The state object exposed through `data-*` projection and the `class` /\n * `style` callback surfaces.\n */\nexport interface ToggleState {\n\t/** Whether the toggle is currently pressed. */\n\tpressed: boolean;\n\t/** Whether the toggle ignores user interaction. */\n\tdisabled: boolean;\n}\n\nexport interface ToggleProps<Value extends string = string>\n\textends NativeButtonProps,\n\t\tBaseUIComponentProps<\"button\", ToggleState> {\n\t/**\n\t * Tag/component to render. Defaults to `\"button\"`. Replaces the\n\t * pre-spike `render` prop (axis G).\n\t */\n\tas?: ValidComponent;\n\t/**\n\t * Controlled pressed state. When provided (resolved value not\n\t * `undefined`), the consumer owns the state — pair with\n\t * {@link onPressedChange}. When omitted, the toggle manages its own\n\t * pressed state (seeded from {@link defaultPressed}). Inside a\n\t * `<ToggleGroup>` the group's `value` array owns the state instead.\n\t */\n\tpressed?: MaybeAccessor<boolean | undefined>;\n\t/**\n\t * Initial pressed state when uncontrolled. Read once at mount.\n\t * Ignored inside a `<ToggleGroup>` (use the group's `defaultValue`).\n\t * @default false\n\t */\n\tdefaultPressed?: MaybeAccessor<boolean | undefined>;\n\t/** @default false */\n\tdisabled?: boolean | undefined;\n\tonPressedChange?:\n\t\t| ((pressed: boolean, eventDetails: ToggleChangeEventDetails) => void)\n\t\t| undefined;\n\t/**\n\t * Identifier used when the toggle participates in a `<ToggleGroup>`.\n\t * Standalone toggles ignore this prop.\n\t */\n\tvalue?: Value | undefined;\n}\n\n/**\n * A two-state button that can be on or off. Renders a `<button>` element\n * (or `as` override).\n *\n * Solid 2.0-native rewire (§1 wave 1): replaces `renderElement` with\n * `dynamic(() => props.as ?? \"button\")` and threads\n * `createToggle().trigger()` + the `useButton` reactive bag + composite-\n * list focus/tabIndex through `mergeRootProps`. The slot factory now\n * carries data-pressed/data-disabled/aria-pressed.\n */\nexport function Toggle<Value extends string = string>(\n\tprops: ToggleProps<Value>,\n): JSX.Element {\n\tconst group = useToggleGroupContext<Value>();\n\tconst inGroup = group?.present === true;\n\n\tconst ownDisabled = (): boolean => {\n\t\tif (props.disabled) return true;\n\t\tif (inGroup) return group?.disabled() === true;\n\t\treturn false;\n\t};\n\tconst nativeButton = (): boolean => props.nativeButton ?? true;\n\n\t// Controlled / uncontrolled pressed state (Base UI `pressed` /\n\t// `defaultPressed` contract, mirroring React's `useControlled` in\n\t// `Toggle`): inside a group the pressed state is always derived from the\n\t// group's value array (always controlled, `default` is `undefined`);\n\t// standalone, the `pressed` prop wins while its resolved value is\n\t// defined, else an internal signal seeded once from `defaultPressed`.\n\tconst [resolvedPressed, setUncontrolledPressed] =\n\t\tcreateControlledState<boolean>({\n\t\t\tcontrolled: () => {\n\t\t\t\tif (inGroup) {\n\t\t\t\t\tconst v = props.value;\n\t\t\t\t\tif (v == null || v === \"\") return false;\n\t\t\t\t\treturn group?.value().includes(v) ?? false;\n\t\t\t\t}\n\t\t\t\tconst controlled = readOption(props.pressed);\n\t\t\t\treturn controlled === undefined ? undefined : Boolean(controlled);\n\t\t\t},\n\t\t\tdefault: () => (inGroup ? undefined : readOption(props.defaultPressed)),\n\t\t\tfallback: false,\n\t\t\tname: \"<Toggle>\",\n\t\t\tstate: \"pressed\",\n\t\t});\n\n\tconst c = createToggle({\n\t\tpressed: resolvedPressed,\n\t\tdisabled: ownDisabled,\n\t\tonPressedChange: (next, event) => {\n\t\t\tconst details = createChangeEventDetails(\n\t\t\t\tREASONS.none,\n\t\t\t\tevent,\n\t\t\t) as ToggleChangeEventDetails;\n\n\t\t\t// Base UI change flow (React `Toggle.onClick`): route the change\n\t\t\t// through the group first (the group fires its own onValueChange\n\t\t\t// against the same details bag), then the toggle's own\n\t\t\t// onPressedChange, then honor `details.cancel()`, then write the\n\t\t\t// uncontrolled state (a no-op for reads while controlled / in a\n\t\t\t// group).\n\t\t\tif (inGroup) {\n\t\t\t\tconst v = props.value;\n\t\t\t\tif (v != null && v !== \"\") {\n\t\t\t\t\tgroup?.setGroupValue(v, next, details);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprops.onPressedChange?.(next, details);\n\t\t\tif (details.isCanceled) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetUncontrolledPressed(next);\n\t\t},\n\t});\n\n\tconst { props: buttonProps, ref: buttonRef } = useButton({\n\t\tdisabled: c.disabled,\n\t\tnative: nativeButton,\n\t\tcomposite: () => inGroup,\n\t});\n\n\tconst { ref: listItemRef, index: itemIndex } = useCompositeListItem<unknown>(\n\t\t{},\n\t);\n\tconst rootContext = useCompositeRootContext(true);\n\n\tconst groupTabIndex = (): number | undefined => {\n\t\tif (!rootContext) return undefined;\n\t\treturn rootContext.highlightedIndex() === itemIndex() ? 0 : -1;\n\t};\n\n\tconst onGroupFocus = (): void => {\n\t\tif (!rootContext) return;\n\t\tconst i = itemIndex();\n\t\tif (i >= 0) rootContext.onHighlightedIndexChange(i);\n\t};\n\n\t// Composite/group concerns: tabIndex + focus handler. Plus useButton's\n\t// reactive bag. These form the \"internal\" side; c.trigger() is layered\n\t// next so the toggle's onClick composes correctly with useButton's\n\t// disabled-suppression.\n\tconst compositeBag = {\n\t\tget tabIndex() {\n\t\t\treturn groupTabIndex();\n\t\t},\n\t\tonFocus: onGroupFocus,\n\t};\n\n\tconst userStyling = resolveClassStyle(props, () => ({\n\t\tpressed: c.pressed(),\n\t\tdisabled: c.disabled(),\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\"defaultPressed\",\n\t\t\"disabled\",\n\t\t\"form\",\n\t\t\"nativeButton\",\n\t\t\"onPressedChange\",\n\t\t\"pressed\",\n\t\t\"type\",\n\t\t\"value\",\n\t);\n\n\t// Compose, left-to-right wins on the right per mergeRootProps:\n\t//   compositeBag ∘ buttonProps ∘ c.trigger() ∘ userProps\n\t// Event handlers chain in declaration order, gated by defaultPrevented\n\t// (so useButton's disabled check fires before the toggle onClick).\n\tconst step1 = mergeRootProps(compositeBag, buttonProps);\n\tconst triggerBag = c.trigger();\n\tconst step2 = mergeRootProps(step1, triggerBag);\n\tconst styledUserProps = mergeRootProps(userStyling, userProps);\n\n\tconst merged = mergeRootProps(step2, styledUserProps);\n\n\tconst Tag = dynamic(() => props.as ?? \"button\");\n\treturn (\n\t\t<Tag\n\t\t\t{...merged}\n\t\t\tref={composeRefs(buttonRef, listItemRef, userRef(props))}\n\t\t/>\n\t);\n}\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,cAAc;AACtC,SAASC,IAAI,QAAQ,UAAU;AAC/B,SAECC,wBAAwB,EACxBC,OAAO,QACD,mCAAmC;AAC1C,SAASC,WAAW,EAAEC,OAAO,QAAQ,2BAA2B;AAChE,SAASC,uBAAuB,QAAQ,6CAA6C;AACrF,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,qBAAqB,QAAQ,sCAAsC;AAC5E,SAA6BC,UAAU,QAAQ,6BAA6B;AAC5E,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,iBAAiB,QAAQ,kCAAkC;AAKpE,SAASC,SAAS,QAAQ,oCAAoC;AAC9D,SAASC,qBAAqB,QAAQ,yCAAyC;AAC/E,SAASC,YAAY,QAAQ,qBAAqB;;AAElD;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AACA;;AA0CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,MAAMA,CACrBC,KAAyB,EACX;EACd,MAAMC,KAAK,GAAGJ,qBAAqB,CAAQ,CAAC;EAC5C,MAAMK,OAAO,GAAGD,KAAK,EAAEE,OAAO,KAAK,IAAI;EAEvC,MAAMC,WAAW,GAAGA,CAAA,KAAe;IAClC,IAAIJ,KAAK,CAACK,QAAQ,EAAE,OAAO,IAAI;IAC/B,IAAIH,OAAO,EAAE,OAAOD,KAAK,EAAEI,QAAQ,CAAC,CAAC,KAAK,IAAI;IAC9C,OAAO,KAAK;EACb,CAAC;EACD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