Skip to content

Commit

Permalink
Merge pull request #615 from wangyuan0108/docs/switch
Browse files Browse the repository at this point in the history
Docs/switch
  • Loading branch information
LeeJim authored Jul 16, 2022
2 parents 2064964 + f4ba3b7 commit e0b19e4
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 45 deletions.
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>

0 comments on commit e0b19e4

Please sign in to comment.