@farm-investimentos/front-mfe-components 15.4.8 → 15.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "15.4.8",
3
+ "version": "15.5.1",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -150,6 +150,22 @@ export const Dense = () => ({
150
150
  '<farm-collapsible icon="plus" title="With Icon" textChip="chip" dense showChip>collapsible content</farm-collapsible>',
151
151
  });
152
152
 
153
+ export const Custom = () => ({
154
+ template: `
155
+ <farm-collapsible custom>
156
+ <template #custom>
157
+ <farm-btn
158
+ v-bind="attrs"
159
+ v-on="on"
160
+ >
161
+ custom
162
+ </farm-btn>
163
+ </template>
164
+ collapsible content
165
+ </farm-collapsible>
166
+ `,
167
+ });
168
+
153
169
  Primary.storyName = 'Basic';
154
170
  Title.storyName = 'Title';
155
171
  Icon.storyName = 'Icon';
@@ -3,23 +3,24 @@
3
3
  <farm-card-content gutter="md">
4
4
  <div class="collapsible__header" @click="onToggleCollapsible(status)">
5
5
  <div class="collapsible__content-title">
6
- <div class="collapsible__icon collapsible__icon--main" v-if="icon !== ''">
6
+ <div class="collapsible__icon collapsible__icon--main" v-if="icon !== '' && !custom">
7
7
  <farm-icon size="md" :color="colorIcon">
8
8
  {{ icon }}
9
9
  </farm-icon>
10
10
  </div>
11
- <farm-heading type="6" color="black">
11
+ <farm-heading type="6" color="black" v-if="!custom">
12
12
  {{ title }}
13
13
  </farm-heading>
14
14
  <farm-btn
15
15
  outlined
16
16
  class="ml-6"
17
- v-if="hasButton"
17
+ v-if="hasButton && !custom"
18
18
  :disabled="disabledButton"
19
19
  @click.stop="onClick()"
20
20
  >
21
21
  {{ labelButton }}
22
22
  </farm-btn>
23
+ <slot name="custom" v-if="custom"></slot>
23
24
  </div>
24
25
  <div class="collapsible__content-right">
25
26
  <div class="collapsible__icon" v-if="showChip">
@@ -175,6 +176,10 @@ export default defineComponent({
175
176
  type: String,
176
177
  default: 'base',
177
178
  },
179
+ custom: {
180
+ type: Boolean,
181
+ default: false,
182
+ },
178
183
  },
179
184
 
180
185
  data() {
@@ -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
- :readonly="readonly"
48
- :mask="`${readonly ? '' : '##/##/####'}`"
48
+ :ellipsed="multiple"
49
+ :readonly="isReadonly"
50
+ :mask="`${isReadonly ? '' : '##/##/####'}`"
49
51
  :id="inputId"
50
- :rules="[checkDateValid, checkMax, checkMin, checkRequire, checkIsInAllowedDates]"
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 ? !!value || value != '' || 'Campo obrigatório' : true;
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
- this.dateField = `${year}-${month}-${day}`;
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() === 2077
91
+ allowedDates: (value) => new Date(value).getFullYear() === YEAR_TO_TEST
89
92
  });
90
- expect(component.checkIsInAllowedDates('2077-05-03')).toBe(true);
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
  });
@@ -3,6 +3,12 @@
3
3
  .farm-textfield {
4
4
  height: 64px;
5
5
 
6
+ &--ellipsed {
7
+ input {
8
+ text-overflow: ellipsis;
9
+ }
10
+ }
11
+
6
12
  &--hiddendetails {
7
13
  height: 40px;
8
14
  }
@@ -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);
@@ -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) => {