@farm-investimentos/front-mfe-components 11.8.4 → 11.9.0
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 +121 -152
- 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 +121 -152
- 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/Form/Form.stories.js +31 -23
- 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
|
@@ -26,6 +26,7 @@ const styles = {
|
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/*
|
|
29
30
|
export const Primary = () => ({
|
|
30
31
|
data() {
|
|
31
32
|
return {
|
|
@@ -182,30 +183,9 @@ export const InitInvalid = () => ({
|
|
|
182
183
|
`,
|
|
183
184
|
});
|
|
184
185
|
|
|
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
186
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
|
|
205
|
-
</div>
|
|
206
|
-
</farm-form>
|
|
207
|
-
`,
|
|
208
|
-
});
|
|
187
|
+
|
|
188
|
+
|
|
209
189
|
|
|
210
190
|
export const Grid = () => ({
|
|
211
191
|
data() {
|
|
@@ -331,3 +311,31 @@ export const MigrateSelectV2 = () => ({
|
|
|
331
311
|
</farm-form>
|
|
332
312
|
`,
|
|
333
313
|
});
|
|
314
|
+
*/
|
|
315
|
+
|
|
316
|
+
export const ValidateRadioGroup = () => ({
|
|
317
|
+
data() {
|
|
318
|
+
return {
|
|
319
|
+
checkedValue: null,
|
|
320
|
+
validForm: false,
|
|
321
|
+
styles,
|
|
322
|
+
rules: {
|
|
323
|
+
required: value => !!value || 'Campo obrigatório',
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
template: `
|
|
328
|
+
<farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
|
|
329
|
+
<farm-radio-group v-model="checkedValue" :rules="[rules.required]">
|
|
330
|
+
<farm-radio v-model="checkedValue" value="1" /><farm-label>value 1</farm-label>
|
|
331
|
+
<farm-radio v-model="checkedValue" value="2" /><farm-label>value 2</farm-label>
|
|
332
|
+
<farm-radio v-model="checkedValue" value="3" /><farm-label>value 3</farm-label>
|
|
333
|
+
</farm-radio-group>
|
|
334
|
+
|
|
335
|
+
<div class="footer" :style="[styles.footer]">
|
|
336
|
+
<farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
|
|
337
|
+
<farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
|
|
338
|
+
</div>
|
|
339
|
+
</farm-form>
|
|
340
|
+
`,
|
|
341
|
+
});
|
|
@@ -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>
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
@import '../../configurations/theme-colors';
|
|
2
|
-
|
|
3
|
-
.farm-radio-group {
|
|
4
|
-
border: none;
|
|
5
|
-
cursor: default;
|
|
6
|
-
display: flex;
|
|
7
|
-
width: 100%;
|
|
8
|
-
|
|
9
|
-
&__item {
|
|
10
|
-
font-size: 16px;
|
|
11
|
-
line-height: 18px;
|
|
12
|
-
cursor: pointer;
|
|
13
|
-
display: grid;
|
|
14
|
-
grid-template-columns: 16px auto;
|
|
15
|
-
gap: 0;
|
|
16
|
-
color: rgba(0, 0, 0, .6);
|
|
17
|
-
margin-right: 32px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
label {
|
|
21
|
-
cursor: pointer;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
input[type="radio"].checked {
|
|
25
|
-
border: 1.5px solid black;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
&--vertical {
|
|
29
|
-
flex-direction: column;
|
|
30
|
-
.farm-radio-group__item {
|
|
31
|
-
margin-right: 24px;
|
|
32
|
-
margin-top: 16px;
|
|
33
|
-
&:first-of-type {
|
|
34
|
-
margin-top: 0;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@each $color in $theme-colors-list {
|
|
40
|
-
&#{'[color=' + $color + ']'} {
|
|
41
|
-
input[type="radio"]::before {
|
|
42
|
-
box-shadow: inset 16px 16px themeColor($color);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
input[type="radio"].checked {
|
|
46
|
-
border-color: themeColor($color);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
input[type="radio"] {
|
|
54
|
-
-webkit-appearance: none;
|
|
55
|
-
appearance: none;
|
|
56
|
-
background-color: #ffffff;
|
|
57
|
-
margin: 0;
|
|
58
|
-
font: inherit;
|
|
59
|
-
color: rgba(0, 0, 0, .6);
|
|
60
|
-
width: 18px;
|
|
61
|
-
height: 18px;
|
|
62
|
-
border: 1.5px solid rgba(0, 0, 0, .6);
|
|
63
|
-
border-radius: 50%;
|
|
64
|
-
transform: translate(-12px);
|
|
65
|
-
display: grid;
|
|
66
|
-
place-content: center;
|
|
67
|
-
cursor: pointer;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
input[type="radio"]::before {
|
|
71
|
-
content: "";
|
|
72
|
-
width: 10px;
|
|
73
|
-
height: 10px;
|
|
74
|
-
border-radius: 50%;
|
|
75
|
-
transform: scale(0);
|
|
76
|
-
transition: 120ms transform ease-in-out;
|
|
77
|
-
background-color: CanvasText;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
input[type="radio"].checked::before {
|
|
81
|
-
transform: scale(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
input[type="radio"]:focus {
|
|
85
|
-
outline: none;
|
|
86
|
-
outline-offset: none;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
input[type='radio']:hover {
|
|
90
|
-
box-shadow: 0px 0px 0px 8px rgba(0, 0, 0, 0.1);
|
|
91
|
-
background-color: rgba(0, 0, 0, 0.1);
|
|
92
|
-
border-radius: 50%;
|
|
93
|
-
opacity: 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
input[type='radio']:active {
|
|
97
|
-
animation: pulse 0.2s 1 ease-out;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
@keyframes pulse {
|
|
101
|
-
from {
|
|
102
|
-
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(0, 0, 0, 0.2);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
to {
|
|
106
|
-
box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.2), 0 0 0 8px rgba(0, 0, 0, 0.2);
|
|
107
|
-
}
|
|
108
|
-
}
|