@farm-investimentos/front-mfe-components 11.7.3 → 11.8.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.
Files changed (33) hide show
  1. package/dist/front-mfe-components.common.js +701 -300
  2. package/dist/front-mfe-components.common.js.map +1 -1
  3. package/dist/front-mfe-components.css +1 -1
  4. package/dist/front-mfe-components.umd.js +701 -300
  5. package/dist/front-mfe-components.umd.js.map +1 -1
  6. package/dist/front-mfe-components.umd.min.js +1 -1
  7. package/dist/front-mfe-components.umd.min.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/components/AlertBox/AlertBox.scss +45 -0
  10. package/src/components/AlertBox/AlertBox.stories.js +30 -1
  11. package/src/components/AlertBox/AlertBox.vue +66 -9
  12. package/src/components/DialogHeader/DialogHeader.scss +7 -1
  13. package/src/components/DialogHeader/DialogHeader.vue +1 -0
  14. package/src/components/Form/Form.stories.js +35 -1
  15. package/src/components/Icon/Icon.scss +27 -20
  16. package/src/components/Icon/Icon.stories.js +26 -0
  17. package/src/components/Icon/Icon.vue +6 -0
  18. package/src/components/IdCaption/IdCaption.scss +9 -3
  19. package/src/components/IdCaption/IdCaption.stories.js +18 -0
  20. package/src/components/IdCaption/IdCaption.vue +7 -1
  21. package/src/components/Modal/Modal.scss +0 -6
  22. package/src/components/Modal/Modal.vue +1 -1
  23. package/src/components/MultipleFilePicker/MultipleFilePicker.vue +9 -5
  24. package/src/components/Select/Select.scss +18 -0
  25. package/src/components/Select/Select.stories.js +142 -0
  26. package/src/components/Select/Select.vue +229 -0
  27. package/src/components/Select/__tests__/Select.spec.js +40 -0
  28. package/src/components/Select/index.ts +4 -0
  29. package/src/components/TableContextMenu/TableContextMenu.scss +5 -15
  30. package/src/components/TableContextMenu/TableContextMenu.stories.js +11 -2
  31. package/src/components/TableContextMenu/TableContextMenu.vue +19 -3
  32. package/src/components/TextFieldV2/TextFieldV2.stories.js +1 -1
  33. package/src/main.ts +1 -0
