# Checkbox

A macOS checkbox with checked, unchecked, and indeterminate states.

> 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="checkbox/Basic" />

## Import [#import]

```rust
use maccn::{MacCheckbox, MacCheckboxState};
```

## Usage [#usage]

```rust
MacCheckbox::new("agree")
    .checked(true)
    .on_change(|state, _, _, _| {
        println!("State: {:?}", state);
    })
    .child("I agree");
```

## States [#states]

<ComponentPreview name="checkbox/States" />

```rust
use gpui::div;
use maccn::{MacCheckbox, MacCheckboxState};

div()
    .flex()
    .flex_col()
    .gap_2()
    .child(MacCheckbox::new("check-unchecked").child("Unchecked"))
    .child(MacCheckbox::new("check-checked").checked(true).child("Checked"))
    .child(
        MacCheckbox::new("check-mixed")
            .indeterminate(true)
            .child("Indeterminate"),
    )
```

## Sizes [#sizes]

<ComponentPreview name="checkbox/Sizes" />

```rust
use gpui::div;
use maccn::{MacCheckbox, MacControlSize};

div()
    .flex()
    .items_center()
    .gap_2()
    .child(
        MacCheckbox::new("check-xl")
            .size(MacControlSize::ExtraLarge)
            .checked(true)
            .child("XL"),
    )
    .child(
        MacCheckbox::new("check-l")
            .size(MacControlSize::Large)
            .checked(true)
            .child("L"),
    )
    .child(MacCheckbox::new("check-r").checked(true).child("R"))
    .child(
        MacCheckbox::new("check-s")
            .size(MacControlSize::Small)
            .checked(true)
            .child("S"),
    )
    .child(
        MacCheckbox::new("check-m")
            .size(MacControlSize::Mini)
            .checked(true)
            .child("M"),
    )
```

## Disabled [#disabled]

<ComponentPreview name="checkbox/Disabled" />

```rust
use gpui::div;
use maccn::MacCheckbox;

div()
    .flex()
    .flex_col()
    .gap_2()
    .child(MacCheckbox::new("check-d1").disabled(true).child("Disabled"))
    .child(
        MacCheckbox::new("check-d2")
            .checked(true)
            .disabled(true)
            .child("Disabled checked"),
    )
```

## API [#api]

### Props [#props]

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

### State [#state]

| Method                    | Description                             |
| ------------------------- | --------------------------------------- |
| `state(MacCheckboxState)` | Sets the checkbox to any of the states. |
| `checked(bool)`           | Shortcut for `Checked` / `Unchecked`.   |
| `indeterminate(bool)`     | Sets the mixed state when `true`.       |

### Events [#events]

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