ads-nuxt 0.6.4 → 0.6.5

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/README.md CHANGED
@@ -186,7 +186,7 @@ const nome = ref("");
186
186
 
187
187
  | Componente | Descrição |
188
188
  | ----------------- | --------- |
189
- | `AdsTable` | Tabela baseada no `UTable`, com densidade, zebra, bordas, degradê por nível, `sticky` (cabeçalho fixo), `virtualize` (lista virtual para muitas linhas), loading e estado vazio. |
189
+ | `AdsTable` | Tabela baseada no `UTable`, com densidade, zebra, bordas, degradê por nível, `sticky` / `sticky-scrollbar` (opt-in), `virtualize` (lista virtual), loading e estado vazio. |
190
190
  | `AdsTableToolbar` | Barra de ferramentas da tabela. |
191
191
  | `AdsCard` | Cartão genérico. |
192
192
  | `AdsMetricCard` | Cartão de métrica/indicador. |
@@ -41,6 +41,7 @@
41
41
  :skeleton-variant="skeletonVariant"
42
42
  :skeleton-cell-size="adsHeavyCellSize(density)"
43
43
  :sticky="sticky"
44
+ :sticky-scrollbar="stickyScrollbar"
44
45
  :virtualize="virtualize"
45
46
  :framed="framed"
46
47
  :density="density"
@@ -71,6 +72,7 @@ import {
71
72
  mergeAdsTableUi,
72
73
  type AdsTableBorders,
73
74
  type AdsTableDensity,
75
+ type AdsTableSticky,
74
76
  type AdsTableUi,
75
77
  } from "../utils/ads-table";
76
78
 
@@ -97,8 +99,14 @@ const props = withDefaults(
97
99
  /**
98
100
  * Cabeçalho fixo quando a tabela tem altura máxima.
99
101
  * Padrão: "header" — cabeçalho fica no topo ao rolar horizontalmente.
102
+ * `all` = mesmo efeito de `header` (colunas fixas via column-pinning).
100
103
  */
101
- sticky?: boolean | "header" | "footer";
104
+ sticky?: AdsTableSticky;
105
+ /**
106
+ * Barra de rolagem horizontal sticky. Repassa ao AdsTable.
107
+ * Padrão: desligado.
108
+ */
109
+ stickyScrollbar?: boolean;
102
110
  /** Lista virtual para muitas linhas. Repassa ao AdsTable. */
103
111
  virtualize?: boolean;
104
112
  emptyLabel?: string;
@@ -115,6 +123,7 @@ const props = withDefaults(
115
123
  skeletonRows: 5,
116
124
  skeletonVariant: "skeleton",
117
125
  sticky: "header",
126
+ stickyScrollbar: false,
118
127
  virtualize: false,
119
128
  emptyLabel: "Nenhum registro encontrado",
120
129
  emptyIcon: "i-lucide-inbox",
@@ -128,7 +137,10 @@ const mergedUi = computed((): AdsTableUi => {
128
137
  density: props.density,
129
138
  framed: props.framed,
130
139
  borders: props.borders,
131
- stickyHeader: props.sticky === true || props.sticky === "header",
140
+ stickyHeader:
141
+ props.sticky === true ||
142
+ props.sticky === "header" ||
143
+ props.sticky === "all",
132
144
  });
133
145
  return mergeAdsTableUi(base, props.ui);
134
146
  });
@@ -1,42 +1,60 @@
1
1
  <template>
2
- <UTable
3
- :key="virtualize ? 'virtual' : 'static'"
4
- :data="data"
5
- :columns="columns"
6
- :loading="loading"
7
- :sticky="sticky"
8
- :virtualize="virtualizeOptions"
9
- :ui="tableUi"
2
+ <div
3
+ ref="shellEl"
4
+ class="ads-table-shell relative min-w-0"
10
5
  >
11
- <template v-if="!$slots.loading" #loading>
12
- <AdsTableSkeleton
13
- :rows="skeletonRows"
14
- :variant="skeletonVariant"
15
- :columns="skeletonColumns"
16
- :cell-class="skeletonCellSize ?? adsTableCellSize(density)"
17
- />
18
- </template>
19
-
20
- <template v-if="!$slots.empty" #empty>
21
- <div class="flex flex-col items-center gap-2">
22
- <UIcon
23
- :name="emptyIcon"
24
- class="size-6 text-[var(--ads-border-icon-support)]"
25
- aria-hidden="true"
6
+ <UTable
7
+ :key="virtualize ? 'virtual' : 'static'"
8
+ :data="data"
9
+ :columns="columns"
10
+ :loading="loading"
11
+ :sticky="uTableSticky"
12
+ :virtualize="virtualizeOptions"
13
+ :ui="tableUi"
14
+ >
15
+ <template v-if="!$slots.loading" #loading>
16
+ <AdsTableSkeleton
17
+ :rows="skeletonRows"
18
+ :variant="skeletonVariant"
19
+ :columns="skeletonColumns"
20
+ :cell-class="skeletonCellSize ?? adsTableCellSize(density)"
26
21
  />
