Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/switch #615

Merged
merged 2 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/switch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ isComponent: true

<img src="https://tdesign.gtimg.com/miniprogram/readme/switch.png" width="375px" height="50%">

```html
<!-- page.wxml -->
{{ base }}


### 开关状态

{{ status }}


<!-- 受控用法 -->
### 受控用法

```html
<t-switch value="{{value}}" bindchange="onChange"></t-switch>

<!-- 非受控用法 -->
```
### 非受控用法

```html
<t-switch defaultValue="{{value}}"></t-switch>
```

Expand Down
10 changes: 10 additions & 0 deletions src/switch/_example/base/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Component({
data: {
defaultVal: true,
},
handleChange(e) {
this.setData({
defaultVal: e.detail.value,
});
},
});
3 changes: 3 additions & 0 deletions src/switch/_example/base/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"component": true
}
26 changes: 26 additions & 0 deletions src/switch/_example/base/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<view class="group">
<t-cell title="默认">
<t-switch defaultValue="{{true}}"></t-switch>
</t-cell>
<t-cell title="默认关">
<t-switch defaultValue="{{false}}"></t-switch>
</t-cell>
<t-cell title="自定义颜色">
<t-switch defaultValue="{{true}}" colors="{{['#00A870']}}"></t-switch>
</t-cell>
<t-cell title="异步操作" bordered="{{false}}">
<t-switch defaultValue="{{true}}"></t-switch>
</t-cell>
</view>

<view class="group">
<t-cell title="默认">
<t-switch bindchange="handleChange" value="{{defaultVal}}" label="描述信息"></t-switch>
</t-cell>
<t-cell title="默认关">
<t-switch defaultValue="{{false}}" label="描述信息"></t-switch>
</t-cell>
<t-cell title="自定义颜色" bordered="{{false}}">
<t-switch defaultValue="{{true}}" colors="{{['#00A870']}}" label="描述信息"></t-switch>
</t-cell>
</view>
3 changes: 3 additions & 0 deletions src/switch/_example/base/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.group {
margin-top: 24px;
}
Empty file.
3 changes: 3 additions & 0 deletions src/switch/_example/status/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"component": true
}
12 changes: 12 additions & 0 deletions src/switch/_example/status/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<t-cell title="开关">
<t-switch defaultValue="{{true}}" disabled></t-switch>
</t-cell>
<t-cell title="开关">
<t-switch defaultValue="{{false}}" disabled></t-switch>
</t-cell>
<t-cell title="开关">
<t-switch defaultValue="{{true}}" label="描述信息" disabled></t-switch>
</t-cell>
<t-cell title="开关" bordered="{{false}}">
<t-switch defaultValue="{{false}}" label="描述信息" disabled></t-switch>
</t-cell>
Empty file.
4 changes: 3 additions & 1 deletion src/switch/_example/switch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"navigationBarTitleText": "Switch",
"usingComponents": {
"t-demo": "../../components/demo-block"
"t-demo": "../../components/demo-block",
"base": "./base",
"status": "./status"
}
}
42 changes: 2 additions & 40 deletions src/switch/_example/switch.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,10 @@
<view class="demo-desc">用于控制某个功能的开启和关闭。</view>

<t-demo title="01 类型" desc="基础开关">
<view class="group">
<t-cell title="默认">
<t-switch defaultValue="{{true}}" slot="note" />
</t-cell>
<t-cell title="默认关">
<t-switch defaultValue="{{false}}" slot="note" />
</t-cell>
<t-cell title="自定义颜色">
<t-switch defaultValue="{{true}}" colors="{{['#00A870']}}" slot="note" />
</t-cell>
<t-cell title="异步操作" bordered="{{false}}">
<t-switch defaultValue="{{true}}" slot="note" />
</t-cell>
</view>

<view class="group">
<t-cell title="默认">
<t-switch bindchange="handleChange" value="{{defaultVal}}" label="描述信息" slot="note" />
</t-cell>
<t-cell title="默认关">
<t-switch defaultValue="{{false}}" label="描述信息" slot="note" />
</t-cell>
<t-cell title="自定义颜色" bordered="{{false}}">
<t-switch defaultValue="{{true}}" colors="{{['#00A870']}}" label="描述信息" slot="note" />
</t-cell>
</view>
<base />
</t-demo>

<t-demo title="02 状态" desc="开关状态">
<view class="group">
<t-cell title="开关">
<t-switch defaultValue="{{true}}" disabled slot="note" />
</t-cell>
<t-cell title="开关">
<t-switch defaultValue="{{false}}" disabled slot="note" />
</t-cell>
<t-cell title="开关">
<t-switch defaultValue="{{true}}" label="描述信息" disabled slot="note" />
</t-cell>
<t-cell title="开关" bordered="{{false}}">
<t-switch defaultValue="{{false}}" label="描述信息" disabled slot="note" />
</t-cell>
</view>
<status />
</t-demo>
</view>