@farm-investimentos/front-mfe-components 11.7.2 → 11.8.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 +531 -133
- 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 +531 -133
- 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/AlertBox/AlertBox.scss +45 -0
- package/src/components/AlertBox/AlertBox.stories.js +30 -1
- package/src/components/AlertBox/AlertBox.vue +66 -9
- package/src/components/DialogHeader/DialogHeader.scss +7 -1
- package/src/components/Form/Form.stories.js +35 -1
- package/src/components/Form/Form.vue +1 -1
- package/src/components/Icon/Icon.scss +27 -20
- package/src/components/Icon/Icon.stories.js +26 -0
- package/src/components/Icon/Icon.vue +6 -0
- package/src/components/Modal/Modal.scss +0 -6
- package/src/components/Select/Select.scss +13 -0
- package/src/components/Select/Select.stories.js +142 -0
- package/src/components/Select/Select.vue +229 -0
- package/src/components/Select/__tests__/Select.spec.js +35 -0
- package/src/components/Select/index.ts +4 -0
- package/src/components/TextFieldV2/TextFieldV2.stories.js +1 -1
- 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,35 @@
|
|
|
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
|
+
});
|
|
@@ -26,7 +26,7 @@ export default {
|
|
|
26
26
|
},
|
|
27
27
|
design: {
|
|
28
28
|
type: 'figma',
|
|
29
|
-
url: 'https://www.figma.com/file/
|
|
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';
|