@weni/unnnic-system 2.34.1-alpha.3 → 2.35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weni/unnnic-system",
3
- "version": "2.34.1-alpha.3",
3
+ "version": "2.35.0",
4
4
  "type": "commonjs",
5
5
  "files": [
6
6
  "dist",
@@ -87,4 +87,4 @@
87
87
  "vitest": "^1.6.0",
88
88
  "vue-eslint-parser": "^9.4.2"
89
89
  }
90
- }
90
+ }
@@ -9,7 +9,7 @@
9
9
  <div :class="['header', `header--${size}`]">
10
10
  <UnnnicButton
11
11
  size="small"
12
- :iconCenter="`arrow-${index === 0 ? 'left' : 'right'}-1-1`"
12
+ :iconCenter="`keyboard_arrow_${index === 0 ? 'left' : 'right'}`"
13
13
  :type="size === 'large' ? 'secondary' : 'tertiary'"
14
14
  class="button-space"
15
15
  :style="{ gridArea: `${index === 0 ? 'left' : 'right'}-button` }"
@@ -72,7 +72,7 @@
72
72
  <div :class="['header', `header--${size}`]">
73
73
  <UnnnicButton
74
74
  size="small"
75
- iconCenter="arrow-left-1-1"
75
+ iconCenter="keyboard_arrow_left"
76
76
  :type="size === 'large' ? 'secondary' : 'tertiary'"
77
77
  class="button-space"
78
78
  :style="{ gridArea: 'left-button' }"
@@ -85,7 +85,7 @@
85
85
 
86
86
  <UnnnicButton
87
87
  size="small"
88
- iconCenter="arrow-right-1-1"
88
+ iconCenter="keyboard_arrow_right"
89
89
  :type="size === 'large' ? 'secondary' : 'tertiary'"
90
90
  class="button-space"
91
91
  :style="{ gridArea: 'right-button' }"
@@ -183,8 +183,14 @@
183
183
  <div
184
184
  v-for="(option, index) in periodsLocale"
185
185
  :key="index"
186
- :class="['option', { selected: optionSelected === option.id }]"
187
- @click="autoSelect(option.id)"
186
+ :class="[
187
+ 'option',
188
+ {
189
+ selectable: option.id !== 'custom',
190
+ selected: optionSelected === option.id,
191
+ },
192
+ ]"
193
+ @click="option.id === 'custom' ? null : autoSelect(option.id)"
188
194
  >
189
195
  {{ option.name }}
190
196
  </div>
@@ -203,7 +209,7 @@
203
209
  size="small"
204
210
  :text="filterText"
205
211
  type="secondary"
206
- @click="$emit('submit', value)"
212
+ @click="submit"
207
213
  />
208
214
  </div>
209
215
  </div>
@@ -215,6 +221,7 @@ import {
215
221
  months as translationMonths,
216
222
  days as translationDays,
217
223
  periods as translationPeriods,
224
+ buttons as translationButtons,
218
225
  } from './translations.js';
219
226
 
220
227
  import UnnnicI18n from '../../mixins/i18n';
