Toggle
Switch or checkbox control
A switch or checkbox. action is a name your script recognises: flipping it re-runs the script with that action in Script.actions, and the payload carries the new state under value.
Methods
Toggle(options?)WidgetNodeA toggle switch.
- options Any
- isOn Boolean required
The current state.
- label String
Text beside it.
- color Color
Tint when on.
- style ToggleStyle
switch or checkbox. Default switch.
- action String
A name your script recognises. The tap re-runs the script with it in Script.actions.
- payload Any
Any JSON value, delivered alongside the action.
- isOn Boolean required
Examples
Settings toggle
var on = Storage.get("notifs") || false;
Script.onAction(function (a) {
if (a.name === "setNotifs") on = a.payload.value;
});
Storage.set("notifs", on);
Script.setWidget(new Widget({
child: Toggle({
value: on,
label: "Notifications",
color: Color.green(),
action: "setNotifs",
}),
}));