Skip to content

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 switch
MCP
Dioxus
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,
    }
}

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.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add switch
Rust
use 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

Dioxus · rust
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

PropTypeDefaultDescription
labelrequiredString—Label.
descriptionOption<String>Default::default()Second line.
checkedboolDefault::default()Initial value.
placementString"start"`start` (switch first) · `end` (settings row, switch at the end).
sizeString"md"`xs` · `sm` · `md` · `lg`.
hide_labelboolDefault::default()Keep the label for screen readers only (Arc: the label is the switch's name).
nameOption<String>Default::default()Form field name (a hidden input carries `on` / `off`).
disabledboolDefault::default()Disabled.
pendingboolDefault::default()Applying.
restart_noteboolDefault::default()Show "Requires restart" after a change.
stateOption<String>Default::default()Review sheets: force `pressed` or `focus`.
on_changeEventHandler<bool>—Changed.

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
SpaceToggle
EnterToggle (like most settings panels)
TabNext 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 Switch from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: SwitchEl in oxyn_gpui.
  • Props to set first: label.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI