2023-12-31 23:33:05 +08:00
|
|
|
# Switch
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
let value = create_rw_signal(false);
|
|
|
|
|
2024-05-20 14:19:48 +08:00
|
|
|
let message = use_message();
|
|
|
|
let on_change = move |value: bool| {
|
|
|
|
message.create(
|
|
|
|
format!("{value}"),
|
|
|
|
MessageVariant::Success,
|
|
|
|
Default::default(),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-12-31 23:33:05 +08:00
|
|
|
view! {
|
2024-05-20 14:19:48 +08:00
|
|
|
<Switch value on_change/>
|
2023-12-31 23:33:05 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Switch Props
|
|
|
|
|
2024-05-20 14:19:48 +08:00
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| --------- | ----------------------------------- | -------------------- | ------------------------------------------- |
|
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the switch element. |
|
|
|
|
| value | `Model<bool>` | `false` | Switch's value. |
|
|
|
|
| on_change | `Option<Callback>` | `None` | Trigger when the checked state is changing. |
|