Builtin Library
README.md
toggle
iOS-style on/off switch — a Luau builder over canvas. Draws a
rounded pill background, a white circle knob sliding along its axis,
and an optional text label next to it. Operable by mouse (click) and
keyboard (Tab to focus, Enter/Space to flip).
Exports
toggle(label, id, checked, opts?) -> Node— returns the toggle widget node. Module returns the builder function directly.
Types:
ToggleOpts = { style?, width?, height?, onColor?, offColor?, knobColor?, onChange?, classes?, ariaLabel?, app? }
Usage
local toggle = require("@builtin::modules.zui.widget.toggle")
toggle("Lights on", "lights", state.lights, { onChange = "lights:toggle" })
-- Without onChange, the callback id defaults to the widget id:
toggle("Bypass", "fx:bypass", state.bypass)
Notes
- Under
Z.appthe internal<id>:clickhandler readswidgetState(id, "checked"), flips it, and dispatchesonChange(or the widget id) with{ value = newBool }. The Router unpacksdata.valuesofunction(v) endreceives the new bool. - Without
Z.appthe canvas'sonClickroutes directly to the caller's callback id and the legacyonCallback(id, _)pattern (caller flips its own local state) keeps working. - DOM mirror surfaces as
<canvas role="switch" aria-checked="…">for screen-reader support.