import type { JSX, ValidComponent } from "@solidjs/web"; import { dynamic } from "@solidjs/web"; import { createMemo, omit } from "solid-js"; import { type BaseUIChangeEventDetails, createChangeEventDetails, REASONS, } from "../../internals/change-event-details"; import { composeRefs, userRef } from "../../internals/compose-refs"; import { createControlledState } from "../../internals/create-controlled-state"; import { useFieldRootContext } from "../../internals/field-context"; import { fieldStateAttrs } from "../../internals/field-state-attrs"; import { HiddenInput } from "../../internals/hidden-input/hidden-input.tsx"; import { useAriaLabelledBy } from "../../internals/labelable-provider/use-aria-labelled-by.ts"; import { type MaybeAccessor, readOption } from "../../internals/maybe-accessor"; import { mergeRootProps } from "../../internals/merge-root-props"; import { resolveClassStyle } from "../../internals/resolve-class-style"; import { ariaLabelledBy as seedAriaLabelledBy } from "../../internals/seed-aria-attr"; import type { BaseUIComponentProps, NativeButtonProps, } from "../../internals/types"; import { useButton } from "../../internals/use-button/use-button"; import { useFieldControlValidation } from "../../internals/use-field-control-validation/use-field-control-validation.ts"; import { createSwitch } from "../create-switch.tsx"; import { SwitchRootContext, type SwitchRootContextValue, type SwitchRootState, } from "../switch-root-context.ts"; /** The reason carried on every `onCheckedChange` event details bag. */ export type SwitchRootChangeEventReason = typeof REASONS.none; /** Shape of the `onCheckedChange` event details bag. */ export type SwitchRootChangeEventDetails = BaseUIChangeEventDetails; export interface SwitchRootProps extends NativeButtonProps, Omit, "onChange"> { /** * Tag/component to render. Defaults to `"button"`. Replaces the * pre-spike `render` prop (axis G). */ as?: ValidComponent; /** * Controlled checked state. When provided (resolved value not * `undefined`), the consumer owns the state — pair with * {@link onCheckedChange}. When omitted, the switch manages its own * checked state (seeded from {@link defaultChecked}). */ checked?: MaybeAccessor; /** * Initial checked state when uncontrolled. Read once at mount. * @default false */ defaultChecked?: MaybeAccessor; /** @default false */ disabled?: boolean | undefined; name?: string | undefined; form?: string | undefined; onCheckedChange?: | ((checked: boolean, eventDetails: SwitchRootChangeEventDetails) => void) | undefined; /** @default false */ readOnly?: MaybeAccessor; /** @default false */ required?: MaybeAccessor; value?: string | undefined; uncheckedValue?: string | undefined; } export type { SwitchRootState }; /** * Represents the switch itself. Renders a `