@weni/unnnic-system 3.35.4 → 3.36.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": "3.35.4",
3
+ "version": "3.36.0",
4
4
  "type": "commonjs",
5
5
  "files": [
6
6
  "dist",
@@ -69,7 +69,8 @@
69
69
  "test": "vitest",
70
70
  "test:ui": "vitest --ui",
71
71
  "coverage": "vitest --coverage",
72
- "style-dictionary:generate": "style-dictionary build --config styleDictionary.config.mjs"
72
+ "style-dictionary:generate": "style-dictionary build --config styleDictionary.config.mjs",
73
+ "prepare": "git config core.hooksPath .githooks || true"
73
74
  },
74
75
  "publishConfig": {
75
76
  "registry": "https://registry.npmjs.org/"
@@ -128,7 +129,9 @@
128
129
  "eslint": "^9.37.0",
129
130
  "eslint-plugin-storybook": "^0.10.0",
130
131
  "eslint-plugin-vue": "10.4.0",
132
+ "js-yaml": "^4.1.0",
131
133
  "jsdom": "^24.1.1",
134
+ "micromatch": "^4.0.5",
132
135
  "postcss": "^8.5.6",
133
136
  "prettier": "3.6.2",
134
137
  "react": "^18.2.0",
@@ -1,10 +1,12 @@
1
1
  <script setup lang="ts">
2
2
  import type { HTMLAttributes } from 'vue';
3
- import { computed } from 'vue';
3
+ import { computed, nextTick, onMounted, onUpdated, ref } from 'vue';
4
+ import { useResizeObserver } from '@vueuse/core';
4
5
  import { cn } from '@/lib/utils';
5
6
  import { useHasComponentContent } from '@/composables/useSlotUtils';
6
7
  import Icon from '../Icon.vue';
7
8
  import IconArrowsDefault from '../icons/iconArrowsDefault.vue';
9
+ import UnnnicToolTip from '../ToolTip/ToolTip.vue';
8
10
  import {
9
11
  SORT_ORDER,
10
12
  type CellAlign,
@@ -26,6 +28,7 @@ const props = withDefaults(
26
28
  sortable?: boolean;
27
29
  type?: CellType;
28
30
  width?: string;
31
+ hideTooltip?: boolean;
29
32
  }>(),
30
33
  {
31
34
  align: 'left',
@@ -35,11 +38,41 @@ const props = withDefaults(
35
38
  sortable: false,
36
39
  type: 'body',
37
40
  width: undefined,
41
+ hideTooltip: false,
38
42
  },
39
43
  );
40
44
 
41
45
  const hasComponentContent = useHasComponentContent();
42
46
 
47
+ const contentRef = ref<HTMLElement | null>(null);
48
+ const isTruncated = ref(false);
49
+ const tooltipText = ref('');
50
+
51
+ const updateTruncation = () => {
52
+ const element = contentRef.value;
53
+
54
+ if (!element || props.hideTooltip) {
55
+ isTruncated.value = false;
56
+ tooltipText.value = '';
57
+ return;
58
+ }
59
+
60
+ const text = element.textContent?.trim() ?? '';
61
+ tooltipText.value = text;
62
+ isTruncated.value =
63
+ text.length > 0 && element.scrollWidth > element.clientWidth;
64
+ };
65
+
66
+ onMounted(() => {
67
+ nextTick(updateTruncation);
68
+ });
69
+
70
+ onUpdated(() => {
71
+ updateTruncation();
72
+ });
73
+
74
+ useResizeObserver(contentRef, updateTruncation);
75
+
43
76
  const isSorting = computed(
44
77
  () =>
45
78
  props.sortable &&
@@ -76,7 +109,23 @@ const cellClasses = computed(() =>
76
109
  :scope="props.type === 'header' ? 'col' : undefined"
77
110
  :style="{ width: props.width }"
78
111
  >
79
- <span class="unnnic-data-table-cell__content">
112
+ <UnnnicToolTip
113
+ v-if="!props.hideTooltip"
114
+ :enabled="isTruncated"
115
+ :text="tooltipText"
116
+ side="top"
117
+ >
118
+ <span
119
+ ref="contentRef"
120
+ class="unnnic-data-table-cell__content"
121
+ >
122
+ <slot />
123
+ </span>
124
+ </UnnnicToolTip>
125
+ <span
126
+ v-else
127
+ class="unnnic-data-table-cell__content"
128
+ >
80
129
  <slot />
81
130
  </span>
82
131
  <template v-if="props.type === 'header' && props.sortable">
@@ -136,6 +185,14 @@ $cell-min-height-sm: 46px;
136
185
  white-space: nowrap;
137
186
  }
138
187
 
188
+ :deep(.unnnic-tooltip.unnnic-tooltip-trigger) {
189
+ display: flex;
190
+ flex: 1 1 auto;
191
+ min-width: 0;
192
+ max-width: 100%;
193
+ overflow: hidden;
194
+ }
195
+
139
196
  :deep(.unnnic-data-table-cell__sort-icon) {
140
197
  flex-shrink: 0;
141
198
  }
@@ -32,6 +32,7 @@ const props = withDefaults(
32
32
  type="body"
33
33
  :size="props.size"
34
34
  align="center"
35
+ hideTooltip
35
36
  >
36
37
  <IconLoading
37
38
  class="unnnic-data-table__body-cell--loading"
@@ -184,6 +184,12 @@ describe('UnnnicDataTable', () => {
184
184
  wrapper.findComponent({ name: 'UnnnicIconLoading' }).exists(),
185
185
  ).toBe(true);
186
186
  expect(wrapper.find('[data-testid="body-cell"]').exists()).toBe(false);
187
+ expect(
188
+ wrapper
189
+ .find('.unnnic-data-table__body-row--loading')
190
+ .findComponent({ name: 'UnnnicTooltip' })
191
+ .exists(),
192
+ ).toBe(false);
187
193
  });
188
194
 
189
195
  it('shows the empty state', () => {
@@ -251,6 +257,56 @@ describe('UnnnicDataTable', () => {
251
257
  });
252
258
  });
253
259
 
260
+ describe('tooltips', () => {
261
+ const tooltipIn = (cell) => cell.findComponent({ name: 'UnnnicTooltip' });
262
+
263
+ it('renders tooltips on default header and body cells', () => {
264
+ const wrapper = mountTable();
265
+
266
+ expect(wrapper.findAllComponents({ name: 'UnnnicTooltip' })).toHaveLength(
267
+ headers.length + headers.length * items.length,
268
+ );
269
+ });
270
+
271
+ it('hides header and body tooltips when hideTableTooltips is set', () => {
272
+ const wrapper = mountTable({ hideTableTooltips: true });
273
+
274
+ expect(wrapper.findComponent({ name: 'UnnnicTooltip' }).exists()).toBe(
275
+ false,
276
+ );
277
+ });
278
+
279
+ it('hides the tooltip for a text header slot', () => {
280
+ const wrapper = mountTable({}, { 'header-name': 'Custom name' });
281
+ const headerCells = wrapper.findAll('[data-testid="header-cell"]');
282
+
283
+ expect(tooltipIn(headerCells[1]).exists()).toBe(false);
284
+ expect(tooltipIn(headerCells[0]).exists()).toBe(true);
285
+ expect(headerCells[1].text()).toContain('Custom name');
286
+ });
287
+
288
+ it('hides the tooltip for a text body slot', () => {
289
+ const wrapper = mountTable({}, { 'body-name': 'Custom name' });
290
+ const bodyCells = wrapper.findAll('[data-testid="body-cell"]');
291
+
292
+ expect(tooltipIn(bodyCells[1]).exists()).toBe(false);
293
+ expect(tooltipIn(bodyCells[0]).exists()).toBe(true);
294
+ expect(bodyCells[1].text()).toBe('Custom name');
295
+ });
296
+
297
+ it('hides the tooltip for the without-results slot', () => {
298
+ const wrapper = mountTable({ items: [] }, { 'without-results': 'Empty' });
299
+
300
+ expect(
301
+ tooltipIn(wrapper.find('[data-testid="body-cell"]')).exists(),
302
+ ).toBe(false);
303
+ expect(
304
+ tooltipIn(wrapper.find('[data-testid="header-cell"]')).exists(),
305
+ ).toBe(true);
306
+ expect(wrapper.text()).toContain('Empty');
307
+ });
308
+ });
309
+
254
310
  describe('fixed headers', () => {
255
311
  const mockTbodyScrollbar = (wrapper, offsetWidth, clientWidth) => {
256
312
  const tbody = wrapper.find('.unnnic-data-table__body').element;
@@ -1,7 +1,8 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { mount } from '@vue/test-utils';
2
+ import { mount, flushPromises } from '@vue/test-utils';
3
3
 
4
4
  import DataTableCell from '../DataTableCell.vue';
5
+ import UnnnicToolTip from '@/components/ToolTip/ToolTip.vue';
5
6
 
6
7
  const mountCell = (props = {}, slots = {}) =>
7
8
  mount(DataTableCell, {
@@ -9,6 +10,19 @@ const mountCell = (props = {}, slots = {}) =>
9
10
  slots,
10
11
  });
11
12
 
13
+ const setContentWidth = (wrapper, scrollWidth, clientWidth) => {
14
+ const content = wrapper.find('.unnnic-data-table-cell__content').element;
15
+
16
+ Object.defineProperty(content, 'scrollWidth', {
17
+ configurable: true,
18
+ value: scrollWidth,
19
+ });
20
+ Object.defineProperty(content, 'clientWidth', {
21
+ configurable: true,
22
+ value: clientWidth,
23
+ });
24
+ };
25
+
12
26
  describe('DataTableCell', () => {
13
27
  it('renders a body cell as td by default', () => {
14
28
  const wrapper = mountCell({}, { default: 'Lorem ipsum' });
@@ -112,4 +126,70 @@ describe('DataTableCell', () => {
112
126
  expect(wrapper.classes()).toContain('unnnic-data-table-cell--sm');
113
127
  expect(wrapper.classes()).not.toContain('unnnic-data-table-cell--md');
114
128
  });
129
+
130
+ describe('truncation tooltip', () => {
131
+ it('enables the tooltip with the full body text when content is truncated', async () => {
132
+ const wrapper = mountCell({}, { default: 'A very long cell value' });
133
+
134
+ setContentWidth(wrapper, 240, 80);
135
+ await flushPromises();
136
+
137
+ const tooltip = wrapper.findComponent(UnnnicToolTip);
138
+ expect(tooltip.exists()).toBe(true);
139
+ expect(tooltip.props('enabled')).toBe(true);
140
+ expect(tooltip.props('text')).toBe('A very long cell value');
141
+ expect(tooltip.props('side')).toBe('top');
142
+ });
143
+
144
+ it('enables the tooltip with the full header text when content is truncated', async () => {
145
+ const wrapper = mountCell(
146
+ { type: 'header', sortable: true },
147
+ { default: 'Very long header' },
148
+ );
149
+
150
+ setContentWidth(wrapper, 240, 80);
151
+ await flushPromises();
152
+
153
+ const tooltip = wrapper.findComponent(UnnnicToolTip);
154
+ expect(tooltip.props('enabled')).toBe(true);
155
+ expect(tooltip.props('text')).toBe('Very long header');
156
+ expect(tooltip.find('[data-testid="arrow-default-icon"]').exists()).toBe(
157
+ false,
158
+ );
159
+ expect(wrapper.find('[data-testid="arrow-default-icon"]').exists()).toBe(
160
+ true,
161
+ );
162
+ });
163
+
164
+ it('keeps the tooltip disabled when the text fits', async () => {
165
+ const wrapper = mountCell({}, { default: 'Short' });
166
+
167
+ setContentWidth(wrapper, 40, 120);
168
+ await flushPromises();
169
+
170
+ expect(wrapper.findComponent(UnnnicToolTip).props('enabled')).toBe(false);
171
+ });
172
+
173
+ it('keeps the tooltip disabled when the cell text is empty', async () => {
174
+ const wrapper = mountCell({}, { default: ' ' });
175
+
176
+ setContentWidth(wrapper, 40, 20);
177
+ await flushPromises();
178
+
179
+ expect(wrapper.findComponent(UnnnicToolTip).props('enabled')).toBe(false);
180
+ });
181
+
182
+ it('does not render a tooltip when hideTooltip is set', async () => {
183
+ const wrapper = mountCell(
184
+ { hideTooltip: true, type: 'header' },
185
+ { default: 'Very long header' },
186
+ );
187
+
188
+ setContentWidth(wrapper, 240, 80);
189
+ await flushPromises();
190
+
191
+ expect(wrapper.findComponent(UnnnicToolTip).exists()).toBe(false);
192
+ expect(wrapper.text()).toBe('Very long header');
193
+ });
194
+ });
115
195
  });
@@ -20,6 +20,7 @@
20
20
  :align="getHeaderAlign(header.align)"
21
21
  :sortable="header.isSortable"
22
22
  :sortOrder="getSortOrder(header)"
23
+ :hideTooltip="shouldHideCellTooltip(`header-${header.itemKey}`)"
23
24
  data-testid="header-cell"
24
25
  @click.stop="handleClickHeader(header)"
25
26
  >
@@ -66,6 +67,7 @@
66
67
  type="body"
67
68
  :size="size"
68
69
  :align="getHeaderAlign(header.align)"
70
+ :hideTooltip="shouldHideCellTooltip(`body-${header.itemKey}`)"
69
71
  data-testid="body-cell"
70
72
  >
71
73
  <slot
@@ -94,6 +96,9 @@
94
96
  <DataTableCell
95
97
  type="body"
96
98
  :size="size"
99
+ :hideTooltip="
100
+ props.hideTableTooltips || Boolean(slots['without-results'])
101
+ "
97
102
  data-testid="body-cell"
98
103
  >
99
104
  <slot
@@ -163,6 +168,7 @@ const props = withDefaults(defineProps<DataTableProps>(), {
163
168
  fixedHeaders: false,
164
169
  hideHeaders: false,
165
170
  hidePagination: false,
171
+ hideTableTooltips: false,
166
172
  page: 1,
167
173
  pageTotal: 0,
168
174
  pageInterval: 5,
@@ -200,6 +206,9 @@ const shouldHideHeaders = computed(() => {
200
206
  return props.hideHeaders || !props.headers.length;
201
207
  });
202
208
 
209
+ const shouldHideCellTooltip = (slotName: string) =>
210
+ props.hideTableTooltips || Boolean(slots[slotName]);
211
+
203
212
  const getHeaderAlign = (align?: DataTableHeader['align']): CellAlign =>
204
213
  align ?? 'left';
205
214
 
@@ -54,6 +54,7 @@ export interface DataTableProps {
54
54
  fixedHeaders?: boolean;
55
55
  hideHeaders?: boolean;
56
56
  hidePagination?: boolean;
57
+ hideTableTooltips?: boolean;
57
58
  page?: number;
58
59
  pageTotal?: number;
59
60
  pageInterval?: number;
@@ -115,6 +115,11 @@ export default {
115
115
  'Indicates whether more data is being loaded for infinite scroll. Shows a loading indicator at the bottom of the table.',
116
116
  control: 'boolean',
117
117
  },
118
+ hideTableTooltips: {
119
+ description:
120
+ 'Hides the tooltip shown when header or body text is truncated with an ellipsis.',
121
+ control: 'boolean',
122
+ },
118
123
  },
119
124
  render: (args) => ({
120
125
  components: {
@@ -411,6 +416,35 @@ export const HidePagination = {
411
416
  },
412
417
  };
413
418
 
419
+ export const TruncatedCells = {
420
+ args: {
421
+ hidePagination: true,
422
+ headers: [
423
+ {
424
+ title: 'Identifier with a very long header title that does not fit',
425
+ itemKey: 'id',
426
+ isSortable: true,
427
+ size: '140px',
428
+ },
429
+ {
430
+ title: 'Name',
431
+ itemKey: 'name',
432
+ size: '180px',
433
+ },
434
+ ],
435
+ items: [
436
+ {
437
+ id: 'INV-0001-ALPHA-LONG-IDENTIFIER',
438
+ name: 'Eduardo with a long display name that should truncate',
439
+ },
440
+ {
441
+ id: 'INV-0002',
442
+ name: 'Marcus',
443
+ },
444
+ ],
445
+ },
446
+ };
447
+
414
448
  export const WithoutResults = {
415
449
  args: {
416
450
  headers,