27
- <p class="text-sm text-[var(--ads-text-secondary)]">{{ emptyLabel }}</p>
28
- </div>
29
- </template>
30
-
31
- <template v-for="(_, name) in $slots" #[name]="slotProps">
32
- <slot :name="name" v-bind="slotProps ?? {}" />
33
- </template>
34
- </UTable>
22
+ </template>
23
+
24
+ <template v-if="!$slots.empty" #empty>
25
+ <div class="flex flex-col items-center gap-2">
26
+ <UIcon
27
+ :name="emptyIcon"
28
+ class="size-6 text-[var(--ads-border-icon-support)]"
29
+ aria-hidden="true"
30
+ />
31
+ <p class="text-sm text-[var(--ads-text-secondary)]">{{ emptyLabel }}</p>
32
+ </div>
33
+ </template>
34
+
35
+ <template v-for="(_, name) in $slots" #[name]="slotProps">
36
+ <slot :name="name" v-bind="slotProps ?? {}" />
37
+ </template>
38
+ </UTable>
39
+
40
+ <div
41
+ v-show="stickyScrollbar && needsFakeScroll"
42
+ ref="fakeScroller"
43
+ class="sticky bottom-0 z-20 overflow-x-auto border-t border-[var(--ads-border-subtle)] bg-[var(--ads-surface-card)] [scrollbar-color:var(--ads-border-subtle)_transparent] [scrollbar-width:thin]"
44
+ aria-hidden="true"
45
+ >
46
+ <div
47
+ class="h-3"
48
+ :style="{ width: `${scrollContentWidth}px` }"
49
+ />
50
+ </div>
51
+ </div>
35
52
  </template>
36
53
 
37
54
  <script setup lang="ts" generic="T extends TableData">
38
- import { computed, useAttrs, useSlots } from "vue";
55
+ import { computed, nextTick, onMounted, ref, useAttrs, useSlots, watch } from "vue";
39
56
  import type { TableColumn, TableData } from "@nuxt/ui";
