-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathBaseCheckbox.vue
65 lines (65 loc) · 1.39 KB
/
BaseCheckbox.vue
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
<template>
<div class="form-check"
:class="[{disabled: disabled}, inlineClass]">
<label :for="cbId" class="form-check-label">
<input :id="cbId"
class="form-check-input"
type="checkbox"
:disabled="disabled"
v-model="model"/>
<span class="form-check-sign"></span>
<slot>
<span v-if="inline"> </span>
</slot>
</label>
</div>
</template>
<script>
export default {
name: "base-checkbox",
model: {
prop: "checked"
},
props: {
checked: {
type: [Array, Boolean],
description: "Whether checkbox is checked"
},
disabled: {
type: Boolean,
description: "Whether checkbox is disabled"
},
inline: {
type: Boolean,
description: "Whether checkbox should be inline with other checkboxes"
}
},
data() {
return {
cbId: '',
touched: false
}
},
computed: {
model: {
get() {
return this.checked
},
set(check) {
if (!this.touched) {
this.touched = true
}
this.$emit('input', check)
}
},
inlineClass() {
if (this.inline) {
return `form-check-inline`
}
}
},
created() {
this.cbId = Math.random().toString(16).slice(2)
}
}
</script>