@weni/unnnic-system 3.0.3 → 3.0.4-alpha.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 (32) hide show
  1. package/dist/components/DataTable/index.vue.d.ts +156 -0
  2. package/dist/components/DataTable/index.vue.d.ts.map +1 -0
  3. package/dist/components/DatePicker/DatePicker.vue.d.ts +2 -2
  4. package/dist/components/InputDatePicker/InputDatePicker.vue.d.ts +3 -3
  5. package/dist/components/ModalDialog/ModalDialog.vue.d.ts +1 -1
  6. package/dist/components/ModalDialog/ModalDialog.vue.d.ts.map +1 -1
  7. package/dist/components/TemplatePreview/TemplatePreview.vue.d.ts +9 -0
  8. package/dist/components/TemplatePreview/TemplatePreview.vue.d.ts.map +1 -0
  9. package/dist/components/TemplatePreview/TemplatePreviewModal.vue.d.ts +15 -0
  10. package/dist/components/TemplatePreview/TemplatePreviewModal.vue.d.ts.map +1 -0
  11. package/dist/components/index.d.ts +263 -6
  12. package/dist/components/index.d.ts.map +1 -1
  13. package/dist/{es-61329267.mjs → es-39b05ec7.mjs} +1 -1
  14. package/dist/{index-0d853377.mjs → index-c43e689f.mjs} +9498 -9163
  15. package/dist/{pt-br-1024c0d5.mjs → pt-br-b70cfbf8.mjs} +1 -1
  16. package/dist/style.css +1 -1
  17. package/dist/unnnic.mjs +61 -58
  18. package/dist/unnnic.umd.js +44 -43
  19. package/package.json +2 -2
  20. package/src/assets/img/previews/doc-preview.png +0 -0
  21. package/src/assets/img/previews/image-preview.png +0 -0
  22. package/src/assets/img/previews/video-preview.png +0 -0
  23. package/src/components/DataTable/index.vue +493 -0
  24. package/src/components/ModalDialog/ModalDialog.vue +27 -29
  25. package/src/components/ModalDialog/__tests__/__snapshots__/ModalDialog.spec.js.snap +1 -1
  26. package/src/components/TemplatePreview/TemplatePreview.vue +249 -0
  27. package/src/components/TemplatePreview/TemplatePreviewModal.vue +51 -0
  28. package/src/components/TemplatePreview/types.d.ts +16 -0
  29. package/src/components/index.ts +9 -0
  30. package/src/stories/DataTable.stories.js +332 -0
  31. package/src/stories/TemplatePreview.stories.js +94 -0
  32. package/src/stories/TemplatePreviewModal.stories.js +110 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weni/unnnic-system",
3
- "version": "3.0.3",
3
+ "version": "3.0.4-alpha.1",
4
4
  "type": "commonjs",
5
5
  "files": [
6
6
  "dist",
@@ -99,4 +99,4 @@
99
99
  "vue-eslint-parser": "^9.4.2",
100
100
  "vue-tsc": "^3.0.5"
101
101
  }
