Switch
On or off for things that apply right away: a label and second line, at the start or across a settings row, a thumb that stretches as you press it, a pending state and a restart note.
oxyn add switchrsx! {
Switch {
label: "Auto-approve reads",
description: "Agents read files without asking",
checked: true,
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}Rendered from Rust at build time · goes live when visible
When to use
- On or off for things that apply right away: a label and second line, at the start or across a settings row, a thumb that stretches as you press it, a pending state and a restart note.
When not to use
- Switch between two to six options: use Segmented Control instead.
- How much the agent may do without asking: use Permission selector instead.
- A real checkbox with a label and second line, an indeterminate state for Select all, an error, a card row and a check that draws itself: use Checkbox instead.
Installation
Switch is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add switchuse crate::oxyn::{Switch, PRIMITIVES_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{Switch, PRIMITIVES_CSS};
Usage
rsx! {
Switch {
label: "Auto-approve reads",
description: "Agents read files without asking",
checked: true,
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}Examples
Start
Switch first, label after.
Code
rsx! {
Switch {
label: "Auto-approve reads",
description: "Agents read files without asking",
checked: true,
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}Ide xs
16 px switch for dense IDE panels (Oxyn plus).
Code
rsx! {
Switch {
label: "Auto-approve reads",
checked: true,
size: "xs",
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}Settings row
Label first, switch at the end of the row.
Code
rsx! {
Switch {
label: "Stream reasoning",
description: "Show the model's thinking as it arrives",
placement: "end",
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}Restart
Says the change needs a restart.
Code
rsx! {
Switch {
label: "GPU acceleration",
placement: "end",
restart_note: true,
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}Pending
Applying: the thumb waits for the host.
Code
rsx! {
Switch {
label: "Auto-approve reads",
description: "Agents read files without asking",
checked: true,
pending: true,
on_change: move |on: bool| settings.write().auto_approve_reads = on,
}
}API reference
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | String | — | Label. |
description | Option<String> | Default::default() | Second line. |
checked | bool | Default::default() | Initial value. |
placement | String | "start" | `start` (switch first) · `end` (settings row, switch at the end). |
size | String | "md" | `xs` · `sm` · `md` · `lg`. |
hide_label | bool | Default::default() | Keep the label for screen readers only (Arc: the label is the switch's name). |
name | Option<String> | Default::default() | Form field name (a hidden input carries `on` / `off`). |
disabled | bool | Default::default() | Disabled. |
pending | bool | Default::default() | Applying. |
restart_note | bool | Default::default() | Show "Requires restart" after a change. |
state | Option<String> | Default::default() | Review sheets: force `pressed` or `focus`. |
on_change | EventHandler<bool> | — | Changed. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| Space | Toggle |
| Enter | Toggle (like most settings panels) |
| Tab | Next control |
Accessibility
- A button with role=switch and aria-checked inside a real label element.
- Pending sets aria-busy while the host applies the change.
Responsive behaviour
- end placement stretches across the row, label left, switch right: the settings-list layout.
- The label is part of the hit area.
Notes for AI
- Import
Switchfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
SwitchElinoxyn_gpui. - Props to set first:
label. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.