57
+ import { useEventListener, useResizeObserver } from "@vueuse/core";
40
58
  import AdsTableSkeleton, {
41
59
  type AdsTableSkeletonAlign,
42
60
  type AdsTableSkeletonVariant,
@@ -47,6 +65,7 @@ import {
47
65
  mergeAdsTableUi,
48
66
  type AdsTableBorders,
49
67
  type AdsTableDensity,
68
+ type AdsTableSticky,
50
69
  type AdsTableUi,
51
70
  } from "../utils/ads-table";
52
71
 
@@ -78,8 +97,17 @@ const props = withDefaults(
78
97
  skeletonVariant?: AdsTableSkeletonVariant;
79
98
  /** Altura e respiro da linha do skeleton, quando a tabela foge do padrão da densidade. */
80
99
  skeletonCellSize?: string;
81
- /** Cabeçalho (e rodapé) fixos. A tabela ganha altura máxima de 70vh; max-h na classe sobrescreve. */
82
- sticky?: boolean | "header" | "footer";
100
+ /**
101
+ * Cabeçalho (e rodapé) fixos. A tabela ganha altura máxima de 70vh; max-h na classe sobrescreve.
102
+ * `all` = mesmo efeito de `header` (colunas fixas vêm de `v-model:column-pinning`).
103
+ */
104
+ sticky?: AdsTableSticky;
105
+ /**
106
+ * Barra de rolagem horizontal sticky no rodapé da viewport da tabela.
107
+ * Sincroniza com o overflow do root; esconde a barra nativa horizontal.
108
+ * Padrão: desligado.
109
+ */
110
+ stickyScrollbar?: boolean;
83
111
  /**
84
112
  * Lista virtual: só as linhas visíveis são montadas. Use com muitas linhas (centenas ou mais).
85
113
  * Precisa de rolagem própria (sticky ou max-h), senão a tabela inteira é montada.
@@ -104,6 +132,7 @@ const props = withDefaults(
104
132
  skeletonVariant: "skeleton",
105
133
  skeletonCellSize: undefined,
106
134
  sticky: false,
135
+ stickyScrollbar: false,
107
136
  virtualize: false,
108
137
  pinnedEdge: true,
109
138
  emptyLabel: "Nenhum registro encontrado",
@@ -116,6 +145,27 @@ const props = withDefaults(
116
145
  const slots = useSlots();
117
146
  const attrs = useAttrs();
118
147
 
148
+ const shellEl = ref<HTMLElement | null>(null);
149
+ const fakeScroller = ref<HTMLElement | null>(null);
150
+ const tableScroller = ref<HTMLElement | null>(null);
151
+ const scrollContentWidth = ref(0);
152
+ const needsFakeScroll = ref(false);
153
+
154
+ let isSyncingScroll = false;
155
+
156
+ /** UTable não conhece `all`; mapeia para cabeçalho fixo. */
157
+ const uTableSticky = computed(() => {
158
+ if (props.sticky === "all" || props.sticky === true) return "header" as const;
159
+ return props.sticky;
160
+ });
161
+
162
+ const stickyHeaderEnabled = computed(
163
+ () =>
164
+ props.sticky === true ||
165
+ props.sticky === "header" ||
166
+ props.sticky === "all",
167
+ );
168
+
119
169
  const leafColumns = (columns: TableColumn<T>[]): TableColumn<T>[] =>
120
170
  columns.flatMap((column) =>
121
171
  "columns" in column && column.columns?.length ? leafColumns(column.columns) : [column],
@@ -151,11 +201,16 @@ const tableUi = computed(() => {
151
201
  framed: props.framed,
152
202
  borders: props.borders,
153
203
  depth: props.depth,
154
- stickyHeader: props.sticky === true || props.sticky === "header",
204
+ stickyHeader: stickyHeaderEnabled.value,
155
205
  pinnedEdge: props.pinnedEdge,
156
206
  });
157
207
  // Marca para o CSS do AdsCard alinhar a primeira coluna. Fora do card, não faz nada.
158
208
  base.root = `${base.root} ads-table`.trim();
209
+ if (props.stickyScrollbar) {
210
+ // A barra fake assume o eixo X; a nativa horizontal some para não duplicar.
211
+ base.root =
212
+ `${base.root} [scrollbar-width:thin] [&::-webkit-scrollbar:horizontal]:h-0`.trim();
213
+ }
159
214
  if (!slots.expanded) {
160
215
  // Árvore via getSubRows: o UTable sempre desenha a linha de detalhe da linha aberta.
161
216
  base.tbody = `${base.tbody} [&>tr[data-slot=tr]:not([data-selectable])]:hidden`;
@@ -171,4 +226,61 @@ const tableUi = computed(() => {
171
226
  }
172
227
  return mergeAdsTableUi(base, props.ui);
173
228
  });
229
+
230
+ const resolveTableScroller = () => {
231
+ const root = shellEl.value?.querySelector<HTMLElement>(".ads-table");
232
+ tableScroller.value = root ?? null;
233
+ return tableScroller.value;
234
+ };
235
+
236
+ const syncScrollLeft = (from: HTMLElement | null, to: HTMLElement | null) => {
237
+ if (isSyncingScroll || !from || !to || from.scrollLeft === to.scrollLeft) return;
238
+ isSyncingScroll = true;
239
+ to.scrollLeft = from.scrollLeft;
240
+ isSyncingScroll = false;
241
+ };
242
+
243
+ const measureFakeScroll = () => {
244
+ if (!props.stickyScrollbar) {
245
+ scrollContentWidth.value = 0;
246
+ needsFakeScroll.value = false;
247
+ return;
248
+ }
249
+ const el = resolveTableScroller();
250
+ if (!el) {
251
+ scrollContentWidth.value = 0;
252
+ needsFakeScroll.value = false;
253
+ return;
254
+ }
255
+ scrollContentWidth.value = el.scrollWidth;
256
+ needsFakeScroll.value = el.scrollWidth > el.clientWidth + 1;
257
+ };
258
+
259
+ useEventListener(tableScroller, "scroll", () => {
260
+ if (!props.stickyScrollbar) return;
261
+ syncScrollLeft(tableScroller.value, fakeScroller.value);
262
+ });
263
+ useEventListener(fakeScroller, "scroll", () => {
264
+ if (!props.stickyScrollbar) return;
265
+ syncScrollLeft(fakeScroller.value, tableScroller.value);
266
+ });
267
+
268
+ useResizeObserver(shellEl, () => {
269
+ void nextTick(measureFakeScroll);
270
+ });
271
+
272
+ onMounted(() => {
273
+ resolveTableScroller();
274
+ measureFakeScroll();
275
+ });
276
+
277
+ watch(
278
+ () => [props.data, props.columns, props.stickyScrollbar, props.sticky, props.ui] as const,
279
+ () => {
280
+ void nextTick(() => {
281
+ resolveTableScroller();
282
+ measureFakeScroll();
283
+ });
284
+ },
285
+ );
174
286
  </script>
@@ -29,6 +29,13 @@ export type AdsTableDensity = "md" | "sm";
29
29
  /** lines: só a divisória horizontal. grid: divisória horizontal e vertical. */
30
30
  export type AdsTableBorders = "lines" | "grid";
31
31
 
32
+ /**
33
+ * sticky do AdsTable.
34
+ * `all` = mesmo efeito de `header` (colunas fixas vêm de column-pinning).
35
+ */
36
+ export type AdsTableSticky = boolean | "header" | "footer" | "all";
37
+
38
+
32
39
  export interface AdsTableLook {
33
40
  /** Só o respiro da célula. A fonte não muda. */
34
41
  density?: AdsTableDensity;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ads-nuxt",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "license": "MIT",
5
5
  "description": "Alquimia Design System para Nuxt, construído sobre Nuxt UI",
6
6
  "repository": {