Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 5873956

Browse files
committed
feat(ui/checkbox): add component checkbox
1 parent 1633586 commit 5873956

File tree

32 files changed

+1842
-196
lines changed

32 files changed

+1842
-196
lines changed

packages/varlet-vue2-ui/docs/cli.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Intro
44

5-
The out-of-the-box `Vue3 component library` rapid prototyping tool provides a series of commands and tools to solve the problem of component library development
5+
The out-of-the-box `Vue2 component library` rapid prototyping tool provides a series of commands and tools to solve the problem of component library development
66

77
### Feature
88

packages/varlet-vue2-ui/docs/cli.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### 介绍
44

5-
开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题
5+
开箱即用的 `Vue2组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题
66

77
### 特性
88

packages/varlet-vue2-ui/docs/home.en-US.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div class="varlet-introduce">
22
<div class="varlet-introduce__row">
33
<img class="varlet-introduce__image" src="https://varlet.gitee.io/varlet-ui/varlet_icon.png" />
4-
<div class="varlet-introduce__name">VARLET</div>
4+
<div class="varlet-introduce__name">VARLET-VUE2</div>
55
</div>
6-
<div class="varlet-introduce__des">Material design mobile component library for Vue3</div>
6+
<div class="varlet-introduce__des">Material design mobile component library for Vue2</div>
77
</div>
88

99
### Intro
1010

11-
Varlet is a Material design mobile component library developed based on `Vue3`, developed and maintained by partners in the community.
11+
Varlet is a Material design mobile component library developed based on `Vue2`, developed and maintained by partners in the community.
1212

1313
### Features
1414
- 1.Provide more than 50 high quality general purpose components

packages/varlet-vue2-ui/docs/home.zh-CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div class="varlet-introduce">
22
<div class="varlet-introduce__row">
33
<img class="varlet-introduce__image" src="https://varlet.gitee.io/varlet-ui/varlet_icon.png" />
4-
<div class="varlet-introduce__name">VARLET</div>
4+
<div class="varlet-introduce__name">VARLET-VUE2</div>
55
</div>
6-
<div class="varlet-introduce__des">面向 Vue3 的 Material 风格移动端组件库</div>
6+
<div class="varlet-introduce__des">面向 Vue2 的 Material 风格移动端组件库</div>
77
</div>
88

99
### 介绍
1010

11-
Varlet 是一个基于 `Vue3` 开发的 Material 风格移动端组件库,全面拥抱 `Vue3` 生态,由社区的小伙伴开发和维护。
11+
Varlet 是一个基于 `Vue2` 开发的 Material 风格移动端组件库,全面拥抱 `Vue2` 生态,由社区的小伙伴开发和维护。
1212

1313
### 特性
1414
- 1.提供 50个 高质量通用组件

packages/varlet-vue2-ui/src/badge/badge.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
transition: opacity 0.15s var(--cubic-bezier);
113113
}
114114

115-
&-fade-enter-from,
115+
&-fade-enter,
116116
&-fade-leave-to {
117117
opacity: 0;
118118
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<template>
2+
<div class="var-checkbox-group__wrap">
3+
<div class="var-checkbox-group" :class="[`var-checkbox-group--${direction}`]">
4+
<slot />
5+
</div>
6+
<var-form-details :error-message="errorMessage" />
7+
</div>
8+
</template>
9+
10+
<script>
11+
import VarFormDetails from '../form-details'
12+
import { defineComponent } from '../utils/create'
13+
import { props } from './props'
14+
import { uniq } from '../utils/shared'
15+
import { ValidationMixin } from '../utils/mixins/validation'
16+
import { createParentMixin, createChildrenMixin } from '../utils/mixins/relation'
17+
18+
export default defineComponent({
19+
name: 'VarCheckboxGroup',
20+
21+
components: { VarFormDetails },
22+
23+
mixins: [
24+
ValidationMixin,
25+
createParentMixin('checkboxGroup', { childrenKey: 'checkboxes' }),
26+
createChildrenMixin('form', { parentKey: 'form', childrenKey: 'formItems' }),
27+
],
28+
29+
props,
30+
31+
computed: {
32+
checkedCount() {
33+
return this.value.length
34+
},
35+
36+
checkboxGroupErrorMessage() {
37+
return this.errorMessage
38+
},
39+
},
40+
41+
watch: {
42+
value: {
43+
handler() {
44+
this.syncCheckboxes()
45+
},
46+
deep: true,
47+
},
48+
49+
checkboxes() {
50+
this.syncCheckboxes()
51+
},
52+
},
53+
54+
methods: {
55+
// expose
56+
checkAll() {
57+
const checkedValues = this.checkboxes.map(({ checkedValue }) => checkedValue)
58+
this.resetWithAnimation()
59+
const changedModelValue = uniq(checkedValues)
60+
61+
this.getListeners().onInput?.(changedModelValue)
62+
63+
return changedModelValue
64+
},
65+
66+
// expose
67+
inverseAll() {
68+
const checkedValues = this.checkboxes?.filter(({ checked }) => !checked).map(({ checkedValue }) => checkedValue)
69+
this.resetWithAnimation()
70+
const changedModelValue = uniq(checkedValues)
71+
72+
this.getListeners().onInput?.(changedModelValue)
73+
74+
return changedModelValue
75+
},
76+
77+
// expose
78+
reset() {
79+
this.getListeners().onInput?.([])
80+
this.resetValidation()
81+
},
82+
83+
// expose
84+
validate() {
85+
this._validate(this.rules, this.value)
86+
},
87+
88+
resetWithAnimation() {
89+
this.checkboxes.forEach((checkbox) => {
90+
checkbox.withAnimation = false
91+
})
92+
},
93+
94+
validateWithTrigger(trigger) {
95+
this.$nextTick(() => {
96+
const { validateTrigger, rules, value } = this
97+
this._validateWithTrigger(validateTrigger, trigger, rules, value)
98+
})
99+
},
100+
101+
change(changedValue) {
102+
this.getListeners().onInput?.(changedValue)
103+
this.getListeners().onChange?.(changedValue)
104+
this.validateWithTrigger('onChange')
105+
},
106+
107+
onChecked(changedValue) {
108+
const { value } = this
109+
110+
if (!value.includes(changedValue)) {
111+
this.change([...value, changedValue])
112+
}
113+
},
114+
115+
onUnchecked(changedValue) {
116+
if (!this.value.includes(changedValue)) {
117+
return
118+
}
119+
120+
this.change(this.value?.filter((value) => value !== changedValue))
121+
},
122+
123+
syncCheckboxes() {
124+
this.checkboxes?.forEach(({ sync }) => {
125+
sync(this.value)
126+
})
127+
},
128+
},
129+
})
130+
</script>
131+
132+
<style lang="less">
133+
@import '../styles/common';
134+
@import '../form-details/formDetails';
135+
@import './checkboxGroup';
136+
</style>

0 commit comments

Comments
 (0)