@farm-investimentos/front-mfe-components 11.8.4 → 11.9.1
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/dist/front-mfe-components.common.js +217 -225
- package/dist/front-mfe-components.common.js.map +1 -1
- package/dist/front-mfe-components.css +1 -1
- package/dist/front-mfe-components.umd.js +217 -225
- package/dist/front-mfe-components.umd.js.map +1 -1
- package/dist/front-mfe-components.umd.min.js +1 -1
- package/dist/front-mfe-components.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.scss +4 -0
- package/src/components/Checkbox/Checkbox.stories.js +12 -9
- package/src/components/Checkbox/Checkbox.vue +30 -6
- package/src/components/Form/Form.stories.js +43 -37
- package/src/components/Logos/OriginatorLogo/OriginatorLogo.vue +1 -1
- package/src/components/Logos/ProductLogo/ProductLogo.vue +1 -1
- package/src/components/Radio/Radio.vue +1 -1
- package/src/components/RadioGroup/RadioGroup.stories.js +35 -44
- package/src/components/RadioGroup/RadioGroup.vue +47 -57
- package/src/components/RadioGroup/IRadioGroup.ts +0 -6
- package/src/components/RadioGroup/RadioGroup.scss +0 -108
package/package.json
CHANGED
|
@@ -23,22 +23,24 @@ export default {
|
|
|
23
23
|
export const Primary = () => ({
|
|
24
24
|
data() {
|
|
25
25
|
return {
|
|
26
|
-
isChecked:
|
|
26
|
+
isChecked: null,
|
|
27
27
|
};
|
|
28
28
|
},
|
|
29
29
|
template: `<div>
|
|
30
|
-
<farm-checkbox v-model="isChecked" />
|
|
30
|
+
<farm-checkbox v-model="isChecked" value="1" />
|
|
31
|
+
isChecked (value): {{ isChecked }}
|
|
31
32
|
</div>`,
|
|
32
33
|
});
|
|
33
34
|
|
|
34
|
-
export const
|
|
35
|
+
export const DefaultCheck = () => ({
|
|
35
36
|
data() {
|
|
36
37
|
return {
|
|
37
38
|
isChecked: true,
|
|
38
39
|
};
|
|
39
40
|
},
|
|
40
41
|
template: `<div>
|
|
41
|
-
<farm-checkbox v-model="isChecked" />
|
|
42
|
+
<farm-checkbox v-model="isChecked" :value="true" />
|
|
43
|
+
isChecked (value): {{ isChecked }}
|
|
42
44
|
</div>`,
|
|
43
45
|
});
|
|
44
46
|
|
|
@@ -49,7 +51,7 @@ export const WithLabel = () => ({
|
|
|
49
51
|
};
|
|
50
52
|
},
|
|
51
53
|
template: `<div>
|
|
52
|
-
<farm-checkbox v-model="isChecked" label="custom label" />
|
|
54
|
+
<farm-checkbox v-model="isChecked" value="1" label="custom label" />
|
|
53
55
|
</div>`,
|
|
54
56
|
});
|
|
55
57
|
|
|
@@ -61,8 +63,8 @@ export const Disabled = () => ({
|
|
|
61
63
|
};
|
|
62
64
|
},
|
|
63
65
|
template: `<div>
|
|
64
|
-
<farm-checkbox v-model="isChecked" :disabled="true" /><br />
|
|
65
|
-
<farm-checkbox v-model="notIsChecked" :disabled="true" />
|
|
66
|
+
<farm-checkbox v-model="isChecked" :value="true" :disabled="true" /><br />
|
|
67
|
+
<farm-checkbox v-model="notIsChecked" value="" :disabled="true" />
|
|
66
68
|
</div>`,
|
|
67
69
|
});
|
|
68
70
|
|
|
@@ -84,6 +86,7 @@ export const Colors = () => ({
|
|
|
84
86
|
>
|
|
85
87
|
<farm-checkbox
|
|
86
88
|
v-model="isChecked"
|
|
89
|
+
:value="true"
|
|
87
90
|
:color="color"
|
|
88
91
|
:variation="variation"
|
|
89
92
|
:label="variation || 'Base'"
|
|
@@ -102,7 +105,7 @@ export const Sizes = () => ({
|
|
|
102
105
|
},
|
|
103
106
|
template: `<div style="display: flex; flex-direction: column; flex-wrap: wrap;">
|
|
104
107
|
<div v-for="size of sizes">
|
|
105
|
-
<farm-checkbox v-model="isChecked" :size="size" :label="size" /><br />
|
|
108
|
+
<farm-checkbox v-model="isChecked" :size="size" :value="true" :label="size" /><br />
|
|
106
109
|
</div>
|
|
107
110
|
</div>`,
|
|
108
111
|
});
|
|
@@ -115,6 +118,6 @@ export const Indeterminate = () => ({
|
|
|
115
118
|
};
|
|
116
119
|
},
|
|
117
120
|
template: `<div>
|
|
118
|
-
<farm-checkbox :indeterminate="true" v-model="isChecked" />
|
|
121
|
+
<farm-checkbox :indeterminate="true" v-model="isChecked" :value="true" />
|
|
119
122
|
</div>`,
|
|
120
123
|
});
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
<span
|
|
4
4
|
:class="{
|
|
5
5
|
'farm-checkbox': true,
|
|
6
|
-
'farm-checkbox--checked':
|
|
6
|
+
'farm-checkbox--checked': isChecked,
|
|
7
7
|
'farm-checkbox--disabled': disabled,
|
|
8
8
|
'farm-checkbox--indeterminate': indeterminate,
|
|
9
9
|
'farm-checkbox--lighten': variation === 'lighten',
|
|
10
10
|
'farm-checkbox--darken': variation === 'darken',
|
|
11
|
+
'farm-checkbox--error': showError,
|
|
11
12
|
}"
|
|
12
13
|
:size="$props.size"
|
|
13
14
|
@click="toggleValue"
|
|
@@ -30,11 +31,18 @@ import deepEqual from '../../composition/deepEqual';
|
|
|
30
31
|
|
|
31
32
|
export default Vue.extend({
|
|
32
33
|
name: 'farm-checkbox',
|
|
34
|
+
model: {
|
|
35
|
+
prop: 'modelValue',
|
|
36
|
+
},
|
|
33
37
|
props: {
|
|
34
38
|
/**
|
|
35
39
|
* v-model binding
|
|
36
40
|
*/
|
|
37
|
-
|
|
41
|
+
modelValue: {},
|
|
42
|
+
/**
|
|
43
|
+
* Value to be set to v-model
|
|
44
|
+
*/
|
|
45
|
+
value: { type: [String, Number, Boolean], default: undefined },
|
|
38
46
|
/**
|
|
39
47
|
* Label
|
|
40
48
|
*/
|
|
@@ -85,28 +93,40 @@ export default Vue.extend({
|
|
|
85
93
|
indeterminate: { type: Boolean, default: false },
|
|
86
94
|
},
|
|
87
95
|
setup(props, { emit }) {
|
|
88
|
-
const innerValue = ref(props.
|
|
96
|
+
const innerValue = ref(props.modelValue);
|
|
89
97
|
const { label, disabled, rules } = toRefs(props);
|
|
90
98
|
const { errorBucket, valid, validatable } = validateFormStateBuilder();
|
|
91
|
-
|
|
99
|
+
const isTouched = ref(false);
|
|
92
100
|
let fieldValidator = validateFormFieldBuilder(rules.value);
|
|
93
101
|
|
|
94
102
|
const toggleValue = () => {
|
|
95
103
|
if (disabled.value) {
|
|
96
104
|
return false;
|
|
97
105
|
}
|
|
98
|
-
|
|
106
|
+
isTouched.value = true;
|
|
107
|
+
if (isChecked.value) {
|
|
108
|
+
innerValue.value = null;
|
|
109
|
+
} else {
|
|
110
|
+
innerValue.value = props.value;
|
|
111
|
+
}
|
|
99
112
|
emit('input', innerValue.value);
|
|
100
113
|
validate(innerValue.value);
|
|
101
114
|
};
|
|
102
115
|
|
|
116
|
+
const isChecked = computed(() => {
|
|
117
|
+
return innerValue.value == props.value;
|
|
118
|
+
});
|
|
119
|
+
|
|
103
120
|
const hasError = computed(() => {
|
|
104
121
|
return errorBucket.value.length > 0;
|
|
105
122
|
});
|
|
106
123
|
|
|
124
|
+
const showError = computed(() => hasError.value && isTouched.value);
|
|
125
|
+
|
|
107
126
|
watch(
|
|
108
127
|
() => props.value,
|
|
109
128
|
() => {
|
|
129
|
+
isTouched.value = true;
|
|
110
130
|
innerValue.value = props.value;
|
|
111
131
|
validate(innerValue.value);
|
|
112
132
|
}
|
|
@@ -126,7 +146,9 @@ export default Vue.extend({
|
|
|
126
146
|
if (disabled.value) {
|
|
127
147
|
return false;
|
|
128
148
|
}
|
|
129
|
-
|
|
149
|
+
isTouched.value = true;
|
|
150
|
+
innerValue.value = null;
|
|
151
|
+
validate(innerValue.value);
|
|
130
152
|
emit('input', innerValue.value);
|
|
131
153
|
};
|
|
132
154
|
|
|
@@ -144,9 +166,11 @@ export default Vue.extend({
|
|
|
144
166
|
valid,
|
|
145
167
|
validatable,
|
|
146
168
|
hasError,
|
|
169
|
+
isChecked,
|
|
147
170
|
toggleValue,
|
|
148
171
|
reset,
|
|
149
172
|
validate,
|
|
173
|
+
showError,
|
|
150
174
|
};
|
|
151
175
|
},
|
|
152
176
|
});
|
|
@@ -32,7 +32,7 @@ export const Primary = () => ({
|
|
|
32
32
|
form: {
|
|
33
33
|
document: 'Document',
|
|
34
34
|
name: 'Name',
|
|
35
|
-
checkbox:
|
|
35
|
+
checkbox: '2',
|
|
36
36
|
birthDate: new Date('1980/09/20').toISOString(),
|
|
37
37
|
selectId: 1,
|
|
38
38
|
rangeDate: [],
|
|
@@ -54,16 +54,16 @@ export const Primary = () => ({
|
|
|
54
54
|
<farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
|
|
55
55
|
<div>
|
|
56
56
|
<farm-label :required="true">Documento</farm-label>
|
|
57
|
-
<farm-textfield v-model="form.document" :rules="[rules.required]" />
|
|
57
|
+
<farm-textfield-v2 v-model="form.document" :rules="[rules.required]" />
|
|
58
58
|
</div>
|
|
59
59
|
<farm-label :required="true">Nome</farm-label>
|
|
60
|
-
<farm-textfield v-model="form.name" :rules="[rules.required]" />
|
|
60
|
+
<farm-textfield-v2 v-model="form.name" :rules="[rules.required]" />
|
|
61
61
|
|
|
62
62
|
<farm-label :required="true">True/false</farm-label>
|
|
63
|
-
<farm-checkbox v-model="form.checkbox" :rules="[rules.checked]" />
|
|
63
|
+
<farm-checkbox v-model="form.checkbox" value="1" :rules="[rules.checked]" />
|
|
64
64
|
|
|
65
65
|
<farm-label :required="true">Select</farm-label>
|
|
66
|
-
<
|
|
66
|
+
<farm-select :rules="[rules.required]" :items="items" v-model="form.selectId"/>
|
|
67
67
|
|
|
68
68
|
<farm-label :required="true">Birthdate:</farm-label>
|
|
69
69
|
<farm-input-datepicker
|
|
@@ -119,7 +119,7 @@ export const Secondary = () => ({
|
|
|
119
119
|
<section>
|
|
120
120
|
<div>
|
|
121
121
|
<farm-label :required="true">Documento</farm-label>
|
|
122
|
-
<farm-textfield v-model="form.document" :rules="[rules.required]" />
|
|
122
|
+
<farm-textfield-v2 v-model="form.document" :rules="[rules.required]" />
|
|
123
123
|
</div>
|
|
124
124
|
</section>
|
|
125
125
|
<section>
|
|
@@ -130,11 +130,11 @@ export const Secondary = () => ({
|
|
|
130
130
|
</section>
|
|
131
131
|
|
|
132
132
|
<farm-label>Not required</farm-label>
|
|
133
|
-
<farm-checkbox v-model="form.checkbox" />
|
|
133
|
+
<farm-checkbox value="1" v-model="form.checkbox" />
|
|
134
134
|
|
|
135
135
|
<div class="footer" :style="[styles.footer]">
|
|
136
|
-
<farm-btn
|
|
137
|
-
<farm-btn
|
|
136
|
+
<farm-btn outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
|
|
137
|
+
<farm-btn :disabled="!validForm">Salvar</farm-btn>
|
|
138
138
|
</div>
|
|
139
139
|
</farm-form>
|
|
140
140
|
`,
|
|
@@ -161,51 +161,30 @@ export const InitInvalid = () => ({
|
|
|
161
161
|
<section>
|
|
162
162
|
<div>
|
|
163
163
|
<farm-label :required="true">Documento</farm-label>
|
|
164
|
-
<farm-textfield v-model="form.document" :rules="[rules.required]" />
|
|
164
|
+
<farm-textfield-v2 v-model="form.document" :rules="[rules.required]" />
|
|
165
165
|
</div>
|
|
166
166
|
</section>
|
|
167
167
|
<section>
|
|
168
168
|
<div>
|
|
169
169
|
<farm-label :required="true">Nome</farm-label>
|
|
170
|
-
<farm-textfield v-model="form.name" :rules="[rules.required]" />
|
|
170
|
+
<farm-textfield-v2 v-model="form.name" :rules="[rules.required]" />
|
|
171
171
|
</div>
|
|
172
172
|
</section>
|
|
173
173
|
|
|
174
174
|
<farm-label :required="true">True/false</farm-label>
|
|
175
|
-
<farm-checkbox v-model="form.checkbox" :rules="[rules.checked]" />
|
|
175
|
+
<farm-checkbox v-model="form.checkbox" value="1" :rules="[rules.checked]" />
|
|
176
176
|
|
|
177
177
|
<div class="footer" :style="[styles.footer]">
|
|
178
|
-
<farm-btn
|
|
179
|
-
<farm-btn
|
|
178
|
+
<farm-btn outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
|
|
179
|
+
<farm-btn :disabled="!validForm">Salvar</farm-btn>
|
|
180
180
|
</div>
|
|
181
181
|
</farm-form>
|
|
182
182
|
`,
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
export const RadioGroupReset = () => ({
|
|
186
|
-
data() {
|
|
187
|
-
return {
|
|
188
|
-
checkedValue: 1,
|
|
189
|
-
buttons: [
|
|
190
|
-
{ label: 'Button 1', id: 1 },
|
|
191
|
-
{ label: 'Button 2', id: 2 },
|
|
192
|
-
{ label: 'Button 3', id: 3 },
|
|
193
|
-
],
|
|
194
|
-
validForm: false,
|
|
195
|
-
styles,
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
template: `
|
|
199
|
-
<farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
|
|
200
|
-
<farm-radio-group v-model="checkedValue" column :buttons="buttons" />
|
|
201
185
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
|
|
205
|
-
</div>
|
|
206
|
-
</farm-form>
|
|
207
|
-
`,
|
|
208
|
-
});
|
|
186
|
+
|
|
187
|
+
|
|
209
188
|
|
|
210
189
|
export const Grid = () => ({
|
|
211
190
|
data() {
|
|
@@ -331,3 +310,30 @@ export const MigrateSelectV2 = () => ({
|
|
|
331
310
|
</farm-form>
|
|
332
311
|
`,
|
|
333
312
|
});
|
|
313
|
+
|
|
314
|
+
export const ValidateRadioGroup = () => ({
|
|
315
|
+
data() {
|
|
316
|
+
return {
|
|
317
|
+
checkedValue: null,
|
|
318
|
+
validForm: false,
|
|
319
|
+
styles,
|
|
320
|
+
rules: {
|
|
321
|
+
required: value => !!value || 'Campo obrigatório',
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
template: `
|
|
326
|
+
<farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
|
|
327
|
+
<farm-radio-group v-model="checkedValue" :rules="[rules.required]">
|
|
328
|
+
<farm-radio v-model="checkedValue" value="1" /><farm-label>value 1</farm-label>
|
|
329
|
+
<farm-radio v-model="checkedValue" value="2" /><farm-label>value 2</farm-label>
|
|
330
|
+
<farm-radio v-model="checkedValue" value="3" /><farm-label>value 3</farm-label>
|
|
331
|
+
</farm-radio-group>
|
|
332
|
+
|
|
333
|
+
<div class="footer" :style="[styles.footer]">
|
|
334
|
+
<farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
|
|
335
|
+
<farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
|
|
336
|
+
</div>
|
|
337
|
+
</farm-form>
|
|
338
|
+
`,
|
|
339
|
+
});
|
|
@@ -26,7 +26,7 @@ export default Vue.extend({
|
|
|
26
26
|
imgSrc() {
|
|
27
27
|
const href = window.location.href;
|
|
28
28
|
return `${
|
|
29
|
-
href.indexOf('localhost') || href.indexOf('front-farm-storybook')
|
|
29
|
+
href.indexOf('localhost') >= 0 || href.indexOf('front-farm-storybook') >= 0
|
|
30
30
|
? 'https://dev.plataforma.portalfarm.com.br'
|
|
31
31
|
: ''
|
|
32
32
|
}/public/logos/originadores/${this.id}/${this.variation}.svg`;
|
|
@@ -26,7 +26,7 @@ export default Vue.extend({
|
|
|
26
26
|
imgSrc() {
|
|
27
27
|
const href = window.location.href;
|
|
28
28
|
return `${
|
|
29
|
-
href.indexOf('localhost') || href.indexOf('front-farm-storybook')
|
|
29
|
+
href.indexOf('localhost') >= 0 || href.indexOf('front-farm-storybook') >= 0
|
|
30
30
|
? 'https://dev.plataforma.portalfarm.com.br'
|
|
31
31
|
: ''
|
|
32
32
|
}/public/logos/products/${this.id}/${this.variation}.svg`;
|
|
@@ -23,73 +23,64 @@ export default {
|
|
|
23
23
|
export const Primary = () => ({
|
|
24
24
|
data() {
|
|
25
25
|
return {
|
|
26
|
-
|
|
27
|
-
{ label: 'Random text', id: 1 },
|
|
28
|
-
{ label: 'In', id: 2 },
|
|
29
|
-
{ label: 'Radio Group', id: 3 },
|
|
30
|
-
],
|
|
31
|
-
checkedValue: 1,
|
|
26
|
+
checkedValue: null,
|
|
32
27
|
};
|
|
33
28
|
},
|
|
34
29
|
template: `<div>
|
|
35
|
-
<farm-radio-group v-model="checkedValue"
|
|
30
|
+
<farm-radio-group v-model="checkedValue">
|
|
31
|
+
<farm-radio v-model="checkedValue" value="1" /><farm-label>value 1</farm-label>
|
|
32
|
+
<farm-radio v-model="checkedValue" value="2" /><farm-label>value 2</farm-label>
|
|
33
|
+
<farm-radio v-model="checkedValue" value="3" /><farm-label>value 3</farm-label>
|
|
34
|
+
</farm-radio-group>
|
|
35
|
+
selectedValue: {{ checkedValue }}
|
|
36
36
|
</div>`,
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
export const Reset = () => ({
|
|
40
40
|
data() {
|
|
41
41
|
return {
|
|
42
|
-
|
|
43
|
-
{ label: 'Button 1', id: 1 },
|
|
44
|
-
{ label: 'Button 2', id: 2 },
|
|
45
|
-
{ label: 'Button 3', id: 3 },
|
|
46
|
-
],
|
|
47
|
-
checkedValue: 1,
|
|
42
|
+
checkedValue: null,
|
|
48
43
|
};
|
|
49
44
|
},
|
|
50
45
|
methods: {
|
|
51
46
|
reset() {
|
|
52
|
-
this.$refs.
|
|
47
|
+
this.$refs.radioGroup.reset();
|
|
53
48
|
},
|
|
54
49
|
},
|
|
55
50
|
template: `<div>
|
|
56
|
-
<farm-radio-group v-model="checkedValue"
|
|
57
|
-
|
|
51
|
+
<farm-radio-group v-model="checkedValue" ref="radioGroup">
|
|
52
|
+
<farm-radio v-model="checkedValue" value="1" /><farm-label>value 1</farm-label>
|
|
53
|
+
<farm-radio v-model="checkedValue" value="2" /><farm-label>value 2</farm-label>
|
|
54
|
+
<farm-radio v-model="checkedValue" value="3" /><farm-label>value 3</farm-label>
|
|
55
|
+
</farm-radio-group>
|
|
56
|
+
selectedValue: {{ checkedValue }}
|
|
57
|
+
<farm-btn @click="reset">reset</farm-btn>
|
|
58
58
|
</div>`,
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
export const
|
|
61
|
+
export const Validate = () => ({
|
|
62
62
|
data() {
|
|
63
63
|
return {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
],
|
|
69
|
-
checkedValue: 1,
|
|
64
|
+
checkedValue: null,
|
|
65
|
+
rules: {
|
|
66
|
+
required: value => !!value || 'Required field',
|
|
67
|
+
},
|
|
70
68
|
};
|
|
71
69
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const Colors = () => ({
|
|
78
|
-
data() {
|
|
79
|
-
return {
|
|
80
|
-
buttons: [
|
|
81
|
-
{ label: 'Button 1', id: 1 },
|
|
82
|
-
{ label: 'Button 2', id: 2 },
|
|
83
|
-
{ label: 'Button 3', id: 3 },
|
|
84
|
-
],
|
|
85
|
-
checkedValue: 1,
|
|
86
|
-
colors,
|
|
87
|
-
};
|
|
70
|
+
methods: {
|
|
71
|
+
reset() {
|
|
72
|
+
this.$refs.radioGroup.reset();
|
|
73
|
+
},
|
|
88
74
|
},
|
|
89
|
-
template: `<div style="
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
<farm-radio
|
|
93
|
-
|
|
75
|
+
template: `<div style="width: 480px">
|
|
76
|
+
|
|
77
|
+
<farm-radio-group v-model="checkedValue" ref="radioGroup" :rules="[rules.required]">
|
|
78
|
+
<farm-radio v-model="checkedValue" value="1" /><farm-label>value 1</farm-label>
|
|
79
|
+
<farm-radio v-model="checkedValue" value="2" /><farm-label>value 2</farm-label>
|
|
80
|
+
<farm-radio v-model="checkedValue" value="3" /><farm-label>value 3</farm-label>
|
|
81
|
+
</farm-radio-group>
|
|
82
|
+
selectedValue: {{ checkedValue }}
|
|
83
|
+
<farm-btn @click="reset">reset</farm-btn>
|
|
84
|
+
|
|
94
85
|
</div>`,
|
|
95
86
|
});
|
|
@@ -2,104 +2,94 @@
|
|
|
2
2
|
<div
|
|
3
3
|
:class="{
|
|
4
4
|
'farm-radio-group': true,
|
|
5
|
-
'farm-radio-group--vertical': $props.vertical,
|
|
6
5
|
}"
|
|
7
|
-
:color="color"
|
|
8
6
|
>
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@click="clicked(button.id)"
|
|
14
|
-
>
|
|
15
|
-
<input
|
|
16
|
-
type="radio"
|
|
17
|
-
name="radio"
|
|
18
|
-
:checked="button.id === innerValue"
|
|
19
|
-
:id="`farm-radio-group_` + index"
|
|
20
|
-
:value="button.id"
|
|
21
|
-
:class="{ checked: button.id === innerValue }"
|
|
22
|
-
/>
|
|
23
|
-
<label> {{ button.label }} </label>
|
|
24
|
-
</div>
|
|
7
|
+
<slot></slot>
|
|
8
|
+
<farm-caption v-if="showErrorText" color="error" variation="regular">
|
|
9
|
+
{{ errorBucket[0] }}
|
|
10
|
+
</farm-caption>
|
|
25
11
|
</div>
|
|
26
12
|
</template>
|
|
27
13
|
<script lang="ts">
|
|
28
|
-
import Vue, { PropType,
|
|
14
|
+
import Vue, { ref, watch, PropType, toRefs, computed, onBeforeMount } from 'vue';
|
|
29
15
|
import validateFormStateBuilder from '../../composition/validateFormStateBuilder';
|
|
30
|
-
import
|
|
16
|
+
import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
|
|
17
|
+
import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
|
|
18
|
+
import deepEqual from '../../composition/deepEqual';
|
|
19
|
+
|
|
31
20
|
export default Vue.extend({
|
|
32
21
|
name: 'farm-radio-group',
|
|
33
22
|
props: {
|
|
34
|
-
/**
|
|
35
|
-
* Array of buttons
|
|
36
|
-
*/
|
|
37
|
-
buttons: {
|
|
38
|
-
type: Array as PropType<Array<IRadioGroup>>,
|
|
39
|
-
default: [],
|
|
40
|
-
},
|
|
41
23
|
/**
|
|
42
24
|
* v-model
|
|
43
25
|
*/
|
|
44
26
|
value: {
|
|
45
27
|
required: true,
|
|
46
28
|
},
|
|
29
|
+
errorMessage: String,
|
|
47
30
|
/**
|
|
48
|
-
*
|
|
31
|
+
* Array of rules used for validation
|
|
49
32
|
*/
|
|
50
|
-
|
|
51
|
-
type:
|
|
52
|
-
default:
|
|
33
|
+
rules: {
|
|
34
|
+
type: Array as PropType<Array<Function>>,
|
|
35
|
+
default: () => [],
|
|
53
36
|
},
|
|
54
|
-
color: {
|
|
55
|
-
type: String as PropType<
|
|
56
|
-
| 'primary'
|
|
57
|
-
| 'secondary'
|
|
58
|
-
| 'neutral'
|
|
59
|
-
| 'info'
|
|
60
|
-
| 'success'
|
|
61
|
-
| 'error'
|
|
62
|
-
| 'warning'
|
|
63
|
-
| 'success'
|
|
64
|
-
| 'extra-1'
|
|
65
|
-
| 'extra-2'
|
|
66
|
-
| 'gray'
|
|
67
|
-
>,
|
|
68
|
-
default: 'primary',
|
|
69
|
-
}
|
|
70
37
|
},
|
|
71
38
|
setup(props, { emit }) {
|
|
39
|
+
const { rules } = toRefs(props);
|
|
72
40
|
const innerValue = ref(props.value);
|
|
73
41
|
const { errorBucket, valid, validatable } = validateFormStateBuilder();
|
|
42
|
+
const isTouched = ref(false);
|
|
74
43
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
44
|
+
let fieldValidator = validateFormFieldBuilder(rules.value);
|
|
45
|
+
|
|
46
|
+
const hasError = computed(() => {
|
|
47
|
+
return errorBucket.value.length > 0;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const showErrorText = computed(() => hasError.value && isTouched.value);
|
|
79
51
|
|
|
80
52
|
watch(
|
|
81
53
|
() => props.value,
|
|
82
54
|
() => {
|
|
55
|
+
isTouched.value = true;
|
|
83
56
|
innerValue.value = props.value;
|
|
57
|
+
validate(innerValue.value);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
watch(
|
|
62
|
+
() => props.rules,
|
|
63
|
+
(newVal, oldVal) => {
|
|
64
|
+
if (deepEqual(newVal, oldVal)) return;
|
|
65
|
+
fieldValidator = validateFormFieldBuilder(rules.value);
|
|
66
|
+
validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
|
|
67
|
+
validate(innerValue.value);
|
|
84
68
|
}
|
|
85
69
|
);
|
|
86
70
|
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
let validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
|
|
72
|
+
|
|
73
|
+
const reset = () => {
|
|
74
|
+
innerValue.value = null;
|
|
89
75
|
emit('input', innerValue.value);
|
|
90
76
|
};
|
|
91
77
|
|
|
78
|
+
onBeforeMount(() => {
|
|
79
|
+
validate(innerValue.value);
|
|
80
|
+
});
|
|
81
|
+
|
|
92
82
|
return {
|
|
93
83
|
innerValue,
|
|
94
84
|
errorBucket,
|
|
95
85
|
valid,
|
|
96
86
|
validatable,
|
|
87
|
+
hasError,
|
|
88
|
+
showErrorText,
|
|
89
|
+
isTouched,
|
|
97
90
|
reset,
|
|
98
|
-
|
|
91
|
+
validate,
|
|
99
92
|
};
|
|
100
93
|
},
|
|
101
94
|
});
|
|
102
95
|
</script>
|
|
103
|
-
<style lang="scss" scoped>
|
|
104
|
-
@import './RadioGroup.scss';
|
|
105
|
-
</style>
|