- Name
checked- Kind
- property
- Type
boolean- Requirement
- required
DocsAPI referenceUI machinesswitch
switch machine
The public state machine contract for @grassroot/ui-machines/switch. The machine owns behaviour; the matching headless layer owns composition.
@grassroot/ui-machines/switch
Package
Service example
switch.tsts
import { createService } from "@grassroot/statechart";import { switchMachine } from "@grassroot/ui-machines/switch"; const service = createService(switchMachine, { input: {} });service.start();service.send({ type: "…" });service.stop();11 of 11
Exports
SwitchChangeReason
typeSwitchChangeReasonts
type SwitchChangeReason = "pointer" | "keyboard" | "programmatic";SwitchCommand
typeSwitchCommandts
type SwitchCommand = CommandObject & { readonly type: "CHECKED_CHANGE_REQUEST"; readonly checked: boolean; readonly reason: SwitchChangeReason;};Name
Kind
Type
Requirement
checkedproperty
booleanrequired
reasonproperty
SwitchChangeReasonrequired
typeproperty
stringrequired
- Name
reason- Kind
- property
- Type
SwitchChangeReason- Requirement
- required
- Name
type- Kind
- property
- Type
string- Requirement
- required
SwitchContext
typeSwitchContextts
type SwitchContext = { readonly mode: "controlled" | "uncontrolled";};Name
Kind
Type
Requirement
modeproperty
"controlled" | "uncontrolled"required
- Name
mode- Kind
- property
- Type
"controlled" | "uncontrolled"- Requirement
- required
SwitchDiagnosticCodes
valueSwitchDiagnosticCodests
export declare const SwitchDiagnosticCodes: readonly DiagnosticCatalogueEntry[];SwitchEvent
typeSwitchEventts
type SwitchEvent = { readonly type: "PRESS"; readonly reason: SwitchChangeReason;} | { readonly type: "RESET";};SwitchInput
typeSwitchInputts
type SwitchInput = { readonly checked?: boolean; readonly defaultChecked?: boolean; readonly disabled?: boolean; readonly readOnly?: boolean;};Name
Kind
Type
Requirement
checkedproperty
booleanoptional
defaultCheckedproperty
booleanoptional
disabledproperty
booleanoptional
readOnlyproperty
booleanoptional
- Name
checked- Kind
- property
- Type
boolean- Requirement
- optional
- Name
defaultChecked- Kind
- property
- Type
boolean- Requirement
- optional
- Name
disabled- Kind
- property
- Type
boolean- Requirement
- optional
- Name
readOnly- Kind
- property
- Type
boolean- Requirement
- optional
switchMachine
valueswitchMachinets
export declare const switchMachine: Machine<SwitchInput, SwitchValue, SwitchContext, SwitchEvent, SwitchCommand>;switchReplaySequence
valueswitchReplaySequencets
export declare const switchReplaySequence: readonly SwitchEvent[];switchSelectors
valueswitchSelectorsts
export declare const switchSelectors: { checked: (snapshot: SwitchSnapshot) => boolean;};Name
Kind
Type
Requirement
checkedproperty
(snapshot: SwitchSnapshot) => booleanrequired
- Name
checked- Kind
- property
- Type
(snapshot: SwitchSnapshot) => boolean- Requirement
- required
SwitchSnapshot
typeSwitchSnapshotts
type SwitchSnapshot = Snapshot<SwitchValue, SwitchContext>;SwitchValue
typeSwitchValuets
type SwitchValue = "unchecked" | "checked";