mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[new feature] add SwitchCell component (#455)
This commit is contained in:
parent
eecc4bbdaa
commit
515f775e5f
23
dist/switch-cell/index.js
vendored
Normal file
23
dist/switch-cell/index.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
Component({
|
||||
options: {
|
||||
addGlobalClass: true
|
||||
},
|
||||
|
||||
properties: {
|
||||
title: String,
|
||||
checked: Boolean,
|
||||
border: Boolean,
|
||||
loading: Boolean,
|
||||
disabled: Boolean,
|
||||
size: {
|
||||
type: String,
|
||||
value: '26px'
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onChange(event) {
|
||||
this.triggerEvent('change', event.detail);
|
||||
}
|
||||
}
|
||||
});
|
7
dist/switch-cell/index.json
vendored
Normal file
7
dist/switch-cell/index.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"van-cell": "../cell/index",
|
||||
"van-switch": "../switch/index"
|
||||
}
|
||||
}
|
15
dist/switch-cell/index.wxml
vendored
Normal file
15
dist/switch-cell/index.wxml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<van-cell
|
||||
center
|
||||
title="{{ title }}"
|
||||
border="{{ border }}"
|
||||
custom-class="van-switch-cell"
|
||||
>
|
||||
<van-switch
|
||||
size="{{ size }}"
|
||||
checked="{{ checked }}"
|
||||
loading="{{ loading }}"
|
||||
disabled="{{ disabled }}"
|
||||
custom-class="van-switch-cell__switch"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell>
|
1
dist/switch-cell/index.wxss
vendored
Normal file
1
dist/switch-cell/index.wxss
vendored
Normal file
@ -0,0 +1 @@
|
||||
.van-switch-cell{padding-top:8px;padding-bottom:8px}.van-switch-cell__switch{vertical-align:middle}
|
@ -33,6 +33,7 @@ const MAP = {
|
||||
search: 'search-201808092138.png',
|
||||
steps: 'steps-201808092138.png',
|
||||
switch: 'switch-201808092138.png',
|
||||
'switch-cell': 'switch-cell-201808221124.png',
|
||||
tag: 'tag-201808092138.png',
|
||||
tabbar: 'tabbar-201808160922.png',
|
||||
toast: 'toast-201808191046.png',
|
||||
|
@ -18,6 +18,7 @@
|
||||
"pages/stepper/index",
|
||||
"pages/steps/index",
|
||||
"pages/switch/index",
|
||||
"pages/switch-cell/index",
|
||||
"pages/search/index",
|
||||
"pages/slider/index",
|
||||
"pages/tag/index",
|
||||
|
@ -105,6 +105,10 @@ export default [
|
||||
{
|
||||
groupName: '高阶组件',
|
||||
list: [
|
||||
{
|
||||
path: '/switch-cell',
|
||||
title: 'SwitchCell 开关单元格'
|
||||
},
|
||||
{
|
||||
path: '/tree-select',
|
||||
title: 'TreeSelect 分类选择'
|
||||
|
11
example/pages/switch-cell/index.js
Normal file
11
example/pages/switch-cell/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
import Page from '../../common/page';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
checked: true
|
||||
},
|
||||
|
||||
onChange(event) {
|
||||
this.setData({ checked: event.detail });
|
||||
}
|
||||
});
|
7
example/pages/switch-cell/index.json
Normal file
7
example/pages/switch-cell/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"navigationBarTitleText": "SwitchCell 开关单元格",
|
||||
"usingComponents": {
|
||||
"demo-block": "../../components/demo-block/index",
|
||||
"van-switch-cell": "../../dist/switch-cell/index"
|
||||
}
|
||||
}
|
31
example/pages/switch-cell/index.wxml
Normal file
31
example/pages/switch-cell/index.wxml
Normal file
@ -0,0 +1,31 @@
|
||||
<demo-block title="基础用法">
|
||||
<van-cell-group>
|
||||
<van-switch-cell
|
||||
title="标题"
|
||||
checked="{{ checked }}"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell-group>
|
||||
</demo-block>
|
||||
|
||||
<demo-block title="禁用状态">
|
||||
<van-cell-group>
|
||||
<van-switch-cell
|
||||
disabled
|
||||
title="标题"
|
||||
checked="{{ checked }}"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell-group>
|
||||
</demo-block>
|
||||
|
||||
<demo-block title="加载状态">
|
||||
<van-cell-group>
|
||||
<van-switch-cell
|
||||
loading
|
||||
title="标题"
|
||||
checked="{{ checked }}"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell-group>
|
||||
</demo-block>
|
@ -1,5 +0,0 @@
|
||||
|
||||
.switch-theme {
|
||||
background: #f44 !important;
|
||||
border-color: #f44 !important;
|
||||
}
|
74
packages/switch-cell/README.md
Normal file
74
packages/switch-cell/README.md
Normal file
@ -0,0 +1,74 @@
|
||||
## SwitchCell 开关单元格
|
||||
|
||||
### 使用指南
|
||||
在 index.json 中引入组件
|
||||
```json
|
||||
"usingComponents": {
|
||||
"van-switch-cell": "path/to/vant-weapp/dist/switch-cell/index"
|
||||
}
|
||||
```
|
||||
|
||||
### 代码演示
|
||||
|
||||
#### 基础用法
|
||||
|
||||
```html
|
||||
<van-switch-cell
|
||||
title="标题"
|
||||
checked="{{ checked }}"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Page({
|
||||
data: {
|
||||
checked: true
|
||||
},
|
||||
|
||||
onChange(event) {
|
||||
// 需要手动对 checked 状态进行更新
|
||||
this.setData({ checked: event.detail });
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
#### 禁用状态
|
||||
通过`disabled`属性可以将组件设置为禁用状态
|
||||
|
||||
```html
|
||||
<van-switch-cell
|
||||
disabled
|
||||
title="标题"
|
||||
checked="{{ checked }}"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
```
|
||||
|
||||
#### 加载状态
|
||||
通过`loading`属性可以将组件设置为加载状态
|
||||
|
||||
```html
|
||||
<van-switch-cell
|
||||
loading
|
||||
title="标题"
|
||||
checked="{{ checked }}"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
|-----------|-----------|-----------|-------------|
|
||||
| checked | 开关状态 | `Boolean` | - |
|
||||
| title | 左侧标题 | `String` | `''` |
|
||||
| loading | 是否为加载状态 | `Boolean` | `false` |
|
||||
| disabled | 是否为禁用状态 | `Boolean` | `false` |
|
||||
| size | 开关尺寸 | `String` | `26px` |
|
||||
|
||||
### Event
|
||||
|
||||
| 事件名 | 说明 | 参数 |
|
||||
|-----------|-----------|-----------|
|
||||
| bind:change | 开关状态切换回调 | event.detail: 是否选中开关 |
|
23
packages/switch-cell/index.js
Normal file
23
packages/switch-cell/index.js
Normal file
@ -0,0 +1,23 @@
|
||||
Component({
|
||||
options: {
|
||||
addGlobalClass: true
|
||||
},
|
||||
|
||||
properties: {
|
||||
title: String,
|
||||
checked: Boolean,
|
||||
border: Boolean,
|
||||
loading: Boolean,
|
||||
disabled: Boolean,
|
||||
size: {
|
||||
type: String,
|
||||
value: '26px'
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onChange(event) {
|
||||
this.triggerEvent('change', event.detail);
|
||||
}
|
||||
}
|
||||
});
|
7
packages/switch-cell/index.json
Normal file
7
packages/switch-cell/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"van-cell": "../cell/index",
|
||||
"van-switch": "../switch/index"
|
||||
}
|
||||
}
|
10
packages/switch-cell/index.pcss
Normal file
10
packages/switch-cell/index.pcss
Normal file
@ -0,0 +1,10 @@
|
||||
@import '../common/style/var.pcss';
|
||||
|
||||
.van-switch-cell {
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
|
||||
&__switch {
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
15
packages/switch-cell/index.wxml
Normal file
15
packages/switch-cell/index.wxml
Normal file
@ -0,0 +1,15 @@
|
||||
<van-cell
|
||||
center
|
||||
title="{{ title }}"
|
||||
border="{{ border }}"
|
||||
custom-class="van-switch-cell"
|
||||
>
|
||||
<van-switch
|
||||
size="{{ size }}"
|
||||
checked="{{ checked }}"
|
||||
loading="{{ loading }}"
|
||||
disabled="{{ disabled }}"
|
||||
custom-class="van-switch-cell__switch"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell>
|
Loading…
x
Reference in New Issue
Block a user