Skip to content

Component Switch

MeowLynxSea edited this page Jun 18, 2026 · 6 revisions

Switch

A binary on/off toggle. Use for settings; use Checkbox for consent / form fields.

use yororen_ui::headless::switch::switch;

switch("notifications", cx)
    .checked(self.notifications_on)
    .on_toggle({
        let entity = cx.entity();
        move |new, _, cx| entity.update(cx, |s, _| s.notifications_on = new);
    })
    .render(cx)

Props

Method Purpose
checked(v) Current state.
disabled(v) Disable the toggle.
on_toggle(closure) Fn(bool, &mut Window, &mut App) + 'static + Send + Sync.
has_custom_tone(v) / custom_tone(hsla) Override the on-tone color.

Factory takes (id, cx). .render(cx) returns Stateful<Div>. No state entity.

See also: Checkbox, ToggleButton, Radio.

Clone this wiki locally