Skip to content

Commit 19773e2

Browse files
jerrynipangxie1991
authored andcommitted
[new feature] Checkbox: 新增 checkbox 组件 (youzan#341)
* [new feature] Checkbox: init demo * [new component]: Checkbox refactor * [new component] Checkbox fix youzan#231 * fix: youzan#231
1 parent 4599412 commit 19773e2

16 files changed

Lines changed: 330 additions & 0 deletions

File tree

doc.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = {
5454
base: 'form',
5555
label: '表单',
5656
include: {
57+
checkbox: require('./packages/checkbox/README.md'),
5758
field: require('./packages/field/README.md'),
5859
search: require('./packages/search/README.md'),
5960
select: require('./packages/select/README.md'),

example/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"pages/dashboard/index",
44
"pages/actionsheet/index",
55
"pages/btn/index",
6+
"pages/checkbox/index",
67
"pages/badge/index",
78
"pages/capsule/index",
89
"pages/card/index",

example/pages/checkbox/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Zan = require('../../dist/index');
2+
3+
Page({
4+
5+
data: {
6+
items: [
7+
{value: 'a'},
8+
{value: 'b', checked: true},
9+
{value: 'c'},
10+
]
11+
},
12+
13+
handleCheckboxChange: function(e) {
14+
console.log('checkbox发生change事件,携带value值为:', e.detail)
15+
console.log('items:', this.data.items)
16+
}
17+
});

example/pages/checkbox/index.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"navigationBarTitleText": "Checkbox 选择",
3+
"usingComponents": {
4+
"zan-checkbox-group": "../../dist/checkbox-group/index",
5+
"zan-checkbox": "../../dist/checkbox/index",
6+
"zan-panel": "../../dist/panel/index",
7+
"zan-cell": "../../dist/cell/index",
8+
"doc-page": "../../components/doc-page/index"
9+
}
10+
}

example/pages/checkbox/index.wxml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<doc-page title="checkbox" without-padding>
2+
<zan-panel title='基本用法'>
3+
<zan-checkbox
4+
checkbox-class="checkbox-demo"
5+
bindchange="handleCheckboxChange"
6+
>复选框</zan-checkbox>
7+
</zan-panel>
8+
9+
<zan-panel title='禁用状态'>
10+
<zan-checkbox
11+
checkbox-class="checkbox-demo"
12+
disabled
13+
checked="{{ true }}"
14+
>复选框</zan-checkbox>
15+
</zan-panel>
16+
17+
<zan-panel title='禁用内容部分点击事件'>
18+
<zan-checkbox
19+
checkbox-class="checkbox-demo"
20+
label-disabled
21+
>复选框</zan-checkbox>
22+
</zan-panel>
23+
24+
<zan-panel title='Checkbox组'>
25+
<zan-checkbox-group>
26+
<zan-checkbox
27+
wx:for="{{ items }}"
28+
wx:for-item="item"
29+
wx:for-index="index"
30+
wx:key="{{ value }}"
31+
checked="{{ item.checked }}"
32+
data-index="{{ index }}"
33+
bindchange="handleCheckboxChange"
34+
>复选框 {{ item.value }}</zan-checkbox>
35+
</zan-checkbox-group>
36+
</zan-panel>
37+
38+
<zan-panel title='列表模式'>
39+
<zan-checkbox type="list">复选框 a</zan-checkbox>
40+
<zan-checkbox type="list">复选框 b</zan-checkbox>
41+
<zan-checkbox type="list">复选框 c</zan-checkbox>
42+
</zan-panel>
43+
</doc-page>

example/pages/checkbox/index.wxss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.checkbox-demo {
2+
display: block;
3+
margin: 15px 0;
4+
}

example/pages/dashboard/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export default {
1717
}, {
1818
name: 'Cell 单元格',
1919
path: '/pages/cell/index'
20+
}, {
21+
name: 'Checkbox 复选框',
22+
path: '/pages/checkbox/index'
2023
}, {
2124
name: 'Helper 基础样式',
2225
path: '/pages/helper/index'

packages/checkbox-group/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const CHECKBOX_PATH = '../checkbox/index';
2+
3+
Component({
4+
relations: {
5+
[CHECKBOX_PATH]: {
6+
type: 'child',
7+
linked() {
8+
this.updateChildren(CHECKBOX_PATH);
9+
}
10+
}
11+
},
12+
13+
data: {
14+
elementUpdateTimeout: 0
15+
},
16+
17+
methods: {
18+
updateChildren(childPath) { // 把checkbox标记为在group中,设置不同样式
19+
let elements = this.getRelationNodes(childPath);
20+
21+
elements.forEach((checkbox, index) => {
22+
checkbox.updateData({ isInGroup: true});
23+
});
24+
}
25+
}
26+
});

packages/checkbox-group/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"component": true
3+
}

packages/checkbox-group/index.pcss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.checkbox-group {
2+
padding-bottom: 10px;
3+
background-color: #fff;
4+
}
5+
.checkbox-group .zan-checkbox {
6+
margin-top: 10px;
7+
}

0 commit comments

Comments
 (0)