@farm-investimentos/front-mfe-components 15.4.8 → 15.5.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 +1527 -1487
- 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 +1527 -1487
- 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/DatePicker/DatePicker.stories.js +17 -0
- package/src/components/DatePicker/DatePicker.vue +52 -9
- package/src/components/DatePicker/__tests__/DatePicker.spec.js +55 -2
- package/src/components/TextFieldV2/TextFieldV2.scss +6 -0
- package/src/components/TextFieldV2/TextFieldV2.vue +8 -0
- package/src/helpers/date.js +1 -1
package/package.json
CHANGED
|
@@ -129,4 +129,21 @@ export const CenterPositioned = () => ({
|
|
|
129
129
|
<farm-input-datepicker inputId="input-custom-id-0" v-model="date" position="center" />
|
|
130
130
|
{{ date }}
|
|
131
131
|
</div>`,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export const MultipleDates = () => ({
|
|
135
|
+
data() {
|
|
136
|
+
return {
|
|
137
|
+
date: [],
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
computed: {
|
|
141
|
+
dates() {
|
|
142
|
+
return this.date.join(' /// ');
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
template: `<div style='max-width: 320px'>
|
|
146
|
+
<farm-input-datepicker inputId="input-custom-id-0" v-model="date" multiple />
|
|
147
|
+
{{ dates }}
|
|
148
|
+
</div>`,
|
|
132
149
|
});
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
:min="min"
|
|
22
22
|
:allowed-dates="allowedDates"
|
|
23
23
|
:picker-date.sync="internalPickerDate"
|
|
24
|
+
:multiple="multiple"
|
|
24
25
|
>
|
|
25
26
|
<farm-btn plain title="Limpar" color="primary" :disabled="isDisabled" @click="clear">
|
|
26
27
|
Limpar
|
|
@@ -44,10 +45,11 @@
|
|
|
44
45
|
v-model="fieldRange"
|
|
45
46
|
autocomplete="off"
|
|
46
47
|
ref="inputCalendar"
|
|
47
|
-
:
|
|
48
|
-
:
|
|
48
|
+
:ellipsed="multiple"
|
|
49
|
+
:readonly="isReadonly"
|
|
50
|
+
:mask="`${isReadonly ? '' : '##/##/####'}`"
|
|
49
51
|
:id="inputId"
|
|
50
|
-
:rules="
|
|
52
|
+
:rules="rules"
|
|
51
53
|
@keyup="keyUpInput"
|
|
52
54
|
/>
|
|
53
55
|
</template>
|
|
@@ -82,7 +84,7 @@ export default defineComponent({
|
|
|
82
84
|
* v-model bind
|
|
83
85
|
*/
|
|
84
86
|
value: {
|
|
85
|
-
type: String,
|
|
87
|
+
type: [String, Array],
|
|
86
88
|
default: '',
|
|
87
89
|
},
|
|
88
90
|
/**
|
|
@@ -131,6 +133,10 @@ export default defineComponent({
|
|
|
131
133
|
type: Boolean,
|
|
132
134
|
default: false,
|
|
133
135
|
},
|
|
136
|
+
multiple: {
|
|
137
|
+
type: Boolean,
|
|
138
|
+
default: false,
|
|
139
|
+
},
|
|
134
140
|
},
|
|
135
141
|
data() {
|
|
136
142
|
const s = this.formatDateRange(this.value);
|
|
@@ -147,7 +153,9 @@ export default defineComponent({
|
|
|
147
153
|
return true;
|
|
148
154
|
},
|
|
149
155
|
checkRequire: value => {
|
|
150
|
-
return this.required
|
|
156
|
+
return this.required
|
|
157
|
+
? !!value || value.length > 0 || value != '' || 'Campo obrigatório'
|
|
158
|
+
: true;
|
|
151
159
|
},
|
|
152
160
|
checkMax: value => {
|
|
153
161
|
if (!this.required && value.length === 0) {
|
|
@@ -189,14 +197,24 @@ export default defineComponent({
|
|
|
189
197
|
},
|
|
190
198
|
fieldRange(newValue) {
|
|
191
199
|
if (!newValue) {
|
|
192
|
-
this.dateField = '';
|
|
200
|
+
this.dateField = this.multiple ? [] : '';
|
|
193
201
|
this.save();
|
|
194
202
|
}
|
|
195
203
|
},
|
|
196
204
|
},
|
|
197
205
|
methods: {
|
|
198
|
-
formatDateRange(date) {
|
|
206
|
+
formatDateRange(date: string | string[]) {
|
|
199
207
|
if (!date || date.length === 0) return '';
|
|
208
|
+
|
|
209
|
+
if (this.multiple) {
|
|
210
|
+
let dateString = [...date]
|
|
211
|
+
.sort((a, b) => +new Date(a) - +new Date(b))
|
|
212
|
+
.map(dateDefaultFormatter)
|
|
213
|
+
.join(', ');
|
|
214
|
+
|
|
215
|
+
return dateString;
|
|
216
|
+
}
|
|
217
|
+
|
|
200
218
|
return dateDefaultFormatter(date);
|
|
201
219
|
},
|
|
202
220
|
save() {
|
|
@@ -206,7 +224,7 @@ export default defineComponent({
|
|
|
206
224
|
this.closeDatepicker();
|
|
207
225
|
},
|
|
208
226
|
clear() {
|
|
209
|
-
this.dateField = '';
|
|
227
|
+
this.dateField = this.multiple ? [] : '';
|
|
210
228
|
this.save();
|
|
211
229
|
this.$refs.inputCalendar.reset();
|
|
212
230
|
},
|
|
@@ -217,9 +235,12 @@ export default defineComponent({
|
|
|
217
235
|
},
|
|
218
236
|
keyUpInput(event) {
|
|
219
237
|
let newValue = event.target.value;
|
|
238
|
+
|
|
220
239
|
if (this.validation(newValue) && newValue.length === 10) {
|
|
221
240
|
const [day, month, year] = newValue.split('/');
|
|
222
|
-
|
|
241
|
+
const formattedDate = `${year}-${month}-${day}`;
|
|
242
|
+
|
|
243
|
+
this.dateField = this.multiple ? [formattedDate] : formattedDate;
|
|
223
244
|
this.save();
|
|
224
245
|
}
|
|
225
246
|
},
|
|
@@ -259,6 +280,28 @@ export default defineComponent({
|
|
|
259
280
|
}
|
|
260
281
|
return true;
|
|
261
282
|
},
|
|
283
|
+
rules() {
|
|
284
|
+
const allRules = [
|
|
285
|
+
this.checkDateValid,
|
|
286
|
+
this.checkMax,
|
|
287
|
+
this.checkMin,
|
|
288
|
+
this.checkRequire,
|
|
289
|
+
this.checkIsInAllowedDates,
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
if (this.multiple) {
|
|
293
|
+
if (!this.inputVal.length && this.required) {
|
|
294
|
+
return allRules.map(rule => rule.call(this, ''));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return this.inputVal.flatMap(date => allRules.map(rule => rule.call(this, date)));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return allRules;
|
|
301
|
+
},
|
|
302
|
+
isReadonly() {
|
|
303
|
+
return this.readonly || this.multiple;
|
|
304
|
+
},
|
|
262
305
|
},
|
|
263
306
|
});
|
|
264
307
|
</script>
|
|
@@ -4,6 +4,7 @@ import DatePicker from '../DatePicker';
|
|
|
4
4
|
describe('DatePicker component', () => {
|
|
5
5
|
let wrapper;
|
|
6
6
|
let component;
|
|
7
|
+
const ALL_RULES_LENGTH = 5;
|
|
7
8
|
|
|
8
9
|
beforeEach(() => {
|
|
9
10
|
wrapper = shallowMount(DatePicker, {
|
|
@@ -84,12 +85,48 @@ describe('DatePicker component', () => {
|
|
|
84
85
|
});
|
|
85
86
|
|
|
86
87
|
it('should allow only dates in year 2077', async () => {
|
|
88
|
+
const YEAR_TO_TEST = 2077;
|
|
89
|
+
|
|
87
90
|
await wrapper.setProps({
|
|
88
|
-
allowedDates: (value) => new Date(value).getFullYear() ===
|
|
91
|
+
allowedDates: (value) => new Date(value).getFullYear() === YEAR_TO_TEST
|
|
89
92
|
});
|
|
90
|
-
expect(component.checkIsInAllowedDates(
|
|
93
|
+
expect(component.checkIsInAllowedDates(`${YEAR_TO_TEST}-05-03`)).toBe(true);
|
|
91
94
|
expect(component.checkIsInAllowedDates('2023-05-03')).toBe('Data inválida');
|
|
92
95
|
});
|
|
96
|
+
|
|
97
|
+
it('should be readonly if is multiple', async () => {
|
|
98
|
+
await wrapper.setProps({
|
|
99
|
+
multiple: true
|
|
100
|
+
});
|
|
101
|
+
expect(component.isReadonly).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should have 5 rules if is not multiple', async () => {
|
|
105
|
+
await wrapper.setProps({
|
|
106
|
+
value: ''
|
|
107
|
+
});
|
|
108
|
+
expect(component.rules.length).toBe(ALL_RULES_LENGTH);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should have 5 rules if is multiple picker, is required and no value is selected', async () => {
|
|
112
|
+
await wrapper.setProps({
|
|
113
|
+
multiple: true,
|
|
114
|
+
required: true,
|
|
115
|
+
value: []
|
|
116
|
+
});
|
|
117
|
+
expect(component.rules.length).toBe(ALL_RULES_LENGTH);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should have 10 rules if is multiple picker, is required and 2 dates are selected', async () => {
|
|
121
|
+
const value = ['2023-05-10', '2032-05-12'];
|
|
122
|
+
|
|
123
|
+
await wrapper.setProps({
|
|
124
|
+
multiple: true,
|
|
125
|
+
required: true,
|
|
126
|
+
value
|
|
127
|
+
});
|
|
128
|
+
expect(component.rules.length).toBe(value.length * ALL_RULES_LENGTH);
|
|
129
|
+
});
|
|
93
130
|
});
|
|
94
131
|
|
|
95
132
|
describe('methods', () => {
|
|
@@ -102,5 +139,21 @@ describe('DatePicker component', () => {
|
|
|
102
139
|
component.closeDatepicker();
|
|
103
140
|
expect(component.menuField).toBeFalsy();
|
|
104
141
|
});
|
|
142
|
+
|
|
143
|
+
it('should use formatDateRange to format a date', async () => {
|
|
144
|
+
const value = '2023-10-10';
|
|
145
|
+
|
|
146
|
+
expect(component.formatDateRange(value)).toBe('10/10/2023');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should use formatDateRange to format multiple dates', async () => {
|
|
150
|
+
const value = ['2023-10-10', '2023-10-15'];
|
|
151
|
+
|
|
152
|
+
await wrapper.setProps({
|
|
153
|
+
multiple: true,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(component.formatDateRange(value)).toBe('10/10/2023, 15/10/2023');
|
|
157
|
+
});
|
|
105
158
|
});
|
|
106
159
|
});
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
'farm-textfield--disabled': disabled,
|
|
12
12
|
'farm-textfield--hiddendetails': hideDetails,
|
|
13
13
|
'farm-textfield--uppercase': isUppercase,
|
|
14
|
+
'farm-textfield--ellipsed': ellipsed,
|
|
14
15
|
}"
|
|
15
16
|
:id="customId"
|
|
16
17
|
>
|
|
@@ -168,6 +169,13 @@ export default defineComponent({
|
|
|
168
169
|
// eslint-disable-next-line
|
|
169
170
|
default: (event: Event) => {},
|
|
170
171
|
},
|
|
172
|
+
/**
|
|
173
|
+
* Used for hide too much content inside input
|
|
174
|
+
*/
|
|
175
|
+
ellipsed: {
|
|
176
|
+
type: Boolean,
|
|
177
|
+
default: false,
|
|
178
|
+
},
|
|
171
179
|
},
|
|
172
180
|
setup(props, { emit }) {
|
|
173
181
|
const { rules } = toRefs(props);
|
package/src/helpers/date.js
CHANGED
|
@@ -2,7 +2,7 @@ export const defaultFormat = (data, UTCTimeZone = true) => {
|
|
|
2
2
|
const options = {
|
|
3
3
|
timeZone: 'UTC',
|
|
4
4
|
};
|
|
5
|
-
return data ? new Date(data).toLocaleDateString('pt-BR', UTCTimeZone ? options : {}) : null;
|
|
5
|
+
return data ? new Date(`${data} 00:00`).toLocaleDateString('pt-BR', UTCTimeZone ? options : {}) : null;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export const convertDate = (data) => {
|