@farm-investimentos/front-mfe-components 12.2.0 → 12.2.2

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": "12.2.0",
3
+ "version": "12.2.2",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -10,7 +10,7 @@
10
10
  "serve": "vue-cli-service serve",
11
11
  "build": "npm run build:components",
12
12
  "build:components": "vue-cli-service build --target lib --name front-mfe-components src/main.ts",
13
- "lint": "vue-cli-service lint",
13
+ "lint": "vue-cli-service lint --fix",
14
14
  "storybook": "start-storybook -p 6006",
15
15
  "build-storybook": "build-storybook",
16
16
  "test:unit": "jest --updateSnapshot",
@@ -62,3 +62,17 @@ export const Colors = () => ({
62
62
  <farm-alertbox class="mt-3" v-for="color of colors" :key="'random_10_' + color" :color="color" icon="book" dismissable>alert box</farm-alertbox>
63
63
  </div> `,
64
64
  });
65
+
66
+ export const withDismissableShowAgain = () => ({
67
+ data() {
68
+ return {
69
+ v: true,
70
+ }
71
+ },
72
+ template: `<div>
73
+ <farm-alertbox v-model="v" dismissable>alert box</farm-alertbox>
74
+ <farm-btn v-if="!v" @click="v = true;">
75
+ show
76
+ </farm-btn>
77
+ </div>`,
78
+ });
@@ -44,6 +44,7 @@
44
44
 
45
45
  <script lang="ts">
46
46
  import Vue, { ref, PropType } from 'vue';
47
+ import valueWatcher from './valueWatcher';
47
48
 
48
49
  export default Vue.extend({
49
50
  name: 'farm-alertbox',
@@ -87,20 +88,29 @@ export default Vue.extend({
87
88
  >,
88
89
  default: 'primary',
89
90
  },
91
+ value: {
92
+ type: Boolean,
93
+ default: true,
94
+ },
90
95
  },
91
- setup() {
96
+ setup(props, { emit }) {
92
97
  const visible = ref(true);
93
98
 
94
99
  function close() {
95
100
  visible.value = false;
101
+ emit('input', false);
96
102
  }
97
103
 
104
+ valueWatcher(props, visible);
105
+
98
106
  return {
99
107
  visible,
100
108
  close,
101
109
  };
102
110
  },
103
111
  });
112
+
113
+
104
114
  </script>
105
115
  <style lang="scss" scoped>
106
116
  @import './AlertBox';
@@ -0,0 +1,15 @@
1
+ import { ref, reactive } from 'vue';
2
+ import valueWatcher from '../valueWatcher';
3
+
4
+ describe('valueWatcher', () => {
5
+ it('Should change value for visible', done => {
6
+ const visible = ref(false);
7
+ const mockProps = reactive({ value: false });
8
+ valueWatcher(mockProps, visible);
9
+ mockProps.value = true;
10
+ setTimeout(() => {
11
+ expect(visible.value).toBeTruthy();
12
+ done();
13
+ });
14
+ });
15
+ });
@@ -0,0 +1,10 @@
1
+ import { Ref, watch } from 'vue';
2
+
3
+ export default function (props, visible: Ref) {
4
+ watch(
5
+ () => props.value,
6
+ (newValue: boolean) => {
7
+ visible.value = newValue;
8
+ }
9
+ );
10
+ }
@@ -160,15 +160,17 @@
160
160
  background-color: var(--farm-#{$color}-base);
161
161
  color: white;
162
162
 
163
- ::v-deep .farm-btn__content {
164
- i.mdi {
165
- color: white;
166
- }
167
-
168
- .farm-btn__content i.mdi {
169
- color: black;
163
+ &:not(.farm-btn--outlined):not(.farm-btn--plain):not(.farm-btn--icon) {
164
+ ::v-deep .farm-btn__content {
165
+ i.mdi {
166
+ color: white;
167
+ }
168
+ .farm-btn__content i.mdi {
169
+ color: black;
170
+ }
170
171
  }
171
172
  }
173
+
172
174
  }
173
175
 
174
176
  .farm-btn--extra,
@@ -172,17 +172,17 @@ export const Icons = () => ({
172
172
  template: `<div class="buttons-container">
173
173
  <h4>Full</h4>
174
174
  <farm-btn v-for="color of colors":key="'random_3_' + color" :color="color">
175
- <v-icon>mdi-book</v-icon> book
175
+ <farm-icon>book</farm-icon> book
176
176
  </farm-btn>
177
177
 
178
178
  <h4>Outlined</h4>
179
179
  <farm-btn v-for="color of colors":key="color + 'outlined'" :color="color" outlined>
180
- <v-icon>mdi-book</v-icon> book
180
+ <farm-icon>book</farm-icon> book
181
181
  </farm-btn>
182
182
 
183
183
  <h4>Plain</h4>
184
184
  <farm-btn v-for="color of colors":key="color + 'plain'" :color="color" plain>
185
- <v-icon>mdi-book</v-icon> book
185
+ <farm-icon color="primary">book</farm-icon> book
186
186
  </farm-btn>
187
187
 
188
188
 
@@ -35,8 +35,12 @@ export const Primary = () => ({
35
35
  };
36
36
  },
37
37
  template: `<div style="width: 120px;">
38
- <farm-select v-model="v" :items="items" />
38
+ <farm-label for="select_id">
39
+ label
40
+ </farm-label>
41
+ <farm-select id="select_id" v-model="v" :items="items" />
39
42
  v-model: {{ v }}
43
+
40
44
  </div>`,
41
45
  });
