2024-01-03 20:52:56 +08:00
|
|
|
# Button
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space>
|
2024-05-01 20:26:17 +08:00
|
|
|
<Button>"Secondary"</Button>
|
2024-05-06 17:28:47 +08:00
|
|
|
<Button appearance=ButtonAppearance::Primary>"Primary"</Button>
|
|
|
|
<Button appearance=ButtonAppearance::Subtle>"Subtle"</Button>
|
|
|
|
<Button appearance=ButtonAppearance::Transparent>"Transparent"</Button>
|
2024-01-03 20:52:56 +08:00
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-05-06 17:28:47 +08:00
|
|
|
### Shape
|
2024-01-03 20:52:56 +08:00
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space>
|
2024-05-06 17:28:47 +08:00
|
|
|
<Button>"Rounded"</Button>
|
|
|
|
<Button shape=ButtonShape::Circular>"Circular"</Button>
|
|
|
|
<Button shape=ButtonShape::Square>"Square"</Button>
|
2024-01-03 20:52:56 +08:00
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Icon
|
|
|
|
|
|
|
|
```rust demo
|
2024-03-07 15:17:26 +08:00
|
|
|
let icon = create_rw_signal(Some(icondata::AiCloseOutlined));
|
|
|
|
|
|
|
|
let on_click = move |_| {
|
|
|
|
icon.update(|icon| {
|
|
|
|
*icon = match icon {
|
|
|
|
Some(data) => {
|
|
|
|
if *data == icondata::AiCloseOutlined {
|
|
|
|
icondata::AiCheckOutlined
|
|
|
|
} else {
|
|
|
|
icondata::AiCloseOutlined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => icondata::AiCloseOutlined
|
|
|
|
}.into();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-01-03 20:52:56 +08:00
|
|
|
view! {
|
2024-03-07 15:17:26 +08:00
|
|
|
<Space vertical=true>
|
|
|
|
<Space>
|
|
|
|
<Button icon on_click>
|
|
|
|
"Change icon"
|
|
|
|
</Button>
|
|
|
|
<Button icon on_click=move |_| icon.set(None)>
|
|
|
|
"Clear icon"
|
|
|
|
</Button>
|
|
|
|
</Space>
|
|
|
|
<Space>
|
|
|
|
<Button color=ButtonColor::Error icon=icondata::AiCloseOutlined>
|
|
|
|
"Error Color Icon"
|
|
|
|
</Button>
|
|
|
|
<Button color=ButtonColor::Error icon=icondata::AiCloseOutlined>
|
|
|
|
"Error Color Icon"
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
color=ButtonColor::Error
|
|
|
|
icon=icondata::AiCloseOutlined
|
|
|
|
round=true
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color=ButtonColor::Error
|
|
|
|
icon=icondata::AiCloseOutlined
|
|
|
|
circle=true
|
|
|
|
/>
|
|
|
|
</Space>
|
2024-01-03 20:52:56 +08:00
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-05-06 17:28:47 +08:00
|
|
|
### Color
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space>
|
|
|
|
<Button color=ButtonColor::Primary>"Primary Color"</Button>
|
|
|
|
<Button color=ButtonColor::Success>"Success Color"</Button>
|
|
|
|
<Button color=ButtonColor::Warning>"Warning Color"</Button>
|
|
|
|
<Button color=ButtonColor::Error>"Error Color"</Button>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2024-01-03 20:52:56 +08:00
|
|
|
### Loading
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
let loading = create_rw_signal(false);
|
|
|
|
let on_click = move |_| {
|
|
|
|
loading.set(true);
|
|
|
|
set_timeout(
|
|
|
|
move || {
|
|
|
|
loading.set(false);
|
|
|
|
},
|
|
|
|
std::time::Duration::new(2, 0),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
view! {
|
|
|
|
<Space>
|
2024-01-26 23:10:17 +09:00
|
|
|
<Button loading on_click icon=icondata::AiCloseOutlined>
|
2024-01-03 20:52:56 +08:00
|
|
|
"Click Me"
|
|
|
|
</Button>
|
|
|
|
<Button loading on_click>
|
|
|
|
"Click Me"
|
|
|
|
</Button>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Disabled
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space>
|
2024-05-06 17:28:47 +08:00
|
|
|
<Button appearance=ButtonAppearance::Primary disabled=true>
|
2024-01-03 20:52:56 +08:00
|
|
|
"Primary"
|
|
|
|
</Button>
|
2024-05-01 20:26:17 +08:00
|
|
|
<Button disabled=true>
|
2024-01-29 16:18:01 +08:00
|
|
|
"Outlined"
|
2024-01-03 20:52:56 +08:00
|
|
|
</Button>
|
2024-05-06 17:28:47 +08:00
|
|
|
<Button appearance=ButtonAppearance::Subtle disabled=true>
|
2024-05-01 20:26:17 +08:00
|
|
|
"Subtle"
|
2024-01-03 20:52:56 +08:00
|
|
|
</Button>
|
2024-05-06 17:28:47 +08:00
|
|
|
<Button appearance=ButtonAppearance::Transparent disabled=true>
|
2024-05-01 20:26:17 +08:00
|
|
|
"Transparent"
|
2024-01-03 20:52:56 +08:00
|
|
|
</Button>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Size
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space>
|
|
|
|
<Button size=ButtonSize::Tiny>"Primary"</Button>
|
|
|
|
<Button size=ButtonSize::Small>"Primary"</Button>
|
|
|
|
<Button size=ButtonSize::Medium>"Primary"</Button>
|
|
|
|
<Button size=ButtonSize::Large>"Primary"</Button>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-03-13 13:41:48 +08:00
|
|
|
### Block
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space vertical=true>
|
|
|
|
<Button block=true>"Primary"</Button>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-01-03 20:52:56 +08:00
|
|
|
### Group
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space>
|
|
|
|
<ButtonGroup>
|
2024-05-01 20:26:17 +08:00
|
|
|
<Button>"Outlined"</Button>
|
|
|
|
<Button>"Outlined"</Button>
|
|
|
|
<Button>"Outlined"</Button>
|
2024-01-03 20:52:56 +08:00
|
|
|
</ButtonGroup>
|
|
|
|
<ButtonGroup vertical=true>
|
2024-05-01 20:26:17 +08:00
|
|
|
<Button>"Outlined"</Button>
|
|
|
|
<Button>"Outlined"</Button>
|
|
|
|
<Button>"Outlined"</Button>
|
2024-01-03 20:52:56 +08:00
|
|
|
</ButtonGroup>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Button Props
|
|
|
|
|
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
2024-02-09 22:44:22 +08:00
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Additional classes for the button element. |
|
|
|
|
| style | `Option<MaybeSignal<String>>` | `Default::default()` | Button's style. |
|
2024-05-06 17:28:47 +08:00
|
|
|
| appearance | `MaybeSignal<ButtonAppearance>` | `ButtonAppearance::Primary` | Button's variant. |
|
2024-01-03 20:52:56 +08:00
|
|
|
| color | `MaybeSignal<ButtonColor>` | `ButtonColor::Primary` | Button's color. |
|
2024-03-13 13:41:48 +08:00
|
|
|
| block | `MaybeSignal<bool>` | `false` | Whether the button is displayed as block. |
|
2024-01-03 20:52:56 +08:00
|
|
|
| round | `MaybeSignal<bool>` | `false` | Whether the button shows rounded corners. |
|
|
|
|
| circle | `MaybeSignal<bool>` | `false` | Whether the button is round. |
|
2024-03-07 15:17:26 +08:00
|
|
|
| icon | `OptionalMaybeSignal<icondata_core::Icon>` | `None` | The icon of the button. |
|
2024-01-03 20:52:56 +08:00
|
|
|
| loading | `MaybeSignal<bool>` | `false` | Whether the button shows the loading status. |
|
|
|
|
| disabled | `MaybeSignal<bool>` | `false` | Whether the button is disabled. |
|
|
|
|
| size | `MaybeSignal<ButtonSize>` | `ButtonSize::Medium` | Button size. |
|
|
|
|
| on_click | `Option<Callback<ev::MouseEvent>>` | `None` | Listen for button click events. |
|
2024-02-09 22:44:22 +08:00
|
|
|
| children | `Option<Children>` | | Button's content. |
|
|
|
|
|
|
|
|
### ButtonGroup props
|
|
|
|
|
2024-03-13 13:41:48 +08:00
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| -------- | ----------------------------------- | -------------------- | ----------------------------------------- |
|
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Additional classes for the group element. |
|
|
|
|
| vertical | `bool` | `false` | Directions of buttons in the group. |
|
|
|
|
| children | `Children` | | ButtonGroup's content. |
|