@@ -0,0 +1,229 @@
1
+ <template>
2
+ <div
3
+ class="farm-textfield"
4
+ :class="{
5
+ 'farm-textfield': true,
6
+ 'farm-textfield--validatable': rules.length > 0,
7
+ 'farm-textfield--touched': isTouched,
8
+ 'farm-textfield--blured': isBlured,
9
+ 'farm-textfield--error': hasError,
10
+ 'farm-textfield--disabled': disabled,
11
+ }"
12
+ v-if="!readonly && !disabled"
13
+ >
14
+ <farm-contextmenu bottom v-model="isVisible">
15
+ <farm-list v-if="!readonly">
16
+ <farm-listitem
17
+ v-for="item in items"
18
+ clickable
19
+ hoverColorVariation="lighten"
20
+ hover-color="primary"
21
+ :key="'contextmenu_item_' + item.text"
22
+ :class="{ 'farm-listitem--selected': item[itemValue] === innerValue }"
23
+ @click="selectItem(item)"
24
+ >
25
+ <farm-caption bold tag="span">{{ item[itemText] }}</farm-caption>
26
+ </farm-listitem>
27
+ </farm-list>
28
+ <template v-slot:activator="{}">
29
+ <div class="farm-textfield--input">
30
+ <input
31
+ v-model="selectedText"
32
+ :disabled="disabled"
33
+ :readonly="true"
34
+ @click="clickInput"
35
+ @keyup="onKeyUp"
36
+ @blur="onBlur"
37
+ />
38
+ <farm-icon color="gray" :class="{ 'farm-icon--rotate': isVisible }">
39
+ menu-down
40
+ </farm-icon>
41
+ </div>
42
+ </template>
43
+ </farm-contextmenu>
44
+
45
+ <farm-caption v-if="showErrorText" color="error" variation="regular">
46
+ {{ errorBucket[0] }}
47
+ </farm-caption>
48
+ <farm-caption v-if="hint && !showErrorText" color="gray" variation="regular">
49
+ {{ hint }}
50
+ </farm-caption>
51
+ </div>
52
+ <farm-textfield-v2 v-else v-model="selectedText" :disabled="disabled" :readonly="readonly" />
53
+ </template>
54
+
55
+ <script lang="ts">
56
+ import Vue, { computed, onBeforeMount, PropType, ref, toRefs, watch } from 'vue';
57
+ import validateFormStateBuilder from '../../composition/validateFormStateBuilder';
58
+ import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
59
+ import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
60
+ import deepEqual from '../../composition/deepEqual';
61
+
62
+ export default Vue.extend({
63
+ name: 'farm-select',
64
+ inheritAttrs: true,
65
+ props: {
66
+ /**
67
+ * v-model binding
68
+ */
69
+ value: { type: [String, Number], default: '' },
70
+ hint: {
71
+ type: String,
72
+ default: null,
73
+ },
74
+ /**
75
+ * Disabled the input
76
+ */
77
+ disabled: {
78
+ type: Boolean,
79
+ default: false,
80
+ },
81
+ /**
82
+ * Puts input in readonly state
83
+ */
84
+ readonly: {
85
+ type: Boolean,
86
+ default: false,
87
+ },
88
+
89
+ errorMessage: String,
90
+ /**
91
+ * Array of rules used for validation
92
+ */
93
+ rules: {
94
+ type: Array as PropType<Array<Function>>,
95
+ default: () => [],
96
+ },
97
+ /**
98
+ * An array of objects. Will look for a text, value and disabled keys.
99
+ * This can be changed using the item-text ad item-value
100
+ */
101
+ items: {
102
+ type: Array,
103
+ default: () => [],
104
+ },
105
+ /**
106
+ * Set property of items's text value
107
+ */
108
+ itemText: {
109
+ type: String,
110
+ default: 'text',
111
+ },
112
+ /**
113
+ * Set property of items's value
114
+ */
115
+ itemValue: {
116
+ type: String,
117
+ default: 'value',
118
+ },
119
+ },
120
+ setup(props, { emit }) {
121
+ const { rules, items, itemText, itemValue } = toRefs(props);
122
+ const innerValue = ref(props.value);
123
+ const isTouched = ref(false);
124
+ const isBlured = ref(false);
125
+ const isVisible = ref(false);
126
+ const selectedText = ref('');
127
+
128
+ const { errorBucket, valid, validatable } = validateFormStateBuilder();
129
+
130
+ let fieldValidator = validateFormFieldBuilder(rules.value);
131
+
132
+ const hasError = computed(() => {
133
+ return errorBucket.value.length > 0;
134
+ });
135
+
136
+ const showErrorText = computed(() => hasError.value && isTouched.value);
137
+
138
+ watch(
139
+ () => props.value,
140
+ () => {
141
+ innerValue.value = props.value;
142
+ validate(innerValue.value);
143
+ }
144
+ );
145
+
146
+ watch(
147
+ () => innerValue.value,
148
+ () => {
149
+ isTouched.value = true;
150
+ isBlured.value = true;
151
+ emit('input', innerValue.value);
152
+ emit('change', innerValue.value);
153
+ }
154
+ );
155
+
156
+ watch(
157
+ () => props.rules,
158
+ (newVal, oldVal) => {
159
+ if (deepEqual(newVal, oldVal)) return;
160
+ fieldValidator = validateFormFieldBuilder(rules.value);
161
+ validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
162
+ validate(innerValue.value);
163
+ }
164
+ );
165
+
166
+ onBeforeMount(() => {
167
+ validate(innerValue.value);
168
+ const selectedItem = items.value.find(
169
+ item => item[itemValue.value] === innerValue.value
170
+ );
171
+ if (selectedItem) {
172
+ selectedText.value = selectedItem[itemText.value];
173
+ }
174
+ });
175
+
176
+ let validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
177
+
178
+ const reset = () => {
179
+ innerValue.value = '';
180
+ selectedText.value = '';
181
+ isTouched.value = true;
182
+ emit('input', innerValue.value);
183
+ };
184
+
185
+ const onKeyUp = (event: Event) => {
186
+ emit('keyup', event);
187
+ };
188
+
189
+ const onBlur = (event: Event) => {
190
+ isBlured.value = true;
191
+ validate(innerValue.value);
192
+ emit('blur', event);
193
+ };
194
+
195
+ const selectItem = item => {
196
+ selectedText.value = item[itemText.value];
197
+ innerValue.value = item[itemValue.value];
198
+ };
199
+
200
+ const clickInput = () => {
201
+ isTouched.value = true;
202
+ emit('click');
203
+ };
204
+
205
+ return {
206
+ items,
207
+ innerValue,
208
+ selectedText,
209
+ errorBucket,
210
+ valid,
211
+ validatable,
212
+ hasError,
213
+ isTouched,
214
+ isBlured,
215
+ isVisible,
216
+ showErrorText,
217
+ validate,
218
+ reset,
219
+ selectItem,
220
+ onKeyUp,
221
+ onBlur,
222
+ clickInput,
223
+ };
224
+ },
225
+ });
226
+ </script>
227
+ <style lang="scss" scoped>
228
+ @import 'Select';
229
+ </style>
@@ -0,0 +1,40 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import Select from '../Select';
3
+
4
+ describe('Select component', () => {
5
+ let wrapper;
6
+ let component;
7
+
8
+ beforeEach(() => {
9
+ wrapper = shallowMount(Select);
10
+ component = wrapper.vm;
11
+ });
12
+
13
+ test('Created hook', () => {
14
+ expect(wrapper).toBeDefined();
15
+ });
16
+
17
+ describe('mount component', () => {
18
+ it('renders correctly', () => {
19
+ expect(wrapper.element).toMatchSnapshot();
20
+ });
21
+ });
22
+
23
+ describe('methods', () => {
24
+ it('reset', () => {
25
+ component.reset();
26
+ expect(component.isTouched).toBeTruthy();
27
+ expect(component.innerValue).toEqual('');
28
+ });
29
+
30
+ it('onBlur', () => {
31
+ component.onBlur();
32
+ expect(component.isBlured).toBeTruthy();
33
+ });
34
+
35
+ it('clickInput', () => {
36
+ component.clickInput();
37
+ expect(component.isTouched).toBeTruthy();
38
+ });
39
+ });
40
+ });
@@ -0,0 +1,4 @@
1
+ import Select from './Select.vue';
2
+
3
+ export { Select };
4
+ export default Select;
@@ -1,17 +1,7 @@
1
- .v-list-item.v-list-item--link {
2
- border-bottom: 1px solid var(--farm-stroke-base);
3
- }
4
-
5
- .v-list-item__title {
6
- display: flex;
7
- align-items: center;
8
-
9
-
10
- }
11
-
12
- ::v-deep .v-application--wrap {
13
- min-height: auto;
14
- font-family: 'Montserrat', sans-serif !important;
1
+ .farm-context-menu {
2
+ &--disabled {
3
+ pointer-events: none;
4
+ }
15
5
  }
16
6
 
17
7
  .farm-listitem {
@@ -21,4 +11,4 @@
21
11
  vertical-align: sub;
22
12
  margin-right: 8px;
23
13
  }
24
- }
14
+ }
@@ -28,6 +28,12 @@ export const Primary = () => ({
28
28
  </div>`,
29
29
  });
30
30
 
31
+ export const Disabled = () => ({
32
+ template: `<div style="padding-left: 80px">
33
+ <farm-context-menu disabled :items="[{ label: 'Remover', icon: { color: 'error', type: 'open-in-new' } }]" />
34
+ </div>`,
35
+ });
36
+
31
37
  export const Icons = () => ({
32
38
  template: `<div style="padding-left: 80px">
33
39
  <farm-context-menu
@@ -70,7 +76,10 @@ export const OnRightSide = () => ({
70
76
  return {
71
77
  items: [
72
78
  { label: 'Novo', icon: { type: 'open-in-new' } },
73
- { label: 'Nome bem longo sem quebrar linha', icon: { color: 'secondary', type: 'open-in-new' } },
79
+ {
80
+ label: 'Nome bem longo sem quebrar linha',
81
+ icon: { color: 'secondary', type: 'open-in-new' },
82
+ },
74
83
  { label: 'Remover', icon: { color: 'error', type: 'delete' } },
75
84
  ],
76
85
  };
@@ -78,4 +87,4 @@ export const OnRightSide = () => ({
78
87
  template: `<div style="padding-left: 80px; display: flex; justify-content: end;">
79
88
  <farm-context-menu ref="multi" :items="items" />
80
89
  </div>`,
81
- });
90
+ });
@@ -1,7 +1,16 @@
1
1
  <template>
2
- <farm-contextmenu v-model="value">
3
- <template v-slot:activator="{}">
4
- <farm-btn icon @click="toggleValue" title="Abrir opções" color="secondary">
2
+ <farm-contextmenu
3
+ :class="{ 'farm-context-menu': true, 'farm-context-menu--disabled': disabled }"
4
+ v-model="value"
5
+ >
6
+ <template v-slot:activator>
7
+ <farm-btn
8
+ icon
9
+ title="Abrir opções"
10
+ color="secondary"
11
+ :disabled="disabled"
12
+ @click="toggleValue"
13
+ >
5
14
  <farm-icon size="md">dots-horizontal</farm-icon>
6
15
  </farm-btn>
7
16
  </template>
@@ -47,6 +56,13 @@ export default Vue.extend({
47
56
  type: Array as PropType<Array<IContextMenuOption>>,
48
57
  required: true,
49
58
  },
59
+ /**
60
+ * Is disabled?
61
+ */
62
+ disabled: {
63
+ type: Boolean,
64
+ default: false,
65
+ },
50
66
  },
51
67
  data() {
52
68
  return {
@@ -26,7 +26,7 @@ export default {
26
26
  },
27
27
  design: {
28
28
  type: 'figma',
29
- url: 'https://www.figma.com/file/1f84J4m1IBghWhozQvdyyt/%E2%9C%85---Design-System-%7C-v1?node-id=1503%3A227',
29
+ url: 'https://www.figma.com/file/jnZXo2e0nRJ3fVXl4Et8t4/%E2%9C%8D-Design-System-%7C-BACKUP-(10%2F10%2F2022)?node-id=2491%3A4487',
30
30
  },
31
31
  viewMode: 'docs',
32
32
  },
package/src/main.ts CHANGED
@@ -83,6 +83,7 @@ export * from './components/Icon';
83
83
  export * from './components/Modal';
84
84
  export * from './components/ProgressBar';
85
85
  export * from './components/RadioGroup';
86
+ export * from './components/Select';
86
87
  export * from './components/Stepper';
87
88
  export * from './components/Switcher';
88
89
  export * from './components/TextField';