forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadioGroup.vue
executable file
·104 lines (97 loc) · 2.4 KB
/
RadioGroup.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<template>
<a17-inputframe :error="error" :note="note" :label="label" :name="name" :label-for="uniqId">
<ul class="radioGroup" :class="radioClasses">
<li class="radioGroup__item"
v-for="(radio, index) in radios"
:key="index">
<a17-radio :customClass="'radio__' + radioClass + '--' + (index + 1)"
:name="name"
:value="radio.value"
:label="radio.label"
:initialValue="currentValue"
:disabled="radio.disabled"
@change="changeValue"/>
</li>
</ul>
</a17-inputframe>
</template>
<script>
import randKeyMixin from '@/mixins/randKey'
import InputframeMixin from '@/mixins/inputFrame'
import FormStoreMixin from '@/mixins/formStore'
export default {
name: 'A17CheckboxGroup',
mixins: [randKeyMixin, InputframeMixin, FormStoreMixin],
props: {
radioClass: {
type: String,
default: ''
},
inline: {
type: Boolean,
default: false
},
name: {
type: String,
default: ''
},
label: {
default: ''
},
initialValue: {
default: ''
},
radios: {
default: function () { return [] }
}
},
data: function () {
return {
currentValue: this.initialValue
}
},
computed: {
uniqId: function (value) {
return this.name + '-' + this.randKey
},
radioClasses: function () {
return [
this.inline ? 'radioGroup--inline' : ''
]
}
},
methods: {
updateFromStore: function (newValue) { // called from the formStore mixin
if (newValue !== this.currentValue) {
this.updateValue(newValue)
}
},
updateValue: function (newValue) {
this.currentValue = newValue
},
changeValue: function (newValue) {
if (newValue !== this.currentValue) {
this.updateValue(newValue)
this.$emit('change', this.currentValue)
this.saveIntoStore(newValue)
}
}
}
}
</script>
<style lang="scss" scoped>
.radioGroup {
color: $color__text;
}
.radioGroup--inline {
display: flex;
flex-flow: row wrap;
overflow: hidden;
}
.radioGroup--inline .radioGroup__item {
margin-right: 20px;
}
.radioGroup__item {
padding: 7px 0 8px 0;
}
</style>