index.vue
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
<div class="zui-checkbox" @click="onClick" :class="classRender" :style="styleRender">
<div class="zui-checkbox__icon">
<slot v-if="$slots.icon" :checked="checked"></slot>
<zui-icon v-else :class="iconClassRender" :style="iconStyleRender" :name="iconRender" :size="size" @click="onIconClick"></zui-icon>
</div>
<div v-if="$slots.default" class="zui-checkbox-label">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
name: 'Checkbox',
props: {
value: Boolean,
icon: {
type: String,
default: 'checkcircle',
},
iconChecked: {
type: String,
default: 'radiobuttonunchecked',
},
labelDisabled: Boolean,
disabled: Boolean,
color: String,
size: String,
},
data: function () {
return {
checked: this.value,
};
},
watch: {
value: function (val) {
this.checked = val;
},
},
computed: {
iconRender: function () {
return this.checked ? this.icon : this.iconChecked;
},
styleRender: function () {
return { cursor: !this.labelDisabled ? 'pointer' : '' };
},
classRender: function () {
return { disabled: this.disabled };
},
iconStyleRender: function () {
return { color: this.color && this.checked && !this.disabled ? this.color : '' };
},
iconClassRender: function () {
return { checked: this.checked && !this.disabled };
},
},
methods: {
toggle: function () {
if (!this.disabled) {
this.$emit('input', !this.checked);
}
},
onClick: function () {
if (!this.labelDisabled) {
this.toggle();
}
},
onIconClick: function () {
this.toggle();
},
},
};
</script>
<style>
@import './index.css';
</style>