102
- }
102
+ }
@@ -0,0 +1,493 @@
1
+ <template>
2
+ <table
3
+ class="unnnic-data-table"
4
+ :style="props.fixedHeaders ? {} : heightStyles"
5
+ >
6
+ <thead
7
+ v-if="!shouldHideHeaders"
8
+ class="unnnic-data-table__header"
9
+ >
10
+ <tr class="unnnic-data-table__header-row">
11
+ <th
12
+ v-for="header in headers"
13
+ :key="header.itemKey"
14
+ :class="[
15
+ 'unnnic-data-table__header-cell',
16
+ {
17
+ 'unnnic-data-table__header-cell--clickable': header.isSortable,
18
+ 'unnnic-data-table__header-cell--sorting':
19
+ sort.header === header.title && sort.order !== '',
20
+ },
21
+ ]"
22
+ @click.stop="handleClickHeader(header)"
23
+ >
24
+ <slot
25
+ v-if="slots[`header-${header.itemKey}`]"
26
+ :name="`header-${header.itemKey}`"
27
+ :header="header"
28
+ />
29
+ <template v-else>
30
+ {{ header.title }}
31
+ </template>
32
+ <template v-if="header.isSortable">
33
+ <IconArrowsDefault
34
+ v-if="sort.header !== header.title"
35
+ class="order-default-icon"
36
+ data-testid="arrow-default-icon"
37
+ />
38
+ <Icon
39
+ v-else-if="sort.order === 'asc'"
40
+ clickable
41
+ size="ant"
42
+ :icon="'switch_left'"
43
+ style="transform: rotate(-90deg)"
44
+ data-testid="arrow-asc-icon"
45
+ />
46
+ <Icon
47
+ v-else-if="sort.order === 'desc'"
48
+ clickable
49
+ size="ant"
50
+ :icon="'switch_left'"
51
+ style="transform: rotate(90deg)"
52
+ data-testid="arrow-desc-icon"
53
+ />
54
+ </template>
55
+ </th>
56
+ </tr>
57
+ </thead>
58
+ <tbody
59
+ :class="[
60
+ 'unnnic-data-table__body',
61
+ { 'unnnic-data-table__body--hide-headers': props.hideHeaders },
62
+ ]"
63
+ :style="props.fixedHeaders ? heightStyles : {}"
64
+ >
65
+ <tr
66
+ v-if="isLoading"
67
+ :class="[
68
+ 'unnnic-data-table__body-row',
69
+ 'unnnic-data-table__body-row--loading',
70
+ ]"
71
+ >
72
+ <img
73
+ class="unnnic-data-table__body-cell--loading"
74
+ data-testid="body-row-loading"
75
+ src="../../assets/icons/weni-loading.svg"
76
+ height="40"
77
+ />
78
+ </tr>
79
+ <template v-else-if="props.items.length">
80
+ <tr
81
+ v-for="(item, index) in props.items"
82
+ :key="index"
83
+ :class="[
84
+ 'unnnic-data-table__body-row',
85
+ { 'unnnic-data-table__body-row--clickable': props.clickable },
86
+ ]"
87
+ @click="handleClickRow(item)"
88
+ >
89
+ <template
90
+ v-for="key in headersItemsKeys"
91
+ :key="key"
92
+ >
93
+ <td
94
+ v-if="slots[`body-${key}`]"
95
+ :class="[
96
+ 'unnnic-data-table__body-cell',
97
+ `unnnic-data-table__body-cell--${size}`,
98
+ ]"
99
+ >
100
+ <slot
101
+ :name="`body-${key}`"
102
+ :item="item"
103
+ />
104
+ </td>
105
+ <td
106
+ v-else
107
+ :class="[
108
+ 'unnnic-data-table__body-cell',
109
+ `unnnic-data-table__body-cell--${size}`,
110
+ ]"
111
+ >
112
+ {{ item[key] }}
113
+ </td>
114
+ </template>
115
+ </tr>
116
+ </template>
117
+ <tr
118
+ v-else
119
+ class="unnnic-data-table__body-row"
120
+ >
121
+ <td
122
+ v-if="slots['without-results']"
123
+ :class="[
124
+ 'unnnic-data-table__body-cell',
125
+ `unnnic-data-table__body-cell--${size}`,
126
+ ]"
127
+ >
128
+ <slot name="without-results" />
129
+ </td>
130
+ <td
131
+ v-else
132
+ :class="[
133
+ 'unnnic-data-table__body-cell',
134
+ `unnnic-data-table__body-cell--${size}`,
135
+ ]"
136
+ data-testid="body-cell"
137
+ >
138
+ <p
139
+ class="unnnic-data-table__body-cell-text"
140
+ data-testid="body-cell-text"
141
+ >
142
+ {{ defaultTranslations.without_results[props.locale || 'en'] }}
143
+ </p>
144
+ </td>
145
+ </tr>
146
+ </tbody>
147
+ <TablePagination
148
+ v-if="!props.hidePagination"
149
+ :modelValue="props.page"
150
+ :total="props.pageTotal"
151
+ :interval="props.pageInterval"
152
+ @update:model-value="$emit('update:page', $event)"
153
+ />
154
+ </table>
155
+ </template>
156
+
157
+ <script lang="ts">
158
+ export default {
159
+ name: 'UnnnicDataTable',
160
+ };
161
+ </script>
162
+
163
+ <script setup lang="ts">
164
+ import { computed, ref, useSlots } from 'vue';
165
+
166
+ import Icon from '../Icon.vue';
167
+ import IconArrowsDefault from '../icons/iconArrowsDefault.vue';
168
+ import TablePagination from '../TableNext/TablePagination.vue';
169
+
170
+ type DataTableHeader = {
171
+ title: string;
172
+ isSortable?: boolean;
173
+ itemKey: string;
174
+ align?: 'start' | 'center' | 'end';
175
+ size?: number | string;
176
+ };
177
+
178
+ type DataTableItem = {
179
+ [key: string]: any;
180
+ };
181
+
182
+ const slots = useSlots();
183
+
184
+ const emit = defineEmits<{
185
+ 'update:sort': [sort: { header: string; order: string }];
186
+ itemClick: [item: DataTableItem];
187
+ 'update:page': [page: number];
188
+ }>();
189
+
190
+ const props = defineProps<{
191
+ headers: {
192
+ type: DataTableHeader[];
193
+ required: true;
194
+ };
195
+ items: {
196
+ type: DataTableItem[];
197
+ required: true;
198
+ };
199
+ isLoading: {
200
+ type: Boolean;
201
+ default: false;
202
+ };
203
+ size: {
204
+ type: 'sm' | 'md';
205
+ default: 'md';
206
+ };
207
+ height: {
208
+ type: String;
209
+ default: '';
210
+ };
211
+ maxHeight: {
212
+ type: String;
213
+ default: '';
214
+ };
215
+ clickable: {
216
+ type: Boolean;
217
+ default: false;
218
+ };
219
+ fixedHeaders: {
220
+ type: Boolean;
221
+ default: false;
222
+ };
223
+ hideHeaders: {
224
+ type: Boolean;
225
+ default: false;
226
+ };
227
+ hidePagination: {
228
+ type: Boolean;
229
+ default: false;
230
+ };
231
+ page: {
232
+ type: Number;
233
+ default: 1;
234
+ };
235
+ pageTotal: {
236
+ type: Number;
237
+ default: 0;
238
+ };
239
+ pageInterval: {
240
+ type: Number;
241
+ default: 5;
242
+ };
243
+ locale: {
244
+ type: string;
245
+ default: 'en';
246
+ };
247
+ }>();
248
+
249
+ const defaultTranslations = {
250
+ without_results: {
251
+ 'pt-br': 'Nenhum resultado correspondente',
252
+ en: 'No matching results',
253
+ es: 'No hay resultados coincidentes',
254
+ },
255
+ };
256
+
257
+ const heightStyles = computed(() => {
258
+ return {
259
+ height: props.height || 'unset',
260
+ 'max-height': props.maxHeight || 'unset',
261
+ overflow: props.height || props.maxHeight ? 'auto' : 'unset',
262
+ };
263
+ });
264
+
265
+ const shouldHideHeaders = computed(() => {
266
+ return props.hideHeaders || !props.headers.length;
267
+ });
268
+
269
+ const headersItemsKeys: string[] = computed(() => {
270
+ return props.headers.map((header) => header.itemKey);
271
+ });
272
+
273
+ const sort = ref({
274
+ header: '',
275
+ order: '',
276
+ });
277
+
278
+ const getHeaderColumnSize = (header: DataTableHeader): string => {
279
+ return typeof header.size === 'number'
280
+ ? `${header.size || 1}fr`
281
+ : header.size || '1fr';
282
+ };
283
+
284
+ const gridTemplateColumns: string = computed(() => {
285
+ const columnSizes = props.headers.length
286
+ ? props.headers.map(getHeaderColumnSize)
287
+ : props.items[0].content.map(() => '1fr');
288
+
289
+ return columnSizes.join(' ');
290
+ });
291
+
292
+ const handleSort = (key: string, order: string) => {
293
+ sort.value = { header: key, order };
294
+ emit('update:sort', sort.value);
295
+ };
296
+
297
+ const handleClickHeader = (header: DataTableHeader) => {
298
+ if (!header.isSortable) return;
299
+
300
+ const nextSortOrderMapper = {
301
+ asc: 'desc',
302
+ desc: 'asc',
303
+ '': 'asc',
304
+ };
305
+
306
+ const nextSort =
307
+ header.title !== sort.value.header
308
+ ? 'asc'
309
+ : nextSortOrderMapper[sort.value.order];
310
+
311
+ handleSort(nextSort === '' ? '' : header.title, nextSort);
312
+ };
313
+
314
+ const handleClickRow = (item: DataTableItem) => {
315
+ if (!props.clickable) return;
316
+
317
+ emit('itemClick', item);
318
+ };
319
+ </script>
320
+
321
+ <style scoped lang="scss">
322
+ @use '@/assets/scss/unnnic' as *;
323
+
324
+ $tableBorder: $unnnic-border-width-thinner solid $unnnic-color-neutral-soft;
325
+
326
+ .unnnic-data-table {
327
+ border-spacing: 0;
328
+
329
+ overflow: hidden;
330
+
331
+ width: 100%;
332
+
333
+ display: flex;
334
+ flex-direction: column;
335
+
336
+ &::-webkit-scrollbar {
337
+ width: $unnnic-spacing-inline-nano;
338
+ }
339
+
340
+ &::-webkit-scrollbar-thumb {
341
+ background: $unnnic-color-neutral-cleanest;
342
+ border-radius: $unnnic-border-radius-pill;
343
+ }
344
+
345
+ &::-webkit-scrollbar-track {
346
+ background: $unnnic-color-neutral-soft;
347
+ border-radius: $unnnic-border-radius-pill;
348
+ }
349
+
350
+ &__header {
351
+ &-row {
352
+ @extend %base-row;
353
+
354
+ grid-template-columns: v-bind(gridTemplateColumns);
355
+ }
356
+
357
+ &-cell {
358
+ @extend %base-cell;
359
+
360
+ height: 100%;
361
+
362
+ box-sizing: border-box;
363
+ border: $tableBorder;
364
+ background-color: $unnnic-color-neutral-light;
365
+
366
+ font-weight: $unnnic-font-weight-bold;
367
+
368
+ display: flex;
369
+
370
+ &:first-of-type {
371
+ border-radius: $unnnic-border-radius-sm 0 0 0;
372
+ }
373
+
374
+ &:not(:first-of-type) {
375
+ border-left: none;
376
+ }
377
+
378
+ &:last-of-type {
379
+ border-radius: 0 $unnnic-border-radius-sm 0 0;
380
+ }
381
+
382
+ &--sorting {
383
+ background-color: $unnnic-color-neutral-soft;
384
+ }
385
+
386
+ &--clickable {
387
+ &:hover {
388
+ cursor: pointer;
389
+ background-color: $unnnic-color-neutral-soft;
390
+ }
391
+ }
392
+ }
393
+ }
394
+
395
+ &__body {
396
+ &::-webkit-scrollbar {
397
+ width: $unnnic-spacing-inline-nano;
398
+ }
399
+
400
+ &::-webkit-scrollbar-thumb {
401
+ background: $unnnic-color-neutral-cleanest;
402
+ border-radius: $unnnic-border-radius-pill;
403
+ }
404
+
405
+ &::-webkit-scrollbar-track {
406
+ background: $unnnic-color-neutral-soft;
407
+ border-radius: $unnnic-border-radius-pill;
408
+ }
409
+
410
+ &--hide-headers {
411
+ .unnnic-data-table__body-row:first-of-type {
412
+ border-radius: $unnnic-border-radius-sm $unnnic-border-radius-sm 0 0;
413
+ border-top: $tableBorder;
414
+ }
415
+ }
416
+
417
+ &-row {
418
+ @extend %base-row;
419
+
420
+ overflow: hidden;
421
+
422
+ border: $tableBorder;
423
+ border-collapse: collapse;
424
+ border-top: none;
425
+
426
+ grid-template-columns: v-bind(gridTemplateColumns);
427
+
428
+ &--loading {
429
+ grid-template-columns: 1fr;
430
+ }
431
+
432
+ &--clickable {
433
+ text-decoration: none;
434
+
435
+ &:hover {
436
+ cursor: pointer;
437
+ background-color: $unnnic-color-neutral-lightest;
438
+ }
439
+ }
440
+
441
+ &:last-of-type {
442
+ border-radius: 0 0 $unnnic-border-radius-sm $unnnic-border-radius-sm;
443
+ }
444
+ }
445
+
446
+ &-cell {
447
+ @extend %base-cell;
448
+
449
+ &-text {
450
+ margin: 0;
451
+
452
+ overflow: hidden;
453
+ white-space: nowrap;
454
+ text-overflow: ellipsis;
455
+ }
456
+ }
457
+
458
+ td.unnnic-data-table__body-cell--sm {
459
+ padding: $unnnic-spacing-ant $unnnic-spacing-sm;
460
+ }
461
+
462
+ &-cell--loading {
463
+ margin: $unnnic-spacing-xl 0;
464
+ padding: 0;
465
+
466
+ width: 100%;
467
+
468
+ pointer-events: none;
469
+ }
470
+ }
471
+
472
+ %base-cell {
473
+ border-collapse: collapse;
474
+
475
+ padding: $unnnic-spacing-sm $unnnic-spacing-sm;
476
+
477
+ font-family: $unnnic-font-family-secondary;
478
+ font-size: $unnnic-font-size-body-gt;
479
+ line-height: $unnnic-line-height-small * 5.5;
480
+ text-align: left;
481
+ color: $unnnic-color-neutral-dark;
482
+
483
+ overflow: hidden;
484
+ white-space: nowrap;
485
+ text-overflow: ellipsis;
486
+ }
487
+
488
+ %base-row {
489
+ display: grid;
490
+ align-items: center;
491
+ }
492
+ }
493
+ </style>
@@ -24,10 +24,7 @@
24
24
  </section>
