@farm-investimentos/front-mfe-components 11.8.3 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "11.8.3",
3
+ "version": "11.9.0",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -1,6 +1,5 @@
1
1
  .farm-dialog-header__close {
2
2
  position: absolute;
3
- right: 16px;
4
3
  margin-top: 0;
5
4
  font-size: 16px;
6
5
 
@@ -15,7 +15,7 @@
15
15
  title="Fechar"
16
16
  @click="onClose"
17
17
  >
18
- <farm-icon role="button"> close-thick </farm-icon>
18
+ <farm-icon role="button" size="md"> window-close </farm-icon>
19
19
  </farm-btn>
20
20
  </header>
21
21
  </template>
@@ -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
- <div class="footer" :style="[styles.footer]">
203
- <farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
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
+ });
@@ -5,11 +5,10 @@ input[type="radio"] {
5
5
  margin: 0;
6
6
  font: inherit;
7
7
  color: rgba(0, 0, 0, .6);
8
- width: 18px;
9
- height: 18px;
8
+ width: 24px;
9
+ height: 24px;
10
10
  border: 1.5px solid rgba(0, 0, 0, .6);
11
11
  border-radius: 50%;
12
- transform: translate(-12px);
13
12
  display: grid;
14
13
  place-content: center;
15
14
  cursor: pointer;
@@ -13,6 +13,10 @@ export default {
13
13
  <span style="color: var(--farm-extra-1-base);">development</span>
14
14
  `,
15
15
  },
16
+ design: {
17
+ type: 'figma',
18
+ url: 'https://www.figma.com/file/p62YDSTfWg0Mcnf5APfdvI/%E2%9C%8D-Design-System-%7C-v2?node-id=4913%3A20222&t=RIUg7AZerUGMSaM9-0',
19
+ },
16
20
  },
17
21
  viewMode: 'docs',
18
22
  },
@@ -26,22 +26,24 @@ export default Vue.extend({
26
26
  /**
27
27
  * Value to be set to v-model
28
28
  */
29
- value: { type: String, default: undefined },
29
+ value: { type: [String, Number, Boolean], default: undefined },
30
30
  },
31
31
  computed: {
32
32
  isChecked() {
33
33
  return this.modelValue == this.value;
34
34
  },
35
35
  },
36
- methods: {
37
- onClick(event) {
38
- this.$emit('change', event.target.value);
39
- this.$emit('input', event.target.value);
40
- },
41
- validate() {},
42
- reset() {
43
- this.$emit('input', null);
44
- },
36
+ setup(_, { emit }) {
37
+ const onClick = event => {
38
+ emit('change', event.target.value);
39
+ emit('input', event.target.value);
40
+ };
41
+
42
+ const reset = () => {
43
+ emit('input', null);
44
+ };
45
+ const validate = () => {};
46
+ return { onClick, reset, validate };
45
47
  },
46
48
  });
47
49
  </script>
@@ -23,73 +23,64 @@ export default {
23
23
  export const Primary = () => ({
24
24
  data() {
25
25
  return {
26
- buttons: [
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" :buttons="buttons" />
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
- buttons: [
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.radiogroupreset.reset();
47
+ this.$refs.radioGroup.reset();
53
48
  },
54
49
  },
55
50
  template: `<div>
56
- <farm-radio-group v-model="checkedValue" :buttons="buttons" ref="radiogroupreset" /><br />
57
- <farm-btn @click="reset">Reset</farm-btn>
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 Vertical = () => ({
61
+ export const Validate = () => ({
62
62
  data() {
63
63
  return {
64
- buttons: [
65
- { label: 'Button 1', id: 1 },
66
- { label: 'Button 2', id: 2 },
67
- { label: 'Button 3', id: 3 },
68
- ],
69
- checkedValue: 1,
64
+ checkedValue: null,
65
+ rules: {
66
+ required: value => !!value || 'Required field',
67
+ },
70
68
  };
71
69
  },
72
- template: `<div>
73
- <farm-radio-group v-model="checkedValue" vertical :buttons="buttons" />
74
- </div>`,
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="display: flex; flex-direction: row; flex-wrap: wrap;">
90
- <div v-for="color in colors" style="width: 33.3%; margin-bottom: 32px;">
91
- <h4 style="margin-bottom: 16px">{{ color }}</h4>
92
- <farm-radio-group v-model="checkedValue" vertical :color="color" :buttons="buttons" />
93
- </div>
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
- <div
10
- class="farm-radio-group__item"
11
- v-for="(button, index) in buttons"
12
- :key="`farm-radio-group_` + index"
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, ref, watch } from 'vue';
14
+ import Vue, { ref, watch, PropType, toRefs, computed, onBeforeMount } from 'vue';
29
15
  import validateFormStateBuilder from '../../composition/validateFormStateBuilder';
30
- import IRadioGroup from './IRadioGroup';
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
- * Is vertical?
31
+ * Array of rules used for validation
49
32
  */
50
- vertical: {
51
- type: Boolean,
52
- default: false,
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
- const reset = () => {
76
- innerValue.value = false;
77
- emit('input', innerValue.value);
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
- const clicked = value => {
88
- innerValue.value = value;
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
- clicked,
91
+ validate,
99
92
  };
100
93
  },
101
94
  });
102
95
  </script>
103
- <style lang="scss" scoped>
104
- @import './RadioGroup.scss';
105
- </style>
@@ -1,6 +0,0 @@
1
- interface IRadioGroup {
2
- id: Number;
3
- label: String;
4
- }
5
-
6
- export default IRadioGroup;
@@ -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
- }