Skip to content

Commit 0310da4

Browse files
committed
docs(components/switch): add switch component documentation and preview GIF
1 parent 099625b commit 0310da4

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

docs/en/components/switch.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Switch
3+
order: 4
4+
---
5+
6+
# Switch
7+
8+
```rust
9+
pub fn switch(args: impl Into<SwitchArgs>, state: Arc<RwLock<SwitchState>>)
10+
```
11+
12+
The `switch` component displays a toggle that can switch between on and off states.
13+
14+
## Arguments
15+
16+
- `args: impl Into<SwitchArgs>`
17+
18+
This argument configures the style of the `switch` component, including size, color, border, and other properties. Use `SwitchArgsBuilder` to construct it.
19+
20+
- `state: Arc<RwLock<SwitchState>>`
21+
22+
This argument manages the state of the `switch` component, including whether it is currently on or off. You can create an initial state with `SwitchState::new(bool)`. Use the `SwitchState::toggle(&mut self)` method to toggle the switch state.
23+
24+
## Preview
25+
26+
![switch](/switch_example.gif)

docs/public/switch_example.gif

76.5 KB
Loading

docs/zhHans/components/switch.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Switch 组件
3+
order: 4
4+
---
5+
6+
# Switch
7+
8+
```rust
9+
pub fn switch(args: impl Into<SwitchArgs>, state: Arc<RwLock<SwitchState>>)
10+
```
11+
12+
`switch` 组件用于显示一个开关,可以在开启和关闭状态之间切换。
13+
14+
## 参数
15+
16+
- `args: impl Into<SwitchArgs>`
17+
18+
该参数用于配置 `switch` 组件的样式,包括大小、颜色、边框等属性。可以通过 `SwitchArgsBuilder` 来构建。
19+
20+
- `state: Arc<RwLock<SwitchState>>`
21+
22+
该参数用于管理 `switch` 组件的状态,包括当前是开启还是关闭状态。可以通过 `SwitchState::new(bool)` 来创建初始状态。使用`SwitchState::toggle(&mut self)`方法可以切换开关状态。
23+
24+
## 预览
25+
26+
![switch](/switch_example.gif)

0 commit comments

Comments
 (0)