GitHub

Reference machines

toggle

interface 2 type 3 function 1
interface Interfaces 2

# CreateToggleInput

Construction input.

Members

disabled?
optional disabled?: boolean

Construct the machine in the disabled state. Defaults to false.

initial?
optional initial?: boolean

Initial pressed value. Defaults to false.

# ToggleContext

Reactive state surfaced to consumers.

Members

pressed
pressed: boolean

Whether the toggle is currently pressed. Mirrored as aria-pressed.

toggles
toggles: number

Number of user-initiated toggles since construction. Useful for analytics and for detecting infinite-loop bugs in test fixtures.

type Type Aliases 3

# ToggleEvent

ToggleEvent = { type: "TOGGLE"; } | { pressed: boolean; type: "SET"; } | { type: "DISABLE"; } | { type: "ENABLE"; }

All events the Toggle machine can receive.

# ToggleState

ToggleState = "unpressed" | "pressed" | "disabled"

State names the machine can be in.

function Functions 1

# createToggleMachine ( )

createToggleMachine(input?): ToggleMachine

Construct a fresh Toggle machine.

Parameters

input?
CreateToggleInput = {}

Returns

ToggleMachine