Toggle
A button that stays pressed until it is clicked again: mute, a filter, show the map. For one choice out of several, use a Toggle Group.

Lucy.Stack.new({
direction = "horizontal",
gap = "Space2",
children = {
Lucy.Toggle.new({
text = "Crowd cheers",
pressed = true,
onPressedChange = function(on)
app.toast(if on then "Let them cheer" else "Crowd muted")
end,
}),
Lucy.Toggle.new({ text = "Lights", pressed = true, variant = "outline" }),
Lucy.Toggle.new({ text = "Shuffle", variant = "outline" }),
},
Parent = parent,
})
Props
| Prop | Type | Default | State key | What it does |
|---|---|---|---|---|
text | string | "" | yes | The text on it |
pressed | boolean | false | yes | Whether it is on |
variant | string | "default" | yes | default, outline, or line: text only, with a line under it while pressed |
size | string | "md" | yes | sm, md, lg or xl: each as tall as a Button of the same size |
disabled | boolean | false | yes | Greys it out and ignores clicks |
visible | boolean | true | yes | Shows or hides it |
icon | string | An icon name drawn before the text (toggle.icon) | ||
children | table | Anything after the text in the toggle's slot, such as a count. With no text, they show alone. They take the toggle's colours, on, hover and disabled included | ||
onPressedChange | function | Called with (pressed, handle) when it changes |
It also takes the props every component takes.
When the player turns it on or off, it reports toggle with the new value for
useUiSound.
Methods
| Name | What it does |
|---|---|
toggle:toggle() | Turns it on if off, off if on, as if the player clicked it |
Examples
Keep it in step with a setting:

local lights = app.state:ref("settings.lights")
Lucy.Toggle.new({ text = "Lights", pressed = lights, variant = "outline", Parent = hud })
Preview
In Studio, from the command bar: Lucy.Preview.show("Toggle").