@@ -234,6 +241,8 @@ export default {
234
241
  minDate: { type: String, default: '' },
235
242
  maxDate: { type: String, default: '' },
236
243
 
244
+ equivalentOption: { type: String, default: '' },
245
+
237
246
  type: {
238
247
  type: String,
239
248
  default: 'day',
@@ -287,7 +296,7 @@ export default {
287
296
  },
288
297
  },
289
298
 
290
- emits: ['change', 'submit'],
299
+ emits: ['change', 'submit', 'update:equivalentOption'],
291
300
 
292
301
  data() {
293
302
  const today = new Date();
@@ -313,6 +322,10 @@ export default {
313
322
  };
314
323
  },
315
324
 
325
+ mounted() {
326
+ this.updateOptionSelected();
327
+ },
328
+
316
329
  computed: {
317
330
  openMonths() {
318
331
  return [this.addMonth(this.referenceDate, -1), this.referenceDate];
@@ -343,22 +356,58 @@ export default {
343
356
  },
344
357
 
345
358
  clearText() {
346
- return this.clearLabel || this.i18n('clean');
359
+ return this.clearLabel || translationButtons[this.i18nLocale].clear;
347
360
  },
348
361
  filterText() {
349
- return this.actionLabel || this.i18n('filter');
362
+ return this.actionLabel || translationButtons[this.i18nLocale].filter;
350
363
  },
351
364
  },
352
365
 
353
366
  watch: {
354
- value({ startDate, endDate }) {
355
- this.optionSelected = startDate || endDate ? 'custom' : '';
367
+ value() {
368
+ this.updateOptionSelected();
356
369
 
357
370
  this.$emit('change', this.value);
358
371
  },
359
372
  },
360
373
 
361
374
  methods: {
375
+ submit() {
376
+ this.$emit('submit', this.value);
377
+
378
+ if (this.optionSelected === 'custom') {
379
+ this.$emit('update:equivalentOption', '');
380
+ } else {
381
+ this.$emit(
382
+ 'update:equivalentOption',
383
+ this.periodsLocale.find(
384
+ ({ id: periodId }) => periodId === this.optionSelected,
385
+ )?.name || '',
386
+ );
387
+ }
388
+ },
389
+
390
+ updateOptionSelected() {
391
+ const { startDate, endDate } = this.value;
392
+
393
+ function isSameTime(date1, date2) {
394
+ return new Date(date1).getTime() === new Date(date2).getTime();
395
+ }
396
+
397
+ const period = this.periodsLocale.find(({ id: periodId }) => {
398
+ const { startDate: periodStartDate, endDate: periodEndDate } =
399
+ this.getStartAndEndDateByPeriod(periodId);
400
+
401
+ return (
402
+ isSameTime(startDate, periodStartDate) &&
403
+ isSameTime(endDate, periodEndDate)
404
+ );
405
+ });
406
+
407
+ this.optionSelected =
408
+ startDate || endDate ? (period ? period.id : 'custom') : '';
409
+ },
410
+
362
411
  dateToString(date) {
363
412
  return `${date.getMonth() + 1} ${date.getDate()} ${date.getFullYear()}`;
364
413
  },
@@ -725,41 +774,53 @@ export default {
725
774
  this.optionSelected = '';
726
775
  },
727
776
 
728
- autoSelect(method) {
777
+ getStartAndEndDateByPeriod(period) {
778
+ let startDate;
779
+ let endDate;
780
+
729
781
  const today = new Date();
730
782
 
731
- const days = method.match(/^last-(\d+)-days$/);
732
- const months = method.match(/^last-(\d+)-months$/);
783
+ const days = period.match(/^last-(\d+)-days$/);
784
+ const months = period.match(/^last-(\d+)-months$/);
733
785
 
734
786
  if (days) {
735
787
  const howMuch = Number(days[1]);
736
788
 
737
- this.endDate = this.dateToString(today);
789
+ endDate = this.dateToString(today);
738
790
  today.setDate(today.getDate() - howMuch + 1);
739
- this.startDate = this.dateToString(today);
791
+ startDate = this.dateToString(today);
740
792
  } else if (months) {
741
793
  const howMuch = Number(months[1]);
742
794
 
743
- this.endDate = this.dateToString(today);
795
+ endDate = this.dateToString(today);
744
796
  today.setDate(today.getDate() + 1);
745
797
  today.setMonth(today.getMonth() - howMuch);
746
- this.startDate = this.dateToString(today);
747
- } else if (method === 'current-month') {
798
+ startDate = this.dateToString(today);
799
+ } else if (period === 'current-month') {
748
800
  const referenceDate = new Date();
749
801
  today.setDate(1);
750
- this.startDate = this.dateToString(today);
802
+ startDate = this.dateToString(today);
751
803
  const referenceDay = referenceDate.getDate();
752
804
  today.setDate(referenceDay);
753
- this.endDate = this.dateToString(today);
754
- } else if (method === 'previous-month') {
805
+ endDate = this.dateToString(today);
806
+ } else if (period === 'previous-month') {
755
807
  today.setDate(1);
756
808
  today.setMonth(today.getMonth() - 1);
757
- this.startDate = this.dateToString(today);
809
+ startDate = this.dateToString(today);
758
810
  today.setMonth(today.getMonth() + 1);
759
811
  today.setDate(0);
760
- this.endDate = this.dateToString(today);
812
+ endDate = this.dateToString(today);
761
813
  }
762
814
 
815
+ return { startDate, endDate };
816
+ },
817
+
818
+ autoSelect(method) {
819
+ const { startDate, endDate } = this.getStartAndEndDateByPeriod(method);
820
+
821
+ this.startDate = startDate;
822
+ this.endDate = endDate;
823
+
763
824
  if (this.endDate) {
764
825
  const secondMonth = this.addMonth(this.referenceDate, 1);
765
826
 
@@ -922,9 +983,15 @@ export default {
922
983
 
923
984
  padding: $unnnic-spacing-stack-xs $unnnic-spacing-inline-sm;
924
985
  user-select: none;
925
- cursor: pointer;
926
986
 
927
- &:hover,
987
+ &.selectable {
988
+ cursor: pointer;
989
+
990
+ &:hover {
991
+ background-color: $unnnic-color-background-sky;
992
+ }
993
+ }
994
+
928
995
  &.selected {
929
996
  background-color: $unnnic-color-background-sky;
930
997
  }
@@ -65,6 +65,23 @@ export const days = {
65
65
  es: ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
66
66
  };
67
67
 
68
+ export const buttons = {
69
+ 'pt-br': {
70
+ clear: 'Limpar',
71
+ filter: 'Filtrar',
72
+ },
73
+ 'en-us': {
74
+ clear: 'Clear',
75
+ filter: 'Filter',
76
+ },
77
+ es: {
78
+ clear: 'Limpiar',
79
+ filter: 'Filtrar',
80
+ },
81
+ };
82
+
83
+ buttons.en = buttons['en-us'];
84
+
68
85
  export const periods = {
69
86
  'pt-br': [
70
87
  {
@@ -118,6 +118,9 @@ export default {
118
118
  return !!this.$slots.label;
119
119
  },
120
120
  },
121
+ methods: {
122
+ fullySanitize,
123
+ },
121
124
  watch: {
122
125
  val() {
123
126
  this.$emit('update:modelValue', fullySanitize(this.val));
@@ -129,9 +132,6 @@ export default {
129
132
  mounted() {
130
133
  this.val = this.modelValue;
131
134
  },
132
- methods: {
133
- fullySanitize,
134
- },
135
135
  };
136
136
  </script>
137
137
 
@@ -10,7 +10,7 @@
10
10
  :iconRight="iconPosition === 'right' && 'calendar_month'"
11
11
  hasCloudyColor
12
12
  readonly
13
- :modelValue="filterText"
13
+ :modelValue="overwrittenValue || filterText"
14
14
  @focus="showCalendarFilter = true"
15
15
  />
16
16
 
@@ -31,6 +31,7 @@
31
31
  :minDate="minDate"
32
32
  :maxDate="maxDate"
33
33
  :disableClear="disableClear"
34
+ v-model:equivalentOption="overwrittenValue"
34
35
  @change="emitSelectDate"
35
36
  @submit="changeDate"
36
37
  />
@@ -139,6 +140,7 @@ export default {
139
140
  data() {
140
141
  return {
141
142
  showCalendarFilter: false,
143
+ overwrittenValue: '',
142
144
  };
143
145
  },
144
146
 
@@ -86,7 +86,6 @@ import ModalNext from './ModalNext/ModalNext.vue';
86
86
  import ModalDialog from './ModalDialog/ModalDialog.vue';
87
87
  import Tour from './Tour/Tour.vue';
88
88
  import Navigator from './Navigator/index.vue';
89
- import SelectTime from './SelectTime/index.vue';
90
89
 
91
90
  export const components = {
92
91
  unnnicFormElement: formElement,
@@ -178,7 +177,6 @@ export const components = {
178
177
  unnnicTableNext: TableNext,
179
178
  unnnicTour: Tour,
180
179
  unnnicNavigator: Navigator,
181
- unnnicSelectTime: SelectTime,
182
180
  };
183
181
 
184
182
  export const unnnicFontSize = fontSize;
@@ -271,4 +269,3 @@ export const unnnicDrawer = Drawer;
271
269
  export const unnnicTableNext = TableNext;
272
270
  export const unnnicTour = Tour;
273
271
  export const unnnicNavigator = Navigator;
274
- export const unnnicSelectTime = SelectTime;
@@ -1,219 +0,0 @@
1
- <template>
2
- <section
3
- v-onClickOutside="() => (active = false)"
4
- class="unnnic-select-time"
5
- >
6
- <DropdownSkeleton
7
- ref="dropdown-skeleton"
8
- type="manual"
9
- :modelValue="active"
10
- position="bottom"
11
- >
12
- <TextInput
13
- :modelValue="modelValue"
14
- :iconRight="active ? 'keyboard_arrow_up' : 'keyboard_arrow_down'"
15
- nativeType="time"
16
- :placeholder="placeholder"
17
- :disabled="disabled"
18
- class="unnnic-select-time__input"
19
- @focus="active = true"
20
- @blur="handleBlur"
21
- @update:model-value="handleInput"
22
- @keydown.enter="handleBlur({ close: true })"
23
- />
24
-
25
- <template #inside="props">
26
- <section
27
- :style="{ width: props.width }"
28
- class="unnnic-select-time__options"
29
- >
30
- <section
31
- v-for="hour in options"
32
- :ref="`hour-${hour.value}`"
33
- :key="hour.value"
34
- :class="{
35
- 'unnnic-select-time__options__item': true,
36
- 'unnnic-select-time__options__item--selected':
37
- modelValue === hour.value,
38
- }"
39
- @click="handleClickTimeOption(hour.value)"
40
- >
41
- {{ hour.label }}
42
- </section>
43
- </section>
44
- </template>
45
- </DropdownSkeleton>
46
- </section>
47
- </template>
48
-
49
- <script>
50
- import { vOnClickOutside } from '@vueuse/components';
51
-
52
- import DropdownSkeleton from '../Dropdown/DropdownSkeleton.vue';
53
- import TextInput from '../Input/TextInput.vue';
54
-
55
- import { hoursTimesOptions } from '../../utils/hours';
56
-
57
- export default {
58
- name: 'SelectTime',
59
- components: {
60
- DropdownSkeleton,
61
- TextInput,
62
- },
63
-
64
- directives: {
65
- onClickOutside: vOnClickOutside,
66
- },
67
- props: {
68
- modelValue: {
69
- type: String,
70
- default: '',
71
- },
72
- options: {
73
- type: Array,
74
- default: () => hoursTimesOptions,
75
- },
76
- placeholder: {
77
- type: String,
78
- default: '',
79
- },
80
- disabled: {
81
- type: Boolean,
82
- default: false,
83
- },
84
- },
85
- emits: ['update:modelValue'],
86
- data() {
87
- return {
88
- active: false,
89
- };
90
- },
91
- methods: {
92
- handleInput(text) {
93
- const { value } =
94
- this.options.find((hour) => hour.value.includes(text)) || {};
95
-
96
- if (value) {
97
- const hourRef = this.$refs[`hour-${value}`][0];
98
- if (hourRef) {
99
- hourRef.scrollIntoView({ behavior: 'smooth' });
100
- }
101
- }
102
-
103
- this.$emit('update:modelValue', text);
104
- },
105
-
106
- handleBlur({ close = false } = {}) {
107
- if (this.modelValue) {
108
- const cleanValue = this.modelValue.replace(/[^0-9]/g, '');
109
-
110
- if (cleanValue.length > 0) {
111
- let formattedTime = '';
112
-
113
- if (cleanValue.length === 4) {
114
- // Format: 0101 -> 01:01, 1310 -> 13:10
115
- const hours = cleanValue.substring(0, 2);
116
- const minutes = cleanValue.substring(2, 4);
117
-
118
- if (parseInt(hours) <= 23 && parseInt(minutes) <= 59) {
119
- formattedTime = `${hours}:${minutes}`;
120
- }
121
- } else if (cleanValue.length === 3) {
122
- // Format: 123 -> 01:23
123
- const hours = `0${cleanValue.substring(0, 1)}`;
124
- const minutes = cleanValue.substring(1, 3);
125
-
126
- if (parseInt(minutes) <= 59) {
127
- formattedTime = `${hours}:${minutes}`;
128
- }
129
- } else if (cleanValue.length === 2) {
130
- // Format: 12 -> 12:00
131
- const hours = cleanValue;
132
- formattedTime = `${hours}:00`;
133
- } else if (cleanValue.length === 1) {
134
- // Format: 1 -> 01:00
135
- const hours = `0${cleanValue}`;
136
- formattedTime = `${hours}:00`;
137
- }
138
-
139
- this.$emit('update:modelValue', formattedTime);
140
- }
141
- }
142
-
143
- if (close) {
144
- this.active = false;
145
- }
146
- },
147
- handleClickTimeOption(value) {
148
- this.$emit('update:modelValue', value);
149
- this.active = false;
150
- },
151
- },
152
- };
153
- </script>
154
-
155
- <style lang="scss" scoped>
156
- @use '@/assets/scss/unnnic' as *;
157
-
158
- :deep(.unnnic-select-time__input) {
159
- &::-webkit-calendar-picker-indicator {
160
- background: none;
161
- display: none;
162
- }
163
- }
164
-
165
- .unnnic-select-time {
166
- &__options {
167
- @function calc-max-height($value) {
168
- @return ($value * $unnnic-font-size) - ($unnnic-spacing-xs * 2);
169
- }
170
- margin-top: $unnnic-spacing-nano;
171
- border-radius: $unnnic-border-radius-sm;
172
- box-shadow: $unnnic-shadow-level-near;
173
- background-color: $unnnic-color-background-snow;
174
- cursor: pointer;
175
- display: grid;
176
- max-height: calc-max-height(9.25);
177
- overflow-y: auto;
178
-
179
- &__item {
180
- margin: 0px $unnnic-spacing-nano;
181
- background-color: $unnnic-color-background-snow;
182
- padding: $unnnic-spacing-stack-nano $unnnic-inline-xs;
183
- max-width: 100%;
184
- font-family: $unnnic-font-family-secondary;
185
- color: $unnnic-color-neutral-darkest;
186
- font-weight: $unnnic-font-weight-regular;
187
-
188
- white-space: nowrap;
189
- text-overflow: ellipsis;
190
- overflow: hidden;
191
- -webkit-line-clamp: 1;
192
-
193
- &:hover {
194
- border-radius: $unnnic-border-radius-sm;
195
- background-color: $unnnic-color-neutral-light;
196
- }
197
-
198
- &--selected {
199
- color: $unnnic-color-weni-600;
200
- font-weight: $unnnic-font-weight-bold;
201
- }
202
- }
203
-
204
- &::-webkit-scrollbar {
205
- width: $unnnic-spacing-inline-nano;
206
- }
207
-
208
- &::-webkit-scrollbar-thumb {
209
- background: $unnnic-color-neutral-cleanest;
210
- border-radius: $unnnic-border-radius-pill;
211
- }
212
-
213
- &::-webkit-scrollbar-track {
214
- background: $unnnic-color-neutral-soft;
215
- border-radius: $unnnic-border-radius-pill;
216
- }
217
- }
218
- }
219
- </style>
@@ -1,25 +0,0 @@
1
- import unnnicSelectTime from '../components/SelectTime/index.vue';
2
-
3
- export default {
4
- title: 'Select/SelectTime',
5
- component: unnnicSelectTime,
6
- argTypes: {},
7
- render: (args) => ({
8
- components: {
9
- unnnicSelectTime,
10
- },
11
- setup() {
12
- return { args };
13
- },
14
- data() {
15
- return {
16
- exampleValue: '',
17
- };
18
- },
19
- template: `
20
- <unnnicSelectTime v-bind="args" v-model="exampleValue" />
21
- `,
22
- }),
23
- };
24
-
25
- export const Default = {};
@@ -1,100 +0,0 @@
1
- const hoursTimesOptions = [
2
- {
3
- label: '00:00',
4
- value: '00:00',
5
- },
6
- {
7
- label: '01:00',
8
- value: '01:00',
9
- },
10
- {
11
- label: '02:00',
12
- value: '02:00',
13
- },
14
- {
15
- label: '03:00',
16
- value: '03:00',
17
- },
18
- {
19
- label: '04:00',
20
- value: '04:00',
21
- },
22
- {
23
- label: '05:00',
24
- value: '05:00',
25
- },
26
- {
27
- label: '06:00',
28
- value: '06:00',
29
- },
30
- {
31
- label: '07:00',
32
- value: '07:00',
33
- },
34
- {
35
- label: '08:00',
36
- value: '08:00',
37
- },
38
- {
39
- label: '09:00',
40
- value: '09:00',
41
- },
42
- {
43
- label: '10:00',
44
- value: '10:00',
45
- },
46
- {
47
- label: '11:00',
48
- value: '11:00',
49
- },
50
- {
51
- label: '12:00',
52
- value: '12:00',
53
- },
54
- {
55
- label: '13:00',
56
- value: '13:00',
57
- },
58
- {
59
- label: '14:00',
60
- value: '14:00',
61
- },
62
- {
63
- label: '15:00',
64
- value: '15:00',
65
- },
66
- {
67
- label: '16:00',
68
- value: '16:00',
69
- },
70
- {
71
- label: '17:00',
72
- value: '17:00',
73
- },
74
- {
75
- label: '18:00',
76
- value: '18:00',
77
- },
78
- {
79
- label: '19:00',
80
- value: '19:00',
81
- },
82
- {
83
- label: '20:00',
84
- value: '20:00',
85
- },
86
- {
87
- label: '21:00',
88
- value: '21:00',
89
- },
90
- {
91
- label: '22:00',
92
- value: '22:00',
93
- },
94
- {
95
- label: '23:00',
96
- value: '23:00',
97
- },
98
- ];
99
-
100
- export { hoursTimesOptions };