25
25
 
26
26
  <section class="unnnic-modal-dialog__container__body">
27
- <header
28
- v-if="title"
29
- class="unnnic-modal-dialog__container__header"
30
- >
27
+ <header v-if="title" class="unnnic-modal-dialog__container__header">
31
28
  <section class="unnnic-modal-dialog__container__title-container">
32
29
  <UnnnicIcon
33
30
  v-if="icon || type"
@@ -49,6 +46,7 @@
49
46
  data-testid="close-icon"
50
47
  icon="close"
51
48
  clickable
49
+ scheme="neutral-cloudy"
52
50
  @click="close()"
53
51
  />
54
52
  </header>
@@ -98,12 +96,12 @@
98
96
  </template>
99
97
 
100
98
  <script>
101
- import UnnnicIcon from '../Icon.vue';
102
- import UnnnicButton from '../Button/Button.vue';
103
- import UnnnicI18n from '../../mixins/i18n';
99
+ import UnnnicIcon from "../Icon.vue";
100
+ import UnnnicButton from "../Button/Button.vue";
101
+ import UnnnicI18n from "../../mixins/i18n";
104
102
 
105
103
  export default {
106
- name: 'UnnnicModalDialog',
104
+ name: "UnnnicModalDialog",
107
105
  components: {
108
106
  UnnnicIcon,
109
107
  UnnnicButton,
@@ -120,29 +118,29 @@ export default {
120
118
  },
121
119
  type: {
122
120
  type: String,
123
- default: '',
121
+ default: "",
124
122
  validate(type) {
125
- return ['success', 'warning', 'attention'].includes(type);
123
+ return ["success", "warning", "attention"].includes(type);
126
124
  },
127
125
  },
128
126
  size: {
129
127
  type: String,
130
- default: 'md',
128
+ default: "md",
131
129
  validate(size) {
132
- return ['sm', 'md', 'lg'].includes(size);
130
+ return ["sm", "md", "lg"].includes(size);
133
131
  },
134
132
  },
135
133
  title: {
136
134
  type: String,
137
- default: '',
135
+ default: "",
138
136
  },
139
137
  icon: {
140
138
  type: String,
141
- default: '',
139
+ default: "",
142
140
  },
143
141
  iconScheme: {
144
142
  type: String,
145
- default: '',
143
+ default: "",
146
144
  },
147
145
  showCloseIcon: {
148
146
  type: Boolean,
@@ -165,26 +163,26 @@ export default {
165
163
  default: () => ({}),
166
164
  },
167
165
  },
168
- emits: ['primaryButtonClick', 'secondaryButtonClick', 'update:modelValue'],
166
+ emits: ["primaryButtonClick", "secondaryButtonClick", "update:modelValue"],
169
167
 
170
168
  data() {
171
169
  return {
172
170
  defaultTranslations: {
173
171
  cancel: {
174
- 'pt-br': 'Cancelar',
175
- en: 'Cancel',
176
- es: 'Cancelar',
172
+ "pt-br": "Cancelar",
173
+ en: "Cancel",
174
+ es: "Cancelar",
177
175
  },
178
176
  },
179
177
  iconsMapper: {
180
- success: { icon: 'check_circle', scheme: 'aux-green-500' },
181
- warning: { icon: 'warning', scheme: 'aux-red-500' },
182
- attention: { icon: 'error', scheme: 'aux-yellow-500' },
178
+ success: { icon: "check_circle", scheme: "aux-green-500" },
179
+ warning: { icon: "warning", scheme: "aux-red-500" },
180
+ attention: { icon: "error", scheme: "aux-yellow-500" },
183
181
  },
184
182
  primaryButtonTypeMapper: {
185
- success: 'primary',
186
- warning: 'warning',
187
- attention: 'attention',
183
+ success: "primary",
184
+ warning: "warning",
185
+ attention: "attention",
188
186
  },
189
187
  };
190
188
  },
@@ -195,17 +193,17 @@ export default {
195
193
  },
196
194
  methods: {
197
195
  close() {
198
- this.$emit('update:modelValue', false);
196
+ this.$emit("update:modelValue", false);
199
197
  },
200
198
  updateBodyOverflow(isHidden) {
201
- document.body.style.overflow = isHidden ? 'hidden' : '';
199
+ document.body.style.overflow = isHidden ? "hidden" : "";
202
200
  },
203
201
  },
204
202
  };
205
203
  </script>
206
204
 
207
205
  <style lang="scss" scoped>
208
- @use '@/assets/scss/unnnic' as *;
206
+ @use "@/assets/scss/unnnic" as *;
209
207
  * {
210
208
  margin: 0;
211
209
  padding: 0;
@@ -312,7 +310,7 @@ export default {
312
310
  &__actions {
313
311
  display: grid;
314
312
  grid-template-columns: 1fr 1fr;
315
- grid-template-areas: 'secondary-button primary-button';
313
+ grid-template-areas: "secondary-button primary-button";
316
314
  gap: $unnnic-spacing-sm;
317
315
  padding: $unnnic-spacing-md;
318
316
  flex-shrink: 0;
@@ -11,7 +11,7 @@ exports[`ModalDialog.vue > Elements rendering > matches the snapshot 1`] = `
11
11
  <unnnic-icon-stub data-v-68ebadeb="" filled="false" next="false" icon="test-icon" clickable="false" size="md" scheme="neutral-darkest" data-testid="title-icon" class="unnnic-modal-dialog__container__title-icon"></unnnic-icon-stub>
12
12
  <h1 data-v-68ebadeb="" class="unnnic-modal-dialog__container__title-text" data-testid="title-text">Test Title</h1>
13
13
  </section>
14
- <unnnic-icon-stub data-v-68ebadeb="" filled="false" next="false" icon="close" clickable="true" size="md" scheme="neutral-darkest" data-testid="close-icon"></unnnic-icon-stub>
14
+ <unnnic-icon-stub data-v-68ebadeb="" filled="false" next="false" icon="close" clickable="true" size="md" scheme="neutral-cloudy" data-testid="close-icon"></unnnic-icon-stub>
15
15
  </header>
16
16
  <section data-v-68ebadeb="" class="unnnic-modal-dialog__container__content"></section>
17
17
  <section data-v-68ebadeb="" data-testid="actions-section" class="unnnic-modal-dialog__container__actions">