42
46
 
@@ -1,6 +1,5 @@
1
1
  <template>
2
2
  <div
3
- class="farm-textfield"
4
3
  :class="{
5
4
  'farm-textfield': true,
6
5
  'farm-textfield--validatable': rules.length > 0,
@@ -8,10 +7,12 @@
8
7
  'farm-textfield--blured': isBlured,
9
8
  'farm-textfield--error': hasError,
10
9
  'farm-textfield--disabled': disabled,
10
+ 'farm-textfield--hiddendetails': hideDetails,
11
11
  }"
12
12
  v-if="!readonly && !disabled"
13
+ :id="customId"
13
14
  >
14
- <farm-contextmenu bottom v-model="isVisible" :stay-open="multiple">
15
+ <farm-contextmenu bottom v-model="isVisible" :stay-open="multiple" ref="contextmenu">
15
16
  <farm-list v-if="!readonly">
16
17
  <farm-listitem
17
18
  v-for="(item, index) in items"
@@ -28,15 +29,15 @@
28
29
  value="1"
29
30
  size="sm"
30
31
  v-if="isChecked(item)"
31
- ></farm-checkbox>
32
+ />
32
33
  <farm-checkbox
33
34
  class="farm-select__checkbox"
34
35
  v-model="checked"
35
36
  value="2"
36
37
  size="sm"
37
38
  v-else-if="multiple"
38
- ></farm-checkbox
39
- ><farm-caption bold tag="span">{{ item[itemText] }}</farm-caption>
39
+ />
40
+ <farm-caption bold tag="span">{{ item[itemText] }}</farm-caption>
40
41
  </farm-listitem>
41
42
  <farm-listitem v-if="!items || items.length === 0">
42
43
  {{ noDataText }}
@@ -45,9 +46,9 @@
45
46
  <template v-slot:activator="{}">
46
47
  <div class="farm-textfield--input farm-textfield--input--iconed">
47
48
  <input
49
+ v-bind="$attrs"
50
+ :id="$props.id"
48
51
  v-model="selectedText"
49
- :disabled="disabled"
50
- :readonly="true"
51
52
  @click="clickInput"
52
53
  @keyup="onKeyUp"
53
54
  @blur="onBlur"
@@ -74,6 +75,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
74
75
  import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
75
76
  import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
76
77
  import deepEqual from '../../composition/deepEqual';
78
+ import randomId from '../../helpers/randomId';
77
79
 
