# Switch

A macOS toggle switch with smooth animation.

> For the complete documentation index, see [llms.txt](/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](/.well-known/agent-skills/site-skill.md).



<ComponentPreview name="switch/Basic" />

## Import [#import]

```rust
use maccn::MacSwitch;
```

## Usage [#usage]

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

## Sizes [#sizes]

<ComponentPreview name="switch/Sizes" />

```rust
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 [#disabled]

<ComponentPreview name="switch/Disabled" />

```rust
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 [#api]

### Props [#props]

| Prop       | Type             | Default   |
| ---------- | ---------------- | --------- |
| `size`     | `MacControlSize` | `Regular` |
| `checked`  | `bool`           | `false`   |
| `disabled` | `bool`           | `false`   |

### Events [#events]

| Event       | Payload                                      |
| ----------- | -------------------------------------------- |
| `on_change` | `(bool, &ClickEvent, &mut Window, &mut App)` |
