import type { JSX, ValidComponent } from "@solidjs/web"; import { dynamic } from "@solidjs/web"; import { omit } from "solid-js"; import { type BaseUIChangeEventDetails, createChangeEventDetails, REASONS, } from "../internals/change-event-details"; import { composeRefs, userRef } from "../internals/compose-refs"; import { useCompositeRootContext } from "../internals/composite/composite-context.ts"; import { useCompositeListItem } from "../internals/composite/composite-list.tsx"; import { createControlledState } from "../internals/create-controlled-state"; import { type MaybeAccessor, readOption } from "../internals/maybe-accessor"; import { mergeRootProps } from "../internals/merge-root-props"; import { resolveClassStyle } from "../internals/resolve-class-style"; import type { BaseUIComponentProps, NativeButtonProps, } from "../internals/types"; import { useButton } from "../internals/use-button/use-button"; import { useToggleGroupContext } from "../toggle-group/toggle-group-context.ts"; import { createToggle } from "./create-toggle.tsx"; /** * The reason string attached to every `onPressedChange` event details object. * Matches Base UI React's `Toggle.ChangeEventReason`. */ export type ToggleChangeEventReason = typeof REASONS.none; /** * Shape of the details bag handed to `onPressedChange`. */ export type ToggleChangeEventDetails = BaseUIChangeEventDetails; /** * The state object exposed through `data-*` projection and the `class` / * `style` callback surfaces. */ export interface ToggleState { /** Whether the toggle is currently pressed. */ pressed: boolean; /** Whether the toggle ignores user interaction. */ disabled: boolean; } export interface ToggleProps extends NativeButtonProps, BaseUIComponentProps<"button", ToggleState> { /** * Tag/component to render. Defaults to `"button"`. Replaces the * pre-spike `render` prop (axis G). */ as?: ValidComponent; /** * Controlled pressed state. When provided (resolved value not * `undefined`), the consumer owns the state — pair with * {@link onPressedChange}. When omitted, the toggle manages its own * pressed state (seeded from {@link defaultPressed}). Inside a * `` the group's `value` array owns the state instead. */ pressed?: MaybeAccessor; /** * Initial pressed state when uncontrolled. Read once at mount. * Ignored inside a `` (use the group's `defaultValue`). * @default false */ defaultPressed?: MaybeAccessor; /** @default false */ disabled?: boolean | undefined; onPressedChange?: | ((pressed: boolean, eventDetails: ToggleChangeEventDetails) => void) | undefined; /** * Identifier used when the toggle participates in a ``. * Standalone toggles ignore this prop. */ value?: Value | undefined; } /** * A two-state button that can be on or off. Renders a `