78
80
  export default Vue.extend({
79
81
  name: 'farm-select',
@@ -144,6 +146,20 @@ export default Vue.extend({
144
146
  type: Boolean,
145
147
  default: false,
146
148
  },
149
+ /**
150
+ * Hides hint and validation errors
151
+ */
152
+ hideDetails: {
153
+ type: Boolean,
154
+ default: false,
155
+ },
156
+ /**
157
+ * Select id
158
+ */
159
+ id: {
160
+ type: String,
161
+ default: '',
162
+ },
147
163
  },
148
164
  setup(props, { emit }) {
149
165
  const { rules, items, itemText, itemValue, disabled, multiple } = toRefs(props);
@@ -165,6 +181,8 @@ export default Vue.extend({
165
181
  return errorBucket.value.length > 0;
166
182
  });
167
183
 
184
+ const customId = 'farm-select-' + (props.id || randomId(2));
185
+
168
186
  const showErrorText = computed(() => hasError.value && isTouched.value);
169
187
 
170
188
  watch(
@@ -326,6 +344,7 @@ export default Vue.extend({
326
344
  isTouched,
327
345
  isBlured,
328
346
  isVisible,
347
+ customId,
329
348
  showErrorText,
330
349
  validate,
331
350
  reset,
@@ -1,6 +1,10 @@
1
1
  .farm-textarea {
2
2
  min-height: 64px;
3
3
 
4
+ &--hiddendetails {
5
+ height: 40px;
6
+ }
7
+
4
8
  &--textarea {
5
9
  display: flex;
6
10
  align-items: center;
@@ -8,16 +8,19 @@
8
8
  'farm-textarea--blured': isBlured,
9
9
  'farm-textarea--error': hasError,
10
10
  'farm-textarea--disabled': disabled,
11
+ 'farm-textarea--hiddendetails': hideDetails,
11
12
  }"
12
13
  >
13
- <div :class="{
14
- 'farm-textarea--textarea': true,
15
- }">
16
-
14
+ <div
15
+ :class="{
16
+ 'farm-textarea--textarea': true,
17
+ }"
18
+ >
17
19
  <textarea
18
- v-bind="$attrs"
19
20
  v-model="innerValue"
20
- :rows="$props.rows"
21
+ v-bind="$attrs"
22
+ :id="$props.id"
23
+ :rows="$props.rows"
21
24
  :disabled="disabled"
22
25
  :readonly="readonly"
23
26
  @click="$emit('click')"
@@ -40,6 +43,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
40
43
  import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
41
44
  import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
42
45
  import deepEqual from '../../composition/deepEqual';
46
+ import randomId from '../../helpers/randomId';
43
47
 
44
48
  export default Vue.extend({
45
49
  name: 'farm-textarea',
@@ -79,13 +83,27 @@ export default Vue.extend({
79
83
  type: Array as PropType<Array<Function>>,
80
84
  default: () => [],
81
85
  },
82
- /**
83
- * Textarea rows
84
- */
85
- rows: {
86
- default: 5,
87
- type: [String, Number],
88
- }
86
+ /**
87
+ * Textarea rows
88
+ */
89
+ rows: {
90
+ default: 5,
91
+ type: [String, Number],
92
+ },
93
+ /**
94
+ * Hides hint and validation errors
95
+ */
96
+ hideDetails: {
97
+ type: Boolean,
98
+ default: false,
99
+ },
100
+ /**
101
+ * Select id
102
+ */
103
+ id: {
104
+ type: String,
105
+ default: '',
106
+ },
89
107
  },
90
108
  setup(props, { emit }) {
91
109
  const { rules } = toRefs(props);
@@ -100,6 +118,7 @@ export default Vue.extend({
100
118
  const hasError = computed(() => {
101
119
  return errorBucket.value.length > 0;
102
120
  });
121
+ const customId = 'farm-textarea-' + (props.id || randomId(2));
103
122
 
104
123
  const showErrorText = computed(() => hasError.value && isTouched.value);
105
124
 
@@ -162,6 +181,7 @@ export default Vue.extend({
162
181
  valid,
163
182
  validatable,
164
183
  hasError,
184
+ customId,
165
185
  isTouched,
166
186
  isBlured,
167
187
  showErrorText,
@@ -1,6 +1,10 @@
1
1
  .farm-textfield {
2
2
  height: 64px;
3
3
 
4
+ &--hiddendetails {
5
+ height: 40px;
6
+ }
7
+
4
8
  &--input {
5
9
  display: flex;
6
10
  align-items: center;
@@ -39,7 +39,10 @@ export const Primary = () => ({
39
39
  };
40
40
  },
41
41
  template: `<div style="width: 480px;">
42
- <farm-textfield-v2 v-model="v" />
42
+ <farm-label for="select_label">
43
+ label
44
+ </farm-label>
45
+ <farm-textfield-v2 id="select_label" v-model="v" />
43
46
  v-model: {{ v }}
44
47
  </div>`,
45
48
  });
@@ -8,12 +8,16 @@
8
8
  'farm-textfield--blured': isBlured,
9
9
  'farm-textfield--error': hasError,
10
10
  'farm-textfield--disabled': disabled,
11
+ 'farm-textfield--hiddendetails': hideDetails,
11
12
  }"
13
+ :id="customId"
12
14
  >
13
- <div :class="{
14
- 'farm-textfield--input': true,
15
- 'farm-textfield--input--iconed': icon
16
- }">
15
+ <div
16
+ :class="{
17
+ 'farm-textfield--input': true,
18
+ 'farm-textfield--input--iconed': icon,
19
+ }"
20
+ >
17
21
  <button
18
22
  type="button"
19
23
  v-if="icon && iconPosition === 'left'"
@@ -24,7 +28,8 @@
24
28
  <input
25
29
  v-bind="$attrs"
26
30
  v-model="innerValue"
27
- v-mask="mask"
31
+ v-mask="mask"
32
+ :id="$props.id"
28
33
  :disabled="disabled"
29
34
  :readonly="readonly"
30
35
  @click="$emit('click')"
@@ -39,10 +44,14 @@
39
44
  <farm-icon color="gray" size="20px">{{ icon }}</farm-icon>
40
45
  </button>
41
46
  </div>
42
- <farm-caption v-if="showErrorText" color="error" variation="regular">
47
+ <farm-caption v-if="!hideDetails && showErrorText" color="error" variation="regular">
43
48
  {{ errorBucket[0] }}
44
49
  </farm-caption>
45
- <farm-caption v-if="hint && !showErrorText" color="gray" variation="regular">
50
+ <farm-caption
51
+ v-if="!hideDetails && hint && !showErrorText"
52
+ color="gray"
53
+ variation="regular"
54
+ >
46
55
  {{ hint }}
47
56
  </farm-caption>
48
57
  </div>
@@ -54,6 +63,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
54
63
  import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
55
64
  import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
56
65
  import deepEqual from '../../composition/deepEqual';
66
+ import randomId from '../../helpers/randomId';
57
67
 
58
68
  export default Vue.extend({
59
69
  name: 'farm-textfield-v2',
@@ -111,6 +121,20 @@ export default Vue.extend({
111
121
  default: '',
112
122
  type: [String, Function],
113
123
  },
124
+ /**
125
+ * Hides hint and validation errors
126
+ */
127
+ hideDetails: {
128
+ type: Boolean,
129
+ default: false,
130
+ },
131
+ /**
132
+ * Input id
133
+ */
134
+ id: {
135
+ type: String,
136
+ default: '',
137
+ },
114
138
  },
115
139
  setup(props, { emit }) {
116
140
  const { rules } = toRefs(props);
@@ -125,6 +149,7 @@ export default Vue.extend({
125
149
  const hasError = computed(() => {
126
150
  return errorBucket.value.length > 0;
127
151
  });
152
+ const customId = 'farm-textfield-' + (props.id || randomId(2));
128
153
 
129
154
  const showErrorText = computed(() => hasError.value && isTouched.value);
130
155
 
@@ -187,6 +212,7 @@ export default Vue.extend({
187
212
  valid,
188
213
  validatable,
189
214
  hasError,
215
+ customId,
190
216
  isTouched,
191
217
  isBlured,
192
218
  showErrorText,
@@ -0,0 +1,9 @@
1
+ export default (length: number) => {
2
+ let text = '';
3
+ const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
4
+
5
+ for (let i = 0; i < length; i++) {
6
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
7
+ }
8
+ return text;
9
+ };