For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
/
3
Sponsor

Switch

A macOS toggle switch with smooth animation.

Import

use maccn::MacSwitch;

Usage

MacSwitch::new("wifi")
    .checked(true)
    .on_change(|next, _, _, _| {
        println!("Switched to: {}", next);
    })
    .child("Wi-Fi");

Sizes

use gpui::div;
use maccn::{MacControlSize, MacSwitch};
 
div()
    .flex()
    .items_center()
    .gap_2()
    .child(MacSwitch::new("switch-xl").size(MacControlSize::ExtraLarge).checked(true))
    .child(MacSwitch::new("switch-l").size(MacControlSize::Large).checked(true))
    .child(MacSwitch::new("switch-r").checked(true))
    .child(MacSwitch::new("switch-s").size(MacControlSize::Small).checked(true))
    .child(MacSwitch::new("switch-m").size(MacControlSize::Mini).checked(true))

Disabled

use gpui::div;
use maccn::MacSwitch;
 
div()
    .flex()
    .flex_col()
    .gap_2()
    .child(MacSwitch::new("switch-d1").disabled(true).child("Disabled"))
    .child(
        MacSwitch::new("switch-d2")
            .checked(true)
            .disabled(true)
            .child("Disabled on"),
    )

API

Props

PropTypeDefault
sizeMacControlSizeRegular
checkedboolfalse
disabledboolfalse

Events

EventPayload
on_change(bool, &ClickEvent, &mut Window, &mut App)