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

11 exports
View source packages/ui-machines/src/switch/index.ts

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();

Exports

DeclarationView source
SwitchChangeReasonts
type SwitchChangeReason = "pointer" | "keyboard" | "programmatic";
DeclarationView source
SwitchCommandts
type SwitchCommand = CommandObject & {
readonly type: "CHECKED_CHANGE_REQUEST";
readonly checked: boolean;
readonly reason: SwitchChangeReason;
};
Name
Kind
Type
Requirement
checked
property
boolean
required
reason
property
SwitchChangeReason
required
type
property
string
required
Name
checked
Kind
property
Type
boolean
Requirement
required
Name
reason
Kind
property
Type
SwitchChangeReason
Requirement
required
Name
type
Kind
property
Type
string
Requirement
required
DeclarationView source
SwitchContextts
type SwitchContext = {
readonly mode: "controlled" | "uncontrolled";
};
Name
Kind
Type
Requirement
mode
property
"controlled" | "uncontrolled"
required
Name
mode
Kind
property
Type
"controlled" | "uncontrolled"
Requirement
required
DeclarationView source
SwitchDiagnosticCodests
export declare const SwitchDiagnosticCodes: readonly DiagnosticCatalogueEntry[];
DeclarationView source
SwitchEventts
type SwitchEvent = {
readonly type: "PRESS";
readonly reason: SwitchChangeReason;
} | {
readonly type: "RESET";
};
DeclarationView source
SwitchInputts
type SwitchInput = {
readonly checked?: boolean;
readonly defaultChecked?: boolean;
readonly disabled?: boolean;
readonly readOnly?: boolean;
};
Name
Kind
Type
Requirement
checked
property
boolean
optional
defaultChecked
property
boolean
optional
disabled
property
boolean
optional
readOnly
property
boolean
optional
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
DeclarationView source
switchMachinets
export declare const switchMachine: Machine<SwitchInput, SwitchValue, SwitchContext, SwitchEvent, SwitchCommand>;
DeclarationView source
switchReplaySequencets
export declare const switchReplaySequence: readonly SwitchEvent[];
DeclarationView source
switchSelectorsts
export declare const switchSelectors: {
checked: (snapshot: SwitchSnapshot) => boolean;
};
Name
Kind
Type
Requirement
checked
property
(snapshot: SwitchSnapshot) => boolean
required
Name
checked
Kind
property
Type
(snapshot: SwitchSnapshot) => boolean
Requirement
required
DeclarationView source
SwitchSnapshotts
type SwitchSnapshot = Snapshot<SwitchValue, SwitchContext>;
DeclarationView source
SwitchValuets
type SwitchValue = "unchecked" | "checked";