wedux-ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +184 -0
- package/miniprogram_dist/behaviors/formField.js +35 -0
- package/miniprogram_dist/components/avatar/avatar.js +70 -0
- package/miniprogram_dist/components/avatar/avatar.json +4 -0
- package/miniprogram_dist/components/avatar/avatar.scss +68 -0
- package/miniprogram_dist/components/avatar/avatar.wxml +15 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.js +45 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.json +7 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.scss +4 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.wxml +3 -0
- package/miniprogram_dist/components/back-top/back-top.js +68 -0
- package/miniprogram_dist/components/back-top/back-top.json +4 -0
- package/miniprogram_dist/components/back-top/back-top.scss +43 -0
- package/miniprogram_dist/components/back-top/back-top.wxml +10 -0
- package/miniprogram_dist/components/badge/badge.js +100 -0
- package/miniprogram_dist/components/badge/badge.json +4 -0
- package/miniprogram_dist/components/badge/badge.scss +98 -0
- package/miniprogram_dist/components/badge/badge.wxml +11 -0
- package/miniprogram_dist/components/button/button.js +152 -0
- package/miniprogram_dist/components/button/button.json +4 -0
- package/miniprogram_dist/components/button/button.scss +499 -0
- package/miniprogram_dist/components/button/button.wxml +21 -0
- package/miniprogram_dist/components/button-group/button-group.js +51 -0
- package/miniprogram_dist/components/button-group/button-group.json +4 -0
- package/miniprogram_dist/components/button-group/button-group.scss +8 -0
- package/miniprogram_dist/components/button-group/button-group.wxml +3 -0
- package/miniprogram_dist/components/calendar/calendar.js +308 -0
- package/miniprogram_dist/components/calendar/calendar.json +4 -0
- package/miniprogram_dist/components/calendar/calendar.scss +141 -0
- package/miniprogram_dist/components/calendar/calendar.wxml +47 -0
- package/miniprogram_dist/components/card/card.js +44 -0
- package/miniprogram_dist/components/card/card.json +4 -0
- package/miniprogram_dist/components/card/card.scss +143 -0
- package/miniprogram_dist/components/card/card.wxml +31 -0
- package/miniprogram_dist/components/checkbox/checkbox.js +43 -0
- package/miniprogram_dist/components/checkbox/checkbox.json +4 -0
- package/miniprogram_dist/components/checkbox/checkbox.scss +77 -0
- package/miniprogram_dist/components/checkbox/checkbox.wxml +13 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.js +43 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.json +4 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.scss +39 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.wxml +8 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.js +84 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.json +4 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.scss +9 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.wxml +3 -0
- package/miniprogram_dist/components/color-picker/color-picker.js +348 -0
- package/miniprogram_dist/components/color-picker/color-picker.json +7 -0
- package/miniprogram_dist/components/color-picker/color-picker.scss +383 -0
- package/miniprogram_dist/components/color-picker/color-picker.wxml +232 -0
- package/miniprogram_dist/components/date-picker/date-picker.js +1289 -0
- package/miniprogram_dist/components/date-picker/date-picker.json +7 -0
- package/miniprogram_dist/components/date-picker/date-picker.scss +468 -0
- package/miniprogram_dist/components/date-picker/date-picker.wxml +214 -0
- package/miniprogram_dist/components/divider/divider.js +34 -0
- package/miniprogram_dist/components/divider/divider.json +4 -0
- package/miniprogram_dist/components/divider/divider.scss +75 -0
- package/miniprogram_dist/components/divider/divider.wxml +8 -0
- package/miniprogram_dist/components/drawer/drawer.js +104 -0
- package/miniprogram_dist/components/drawer/drawer.json +4 -0
- package/miniprogram_dist/components/drawer/drawer.scss +171 -0
- package/miniprogram_dist/components/drawer/drawer.wxml +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.js +38 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.json +4 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.scss +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.wxml +7 -0
- package/miniprogram_dist/components/flex/flex.js +81 -0
- package/miniprogram_dist/components/flex/flex.json +4 -0
- package/miniprogram_dist/components/flex/flex.scss +4 -0
- package/miniprogram_dist/components/flex/flex.wxml +3 -0
- package/miniprogram_dist/components/float-button/float-button.js +78 -0
- package/miniprogram_dist/components/float-button/float-button.json +4 -0
- package/miniprogram_dist/components/float-button/float-button.scss +54 -0
- package/miniprogram_dist/components/float-button/float-button.wxml +9 -0
- package/miniprogram_dist/components/form/form.js +142 -0
- package/miniprogram_dist/components/form/form.json +4 -0
- package/miniprogram_dist/components/form/form.scss +11 -0
- package/miniprogram_dist/components/form/form.wxml +3 -0
- package/miniprogram_dist/components/form/validator.js +220 -0
- package/miniprogram_dist/components/form-item/form-item.js +240 -0
- package/miniprogram_dist/components/form-item/form-item.json +4 -0
- package/miniprogram_dist/components/form-item/form-item.scss +59 -0
- package/miniprogram_dist/components/form-item/form-item.wxml +33 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.js +54 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.json +4 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.scss +7 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.wxml +1 -0
- package/miniprogram_dist/components/h/h.js +60 -0
- package/miniprogram_dist/components/h/h.json +4 -0
- package/miniprogram_dist/components/h/h.scss +53 -0
- package/miniprogram_dist/components/h/h.wxml +1 -0
- package/miniprogram_dist/components/highlight/highlight.js +77 -0
- package/miniprogram_dist/components/highlight/highlight.json +4 -0
- package/miniprogram_dist/components/highlight/highlight.scss +8 -0
- package/miniprogram_dist/components/highlight/highlight.wxml +12 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.js +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.json +4 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.scss +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.wxml +12 -0
- package/miniprogram_dist/components/input/input.js +59 -0
- package/miniprogram_dist/components/input/input.json +4 -0
- package/miniprogram_dist/components/input/input.scss +96 -0
- package/miniprogram_dist/components/input/input.wxml +34 -0
- package/miniprogram_dist/components/input-otp/input-otp.js +106 -0
- package/miniprogram_dist/components/input-otp/input-otp.json +4 -0
- package/miniprogram_dist/components/input-otp/input-otp.scss +122 -0
- package/miniprogram_dist/components/input-otp/input-otp.wxml +38 -0
- package/miniprogram_dist/components/layout/layout.js +50 -0
- package/miniprogram_dist/components/layout/layout.json +4 -0
- package/miniprogram_dist/components/layout/layout.scss +10 -0
- package/miniprogram_dist/components/layout/layout.wxml +3 -0
- package/miniprogram_dist/components/layout-content/layout-content.js +47 -0
- package/miniprogram_dist/components/layout-content/layout-content.json +4 -0
- package/miniprogram_dist/components/layout-content/layout-content.scss +5 -0
- package/miniprogram_dist/components/layout-content/layout-content.wxml +13 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.js +59 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.json +4 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.scss +23 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.wxml +16 -0
- package/miniprogram_dist/components/layout-header/layout-header.js +59 -0
- package/miniprogram_dist/components/layout-header/layout-header.json +4 -0
- package/miniprogram_dist/components/layout-header/layout-header.scss +23 -0
- package/miniprogram_dist/components/layout-header/layout-header.wxml +16 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.js +48 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.json +4 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.scss +13 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.wxml +5 -0
- package/miniprogram_dist/components/list/list.js +55 -0
- package/miniprogram_dist/components/list/list.json +4 -0
- package/miniprogram_dist/components/list/list.scss +51 -0
- package/miniprogram_dist/components/list/list.wxml +9 -0
- package/miniprogram_dist/components/list-item/list-item.js +24 -0
- package/miniprogram_dist/components/list-item/list-item.json +4 -0
- package/miniprogram_dist/components/list-item/list-item.scss +51 -0
- package/miniprogram_dist/components/list-item/list-item.wxml +14 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.js +77 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.json +4 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.scss +63 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.wxml +35 -0
- package/miniprogram_dist/components/number-animation/number-animation.js +124 -0
- package/miniprogram_dist/components/number-animation/number-animation.json +4 -0
- package/miniprogram_dist/components/number-animation/number-animation.scss +3 -0
- package/miniprogram_dist/components/number-animation/number-animation.wxml +1 -0
- package/miniprogram_dist/components/popover/popover.js +183 -0
- package/miniprogram_dist/components/popover/popover.json +4 -0
- package/miniprogram_dist/components/popover/popover.scss +69 -0
- package/miniprogram_dist/components/popover/popover.wxml +19 -0
- package/miniprogram_dist/components/qr-code/qr-code.js +216 -0
- package/miniprogram_dist/components/qr-code/qr-code.json +4 -0
- package/miniprogram_dist/components/qr-code/qr-code.scss +8 -0
- package/miniprogram_dist/components/qr-code/qr-code.wxml +16 -0
- package/miniprogram_dist/components/radio/radio.js +38 -0
- package/miniprogram_dist/components/radio/radio.json +4 -0
- package/miniprogram_dist/components/radio/radio.scss +50 -0
- package/miniprogram_dist/components/radio/radio.wxml +12 -0
- package/miniprogram_dist/components/radio-button/radio-button.js +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.json +4 -0
- package/miniprogram_dist/components/radio-button/radio-button.scss +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.wxml +8 -0
- package/miniprogram_dist/components/radio-group/radio-group.js +72 -0
- package/miniprogram_dist/components/radio-group/radio-group.json +4 -0
- package/miniprogram_dist/components/radio-group/radio-group.scss +9 -0
- package/miniprogram_dist/components/radio-group/radio-group.wxml +3 -0
- package/miniprogram_dist/components/rate/rate.js +90 -0
- package/miniprogram_dist/components/rate/rate.json +4 -0
- package/miniprogram_dist/components/rate/rate.scss +59 -0
- package/miniprogram_dist/components/rate/rate.wxml +16 -0
- package/miniprogram_dist/components/select/select.js +201 -0
- package/miniprogram_dist/components/select/select.json +7 -0
- package/miniprogram_dist/components/select/select.scss +235 -0
- package/miniprogram_dist/components/select/select.wxml +79 -0
- package/miniprogram_dist/components/stepper/stepper.js +113 -0
- package/miniprogram_dist/components/stepper/stepper.json +4 -0
- package/miniprogram_dist/components/stepper/stepper.scss +73 -0
- package/miniprogram_dist/components/stepper/stepper.wxml +23 -0
- package/miniprogram_dist/components/switch/switch.js +42 -0
- package/miniprogram_dist/components/switch/switch.json +4 -0
- package/miniprogram_dist/components/switch/switch.scss +77 -0
- package/miniprogram_dist/components/switch/switch.wxml +10 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.js +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.json +4 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.scss +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.wxml +12 -0
- package/miniprogram_dist/components/tag/tag.js +87 -0
- package/miniprogram_dist/components/tag/tag.json +4 -0
- package/miniprogram_dist/components/tag/tag.scss +138 -0
- package/miniprogram_dist/components/tag/tag.wxml +12 -0
- package/miniprogram_dist/components/textarea/textarea.js +46 -0
- package/miniprogram_dist/components/textarea/textarea.json +4 -0
- package/miniprogram_dist/components/textarea/textarea.scss +51 -0
- package/miniprogram_dist/components/textarea/textarea.wxml +20 -0
- package/miniprogram_dist/components/theme-provider/presets.js +101 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.js +34 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.json +4 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.scss +3 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.wxml +3 -0
- package/miniprogram_dist/components/time-picker/time-picker.js +136 -0
- package/miniprogram_dist/components/time-picker/time-picker.json +7 -0
- package/miniprogram_dist/components/time-picker/time-picker.scss +135 -0
- package/miniprogram_dist/components/time-picker/time-picker.wxml +47 -0
- package/miniprogram_dist/components/tooltip/tooltip.js +179 -0
- package/miniprogram_dist/components/tooltip/tooltip.json +4 -0
- package/miniprogram_dist/components/tooltip/tooltip.scss +66 -0
- package/miniprogram_dist/components/tooltip/tooltip.wxml +17 -0
- package/miniprogram_dist/components/tree/tree.js +647 -0
- package/miniprogram_dist/components/tree/tree.json +4 -0
- package/miniprogram_dist/components/tree/tree.scss +178 -0
- package/miniprogram_dist/components/tree/tree.wxml +59 -0
- package/miniprogram_dist/components/tree-select/tree-select.js +260 -0
- package/miniprogram_dist/components/tree-select/tree-select.json +8 -0
- package/miniprogram_dist/components/tree-select/tree-select.scss +250 -0
- package/miniprogram_dist/components/tree-select/tree-select.wxml +118 -0
- package/miniprogram_dist/components/upload/upload.js +387 -0
- package/miniprogram_dist/components/upload/upload.json +4 -0
- package/miniprogram_dist/components/upload/upload.scss +258 -0
- package/miniprogram_dist/components/upload/upload.wxml +142 -0
- package/miniprogram_dist/components/watermark/watermark.js +260 -0
- package/miniprogram_dist/components/watermark/watermark.json +4 -0
- package/miniprogram_dist/components/watermark/watermark.scss +35 -0
- package/miniprogram_dist/components/watermark/watermark.wxml +13 -0
- package/miniprogram_dist/libs/qrcodegen.js +714 -0
- package/miniprogram_dist/libs/seemly.min.js +547 -0
- package/miniprogram_dist/libs/tempo_1_0_0.js +1264 -0
- package/miniprogram_dist/libs/validator_13_56_26.min.js +5282 -0
- package/miniprogram_dist/styles/demo.scss +96 -0
- package/miniprogram_dist/styles/iconfont.scss +91 -0
- package/miniprogram_dist/styles/theme.scss +126 -0
- package/miniprogram_dist/styles/tokens.scss +292 -0
- package/miniprogram_dist/utils/relations.js +21 -0
- package/package.json +25 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<view
|
|
2
|
+
class="w-card w-card--{{size}} {{bordered ? 'w-card--bordered' : ''}} {{hoverable ? 'w-card--hoverable' : ''}} {{segmented ? 'w-card--segmented' : ''}}"
|
|
3
|
+
hover-class="{{hoverable ? 'w-card--pressed' : 'none'}}"
|
|
4
|
+
hover-stay-time="100"
|
|
5
|
+
bindtap="handleTap"
|
|
6
|
+
>
|
|
7
|
+
<view class="w-card__cover">
|
|
8
|
+
<view class="w-card__cover-inner">
|
|
9
|
+
<slot name="cover"></slot>
|
|
10
|
+
</view>
|
|
11
|
+
</view>
|
|
12
|
+
|
|
13
|
+
<view wx:if="{{title}}" class="w-card__header">
|
|
14
|
+
<view class="w-card__header-main">{{title}}</view>
|
|
15
|
+
<view class="w-card__header-extra">
|
|
16
|
+
<slot name="header-extra"></slot>
|
|
17
|
+
</view>
|
|
18
|
+
</view>
|
|
19
|
+
|
|
20
|
+
<view class="w-card__body {{_hasHeader ? 'w-card__body--no-top-pad' : ''}}">
|
|
21
|
+
<slot></slot>
|
|
22
|
+
</view>
|
|
23
|
+
|
|
24
|
+
<view class="w-card__footer">
|
|
25
|
+
<slot name="footer"></slot>
|
|
26
|
+
</view>
|
|
27
|
+
|
|
28
|
+
<view class="w-card__action">
|
|
29
|
+
<slot name="action"></slot>
|
|
30
|
+
</view>
|
|
31
|
+
</view>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Component({
|
|
2
|
+
relations: {
|
|
3
|
+
'../checkbox-group/checkbox-group': {
|
|
4
|
+
type: 'ancestor',
|
|
5
|
+
},
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
properties: {
|
|
9
|
+
value: { type: null, value: '' },
|
|
10
|
+
disabled: { type: Boolean, value: false },
|
|
11
|
+
label: { type: String, value: '' },
|
|
12
|
+
indeterminate: { type: Boolean, value: false },
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
data: {
|
|
16
|
+
_groupSize: '',
|
|
17
|
+
_groupDisabled: false,
|
|
18
|
+
_checked: false,
|
|
19
|
+
_maxReached: false,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
methods: {
|
|
23
|
+
_setGroupContext(ctx) {
|
|
24
|
+
const checked = (ctx.currentValues || []).indexOf(this.data.value) >= 0;
|
|
25
|
+
const maxReached = ctx.max > 0 && (ctx.currentValues || []).length >= ctx.max && !checked;
|
|
26
|
+
this.setData({
|
|
27
|
+
_groupSize: ctx.size || '',
|
|
28
|
+
_groupDisabled: ctx.disabled || false,
|
|
29
|
+
_checked: checked,
|
|
30
|
+
_maxReached: maxReached,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
handleTap() {
|
|
35
|
+
if (this.data.disabled || this.data._groupDisabled) return;
|
|
36
|
+
if (this.data._maxReached && !this.data._checked) return;
|
|
37
|
+
const parent = this.getRelationNodes('../checkbox-group/checkbox-group');
|
|
38
|
+
if (parent && parent.length > 0) {
|
|
39
|
+
parent[0]._handleChildChange(this.data.value, !this.data._checked);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
.w-checkbox {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: var(--spacing-sm);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.w-checkbox__box {
|
|
8
|
+
width: var(--size-checkbox);
|
|
9
|
+
height: var(--size-checkbox);
|
|
10
|
+
border-radius: var(--radius-sm);
|
|
11
|
+
border: 2rpx solid var(--color-separator);
|
|
12
|
+
position: relative;
|
|
13
|
+
flex-shrink: 0;
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
transition:
|
|
16
|
+
background-color 0.2s,
|
|
17
|
+
border-color 0.2s;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.w-checkbox--checked .w-checkbox__box {
|
|
21
|
+
background: var(--color-checkbox-checked);
|
|
22
|
+
border-color: var(--color-checkbox-checked);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.w-checkbox--indeterminate .w-checkbox__box {
|
|
26
|
+
background: var(--color-checkbox-checked);
|
|
27
|
+
border-color: var(--color-checkbox-checked);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.w-checkbox__check {
|
|
31
|
+
position: absolute;
|
|
32
|
+
top: 50%;
|
|
33
|
+
left: 50%;
|
|
34
|
+
width: 20rpx;
|
|
35
|
+
height: 12rpx;
|
|
36
|
+
border-left: 3rpx solid transparent;
|
|
37
|
+
border-bottom: 3rpx solid transparent;
|
|
38
|
+
transform: translate(-50%, -50%) rotate(-45deg);
|
|
39
|
+
margin-top: -2rpx;
|
|
40
|
+
transition: border-color 0.2s;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.w-checkbox--checked .w-checkbox__check {
|
|
44
|
+
border-left-color: var(--color-checkbox-check);
|
|
45
|
+
border-bottom-color: var(--color-checkbox-check);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.w-checkbox__indeterminate {
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: 50%;
|
|
51
|
+
left: 50%;
|
|
52
|
+
transform: translate(-50%, -50%);
|
|
53
|
+
width: 18rpx;
|
|
54
|
+
height: 3rpx;
|
|
55
|
+
background: transparent;
|
|
56
|
+
border-radius: 2rpx;
|
|
57
|
+
transition: background-color 0.2s;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.w-checkbox--indeterminate .w-checkbox__indeterminate {
|
|
61
|
+
background: var(--color-checkbox-check);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.w-checkbox__label {
|
|
65
|
+
font-size: var(--font-size-md);
|
|
66
|
+
color: var(--color-text-primary);
|
|
67
|
+
line-height: 1.4;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.w-checkbox--size-small .w-checkbox__label {
|
|
71
|
+
font-size: var(--font-size-sm);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.w-checkbox--disabled {
|
|
75
|
+
opacity: 0.4;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<view
|
|
2
|
+
class="w-checkbox {{_checked ? 'w-checkbox--checked' : ''}} {{indeterminate ? 'w-checkbox--indeterminate' : ''}} {{(disabled || _groupDisabled || _maxReached) ? 'w-checkbox--disabled' : ''}} w-checkbox--size-{{_groupSize || 'medium'}}"
|
|
3
|
+
bindtap="handleTap"
|
|
4
|
+
>
|
|
5
|
+
<view class="w-checkbox__box">
|
|
6
|
+
<view wx:if="{{indeterminate}}" class="w-checkbox__indeterminate"></view>
|
|
7
|
+
<view wx:else class="w-checkbox__check"></view>
|
|
8
|
+
</view>
|
|
9
|
+
<view class="w-checkbox__label">
|
|
10
|
+
<text wx:if="{{label}}">{{label}}</text>
|
|
11
|
+
<slot wx:else></slot>
|
|
12
|
+
</view>
|
|
13
|
+
</view>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Component({
|
|
2
|
+
relations: {
|
|
3
|
+
'../checkbox-group/checkbox-group': {
|
|
4
|
+
type: 'ancestor',
|
|
5
|
+
},
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
properties: {
|
|
9
|
+
value: { type: null, value: '' },
|
|
10
|
+
disabled: { type: Boolean, value: false },
|
|
11
|
+
label: { type: String, value: '' },
|
|
12
|
+
round: { type: Boolean, value: false },
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
data: {
|
|
16
|
+
_groupSize: '',
|
|
17
|
+
_groupDisabled: false,
|
|
18
|
+
_checked: false,
|
|
19
|
+
_maxReached: false,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
methods: {
|
|
23
|
+
_setGroupContext(ctx) {
|
|
24
|
+
const checked = (ctx.currentValues || []).indexOf(this.data.value) >= 0;
|
|
25
|
+
const maxReached = ctx.max > 0 && (ctx.currentValues || []).length >= ctx.max && !checked;
|
|
26
|
+
this.setData({
|
|
27
|
+
_groupSize: ctx.size || '',
|
|
28
|
+
_groupDisabled: ctx.disabled || false,
|
|
29
|
+
_checked: checked,
|
|
30
|
+
_maxReached: maxReached,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
handleTap() {
|
|
35
|
+
if (this.data.disabled || this.data._groupDisabled) return;
|
|
36
|
+
if (this.data._maxReached && !this.data._checked) return;
|
|
37
|
+
const parent = this.getRelationNodes('../checkbox-group/checkbox-group');
|
|
38
|
+
if (parent && parent.length > 0) {
|
|
39
|
+
parent[0]._handleChildChange(this.data.value, !this.data._checked);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
.w-checkbox-button {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
border-radius: var(--radius-md);
|
|
6
|
+
background: var(--color-bg-base);
|
|
7
|
+
color: var(--color-text-primary);
|
|
8
|
+
font-size: var(--font-size-md);
|
|
9
|
+
line-height: 1;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
transition:
|
|
12
|
+
background 0.2s,
|
|
13
|
+
color 0.2s;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.w-checkbox-button--size-medium {
|
|
17
|
+
height: var(--size-tag-height-lg);
|
|
18
|
+
padding: 0 var(--spacing-lg);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.w-checkbox-button--size-small {
|
|
22
|
+
height: var(--size-tag-height-md);
|
|
23
|
+
padding: 0 var(--spacing-md);
|
|
24
|
+
font-size: var(--font-size-sm);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.w-checkbox-button--checked {
|
|
28
|
+
background: var(--color-brand);
|
|
29
|
+
color: var(--color-text-anti);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.w-checkbox-button--round {
|
|
33
|
+
border-radius: var(--radius-full);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.w-checkbox-button--disabled {
|
|
37
|
+
opacity: 0.4;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<view
|
|
2
|
+
class="w-checkbox-button {{_checked ? 'w-checkbox-button--checked' : ''}} {{(disabled || _groupDisabled || _maxReached) ? 'w-checkbox-button--disabled' : ''}} w-checkbox-button--size-{{_groupSize || 'medium'}} {{round ? 'w-checkbox-button--round' : ''}}"
|
|
3
|
+
hover-class="none"
|
|
4
|
+
bindtap="handleTap"
|
|
5
|
+
>
|
|
6
|
+
<text wx:if="{{label}}">{{label}}</text>
|
|
7
|
+
<slot wx:else></slot>
|
|
8
|
+
</view>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const formField = require('../../behaviors/formField');
|
|
2
|
+
|
|
3
|
+
Component({
|
|
4
|
+
behaviors: ['wx://form-field', formField],
|
|
5
|
+
|
|
6
|
+
relations: {
|
|
7
|
+
'../form-item/form-item': {
|
|
8
|
+
type: 'ancestor',
|
|
9
|
+
},
|
|
10
|
+
'../checkbox/checkbox': {
|
|
11
|
+
type: 'descendant',
|
|
12
|
+
linked() {
|
|
13
|
+
this._updateChildren();
|
|
14
|
+
},
|
|
15
|
+
linkChanged() {
|
|
16
|
+
this._updateChildren();
|
|
17
|
+
},
|
|
18
|
+
unlinked() {
|
|
19
|
+
this._updateChildren();
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
'../checkbox-button/checkbox-button': {
|
|
23
|
+
type: 'descendant',
|
|
24
|
+
linked() {
|
|
25
|
+
this._updateChildren();
|
|
26
|
+
},
|
|
27
|
+
linkChanged() {
|
|
28
|
+
this._updateChildren();
|
|
29
|
+
},
|
|
30
|
+
unlinked() {
|
|
31
|
+
this._updateChildren();
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
properties: {
|
|
37
|
+
value: { type: Array, value: [] },
|
|
38
|
+
disabled: { type: Boolean, value: false },
|
|
39
|
+
size: { type: String, value: '' },
|
|
40
|
+
vertical: { type: Boolean, value: false },
|
|
41
|
+
max: { type: Number, value: 0 },
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
data: {},
|
|
45
|
+
|
|
46
|
+
observers: {
|
|
47
|
+
'value, disabled, size, max, _formItemSize, _formItemDisabled'() {
|
|
48
|
+
this._updateChildren();
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
methods: {
|
|
53
|
+
_updateChildren() {
|
|
54
|
+
const checkboxes = this.getRelationNodes('../checkbox/checkbox') || [];
|
|
55
|
+
const checkboxButtons = this.getRelationNodes('../checkbox-button/checkbox-button') || [];
|
|
56
|
+
const children = [...checkboxes, ...checkboxButtons];
|
|
57
|
+
if (!children.length) return;
|
|
58
|
+
const ctx = {
|
|
59
|
+
size: this.data.size || this.data._formItemSize,
|
|
60
|
+
disabled: this.data.disabled || this.data._formItemDisabled,
|
|
61
|
+
currentValues: this.data.value || [],
|
|
62
|
+
max: this.data.max,
|
|
63
|
+
};
|
|
64
|
+
children.forEach((child) => {
|
|
65
|
+
child._setGroupContext(ctx);
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
_handleChildChange(childValue, checked) {
|
|
70
|
+
const values = (this.data.value || []).slice();
|
|
71
|
+
if (checked) {
|
|
72
|
+
if (this.data.max > 0 && values.length >= this.data.max) return;
|
|
73
|
+
if (values.indexOf(childValue) === -1) {
|
|
74
|
+
values.push(childValue);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
const idx = values.indexOf(childValue);
|
|
78
|
+
if (idx >= 0) values.splice(idx, 1);
|
|
79
|
+
}
|
|
80
|
+
this.triggerEvent('update:value', { value: values });
|
|
81
|
+
this._notifyChange();
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|