ads-nuxt 0.3.0 → 0.4.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/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`, loading e estado vazio. |
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. |
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
+ :virtualize="virtualize"
44
45
  :framed="framed"
45
46
  :density="density"
46
47
  :striped="false"
@@ -97,6 +98,8 @@ const props = withDefaults(
97
98
  * Padrão: "header" — cabeçalho fica no topo ao rolar horizontalmente.
98
99
  */
99
100
  sticky?: boolean | "header" | "footer";
101
+ /** Lista virtual para muitas linhas. Repassa ao AdsTable. */
102
+ virtualize?: boolean;
100
103
  emptyLabel?: string;
101
104
  emptyIcon?: string;
102
105
  loadingLabel?: string;
@@ -111,6 +114,7 @@ const props = withDefaults(
111
114
  skeletonRows: 5,
112
115
  skeletonVariant: "skeleton",
113
116
  sticky: "header",
117
+ virtualize: false,
114
118
  emptyLabel: "Nenhum registro encontrado",
115
119
  emptyIcon: "i-lucide-inbox",
116
120
  loadingLabel: undefined,
@@ -21,7 +21,9 @@
21
21
  :search-placeholder="searchPlaceholder"
22
22
  :list-label="label || 'Opções'"
23
23
  :width-class="panelWidthClass"
24
+ :add-label="addLabel"
24
25
  @pick="emit('pick', model)"
26
+ @add="onAdd"
25
27
  />
26
28
  </template>
27
29
 
@@ -90,7 +92,9 @@
90
92
  :search-placeholder="searchPlaceholder"
91
93
  :list-label="label || 'Opções'"
92
94
  :width-class="panelWidthClass"
95
+ :add-label="addLabel"
93
96
  @pick="onPick"
97
+ @add="onAdd"
94
98
  />
95
99
  </template>
96
100
  </UPopover>
@@ -141,6 +145,11 @@ const props = withDefaults(
141
145
  inline?: boolean;
142
146
  /** Largura da lista. Padrão: --ads-select-panel-width (320px). */
143
147
  panelWidthClass?: string;
148
+ /**
149
+ * Ação de cadastrar no rodapé da lista, com ícone de adicionar. `{query}` vira a busca atual,
150
+ * ex.: "Cadastrar {query}". Sem valor, a ação não aparece.
151
+ */
152
+ addLabel?: string;
144
153
  }>(),
145
154
  {
146
155
  placeholder: "Selecione",
@@ -164,6 +173,8 @@ const model = defineModel<string | string[]>({ required: true });
164
173
  const emit = defineEmits<{
165
174
  /** Escolha feita: no radio e no month o popover fecha. */
166
175
  pick: [value: string | string[]];
176
+ /** Ação de cadastrar. Recebe a busca atual. No popover, a lista fecha antes do evento. */
177
+ add: [query: string];
167
178
  }>();
168
179
 
169
180
  defineSlots<{
@@ -249,6 +260,12 @@ const onPick = () => {
249
260
  emit("pick", model.value);
250
261
  };
251
262
 
263
+ const onAdd = (text: string) => {
264
+ // No popover, a lista fecha: o cadastro costuma abrir um formulário ou modal por cima.
265
+ if (!props.inline) isOpen.value = false;
266
+ emit("add", text);
267
+ };
268
+
252
269
  watch(isOpen, (open) => {
253
270
  if (!open) query.value = "";
254
271
  });
@@ -3,6 +3,8 @@
3
3
  para mostrar só a lista, AdsSelect com inline.
4
4
  Seleção simples (radio) ou múltipla (checkbox), busca opcional no topo, "selecionar todos",
5
5
  subtítulo, selo e itens desabilitados. A lista rola a partir de 320px.
6
+ A lista é virtualizada (@tanstack/vue-virtual): só as linhas visíveis são montadas,
7
+ então milhares de opções não travam a tela. Altura medida por linha, pois subtítulo e selo mudam a altura.
6
8
  -->
7
9
  <template>
8
10
  <div
@@ -34,46 +36,69 @@
34
36
  </UInput>
35
37
  </div>
36
38
 
37
- <p
38
- v-if="groups.empty"
39
- class="flex min-h-12 items-center p-4 text-sm leading-[1.3] text-[var(--ads-text-secondary)]"
40
- >
41
- {{ emptyLabel }}
42
- </p>
43
-
44
39
  <div
45
- v-else
40
+ ref="scrollRef"
46
41
  class="max-h-[var(--ads-select-panel-max-height)] overflow-y-auto overscroll-contain [scrollbar-color:var(--color-ads-neutro-claro-50)_transparent] [scrollbar-width:thin]"
47
42
  :role="type === 'radio' ? 'listbox' : 'group'"
48
43
  :aria-label="listLabel"
49
44
  >
50
- <AdsSelectItem
51
- v-if="showSelectAll"
52
- mode="checkbox"
53
- :label="selectAllLabel"
54
- :selected="checkState === 'all'"
55
- :indeterminate="checkState === 'partial'"
56
- :divider="rows.length > 0"
57
- @select="onSelectAll"
58
- />
59
- <AdsSelectItem
60
- v-for="(option, index) in rows"
61
- :key="option.value"
62
- :mode="type"
63
- :label="option.label"
64
- :subtitle="option.subtitle"
65
- :badge="option.badge"
66
- :disabled="option.disabled"
67
- :selected="isSelected(option.value)"
68
- :divider="index < rows.length - 1"
69
- @select="onSelect(option.value)"
70
- />
45
+ <p
46
+ v-if="groups.empty"
47
+ class="flex min-h-12 items-center p-4 text-sm leading-[1.3] text-[var(--ads-text-secondary)]"
48
+ >
49
+ {{ emptyLabel }}
50
+ </p>
51
+
52
+ <div v-else class="relative w-full" :style="{ height: `${virtualizer.getTotalSize()}px` }">
53
+ <div
54
+ v-for="virtualRow in virtualizer.getVirtualItems()"
55
+ :key="virtualRow.key"
56
+ :ref="measureRow"
57
+ :data-index="virtualRow.index"
58
+ role="presentation"
59
+ class="absolute top-0 left-0 w-full"
60
+ :style="{ transform: `translateY(${virtualRow.start}px)` }"
61
+ >
62
+ <AdsSelectItem
63
+ v-if="!rowItems[virtualRow.index].option"
64
+ mode="checkbox"
65
+ :label="selectAllLabel"
66
+ :selected="checkState === 'all'"
67
+ :indeterminate="checkState === 'partial'"
68
+ :divider="rowItems.length > 1"
69
+ @select="onSelectAll"
70
+ />
71
+ <AdsSelectItem
72
+ v-else
73
+ :mode="type"
74
+ :label="rowItems[virtualRow.index].option!.label"
75
+ :subtitle="rowItems[virtualRow.index].option!.subtitle"
76
+ :badge="rowItems[virtualRow.index].option!.badge"
77
+ :disabled="rowItems[virtualRow.index].option!.disabled"
78
+ :selected="isSelected(rowItems[virtualRow.index].option!.value)"
79
+ :divider="virtualRow.index < rowItems.length - 1"
80
+ @select="onSelect(rowItems[virtualRow.index].option!.value)"
81
+ />
82
+ </div>
83
+ </div>
71
84
  </div>
85
+
86
+ <button
87
+ v-if="addText"
88
+ type="button"
89
+ class="flex min-h-12 w-full items-center gap-2 border-t border-[var(--ads-select-divider)] px-4 py-3 text-left text-sm leading-[1.3] font-bold text-[var(--ads-text-brand)] transition-colors hover:bg-[var(--ads-select-item-hover)] focus-visible:bg-[var(--ads-select-item-hover)] focus-visible:outline-none"
90
+ data-testid="select-add"
91
+ @click="emit('add', query.trim())"
92
+ >
93
+ <UIcon name="i-lucide-plus" class="size-4 shrink-0" aria-hidden="true" />
94
+ <span class="min-w-0 truncate">{{ addText }}</span>
95
+ </button>
72
96
  </div>
73
97
  </template>
74
98
 
75
99
  <script setup lang="ts">
76
- import { computed } from "vue";
100
+ import { computed, ref } from "vue";
101
+ import { useVirtualizer } from "@tanstack/vue-virtual";
77
102
  import AdsSelectItem from "./AdsSelectItem.vue";
78
103
  import {
79
104
  groupFilterOptions,
@@ -98,6 +123,11 @@ const props = withDefaults(
98
123
  listLabel?: string;
99
124
  /** Largura do painel. Padrão: --ads-select-panel-width (320px). */
100
125
  widthClass?: string;
126
+ /**
127
+ * Ação de cadastrar no rodapé, com ícone de adicionar. `{query}` vira a busca atual.
128
+ * Sem valor, a ação não aparece.
129
+ */
130
+ addLabel?: string;
101
131
  }>(),
102
132
  {
103
133
  searchable: true,
@@ -112,7 +142,18 @@ const props = withDefaults(
112
142
 
113
143
  const model = defineModel<string | string[]>({ required: true });
114
144
  const query = defineModel<string>("query", { default: "" });
115
- const emit = defineEmits<{ pick: [] }>();
145
+ const emit = defineEmits<{
146
+ pick: [];
147
+ /** Ação de cadastrar. Recebe a busca atual, sem espaços nas pontas. */
148
+ add: [query: string];
149
+ }>();
150
+
151
+ /** Texto da ação: `{query}` recebe a busca; sem busca, o trecho some. */
152
+ const addText = computed(() => {
153
+ if (!props.addLabel) return "";
154
+ const text = props.addLabel.replaceAll("{query}", query.value.trim());
155
+ return text.replace(/\s+/g, " ").trim();
156
+ });
116
157
 
117
158
  const groups = computed(() => groupFilterOptions(props.options, query.value));
118
159
  /** Correspondência exata da busca vem primeiro. */
@@ -122,12 +163,42 @@ const enabledOptions = computed(() => props.options.filter((option) => !option.d
122
163
  const selectedList = computed(() =>
123
164
  Array.isArray(model.value) ? model.value : model.value ? [model.value] : [],
124
165
  );
166
+ const selectedSet = computed(() => new Set(selectedList.value));
125
167
  const checkState = computed(() => selectionCheckState(selectedList.value, enabledOptions.value));
126
168
  const showSelectAll = computed(
127
169
  () => props.type === "checkbox" && props.selectAll && query.value.trim() === "",
128
170
  );
129
171
 
130
- const isSelected = (value: string) => selectedList.value.includes(value);
172
+ /** Linhas da lista virtual: "selecionar todos" (sem option) no começo, quando aparece. */
173
+ interface PanelRow {
174
+ key: string;
175
+ option?: FilterOption;
176
+ }
177
+ const rowItems = computed<PanelRow[]>(() => {
178
+ const list = rows.value.map((option) => ({ key: option.value, option }));
179
+ return showSelectAll.value ? [{ key: SELECT_ALL_KEY }, ...list] : list;
180
+ });
181
+
182
+ const SELECT_ALL_KEY = "__select-all__";
183
+ /** Altura mínima de uma linha (min-h-12). A medida real corrige linhas com subtítulo ou selo. */
184
+ const ROW_ESTIMATE = 48;
185
+
186
+ const scrollRef = ref<HTMLElement | null>(null);
187
+ const virtualizer = useVirtualizer(
188
+ computed(() => ({
189
+ count: rowItems.value.length,
190
+ getScrollElement: () => scrollRef.value,
191
+ estimateSize: () => ROW_ESTIMATE,
192
+ overscan: 8,
193
+ getItemKey: (index: number) => rowItems.value[index]?.key ?? index,
194
+ })),
195
+ );
196
+
197
+ const measureRow = (el: unknown) => {
198
+ if (el instanceof HTMLElement) virtualizer.value.measureElement(el);
199
+ };
200
+
201
+ const isSelected = (value: string) => selectedSet.value.has(value);
131
202
 
132
203
  const onSelect = (value: string) => {
133
204
  if (props.type === "radio") {
@@ -1,9 +1,11 @@
1
1
  <template>
2
2
  <UTable
3
+ :key="virtualize ? 'virtual' : 'static'"
3
4
  :data="data"
4
5
  :columns="columns"
5
6
  :loading="loading"
6
7
  :sticky="sticky"
8
+ :virtualize="virtualizeOptions"
7
9
  :ui="tableUi"
8
10
  >
9
11
  <template v-if="!$slots.loading" #loading>
@@ -75,8 +77,13 @@ const props = withDefaults(
75
77
  skeletonVariant?: AdsTableSkeletonVariant;
76
78
  /** Altura e respiro da linha do skeleton, quando a tabela foge do padrão da densidade. */
77
79
  skeletonCellSize?: string;
78
- /** Cabeçalho (e rodapé) fixos quando a tabela tem altura máxima. */
80
+ /** Cabeçalho (e rodapé) fixos. A tabela ganha altura máxima de 70vh; max-h na classe sobrescreve. */
79
81
  sticky?: boolean | "header" | "footer";
82
+ /**
83
+ * Lista virtual: só as linhas visíveis são montadas. Use com muitas linhas (centenas ou mais).
84
+ * Precisa de rolagem própria (sticky ou max-h), senão a tabela inteira é montada.
85
+ */
86
+ virtualize?: boolean;
80
87
  /** Linha de 1px na borda da coluna fixa. */
81
88
  pinnedEdge?: boolean;
82
89
  emptyLabel?: string;
@@ -96,6 +103,7 @@ const props = withDefaults(
96
103
  skeletonVariant: "skeleton",
97
104
  skeletonCellSize: undefined,
98
105
  sticky: false,
106
+ virtualize: false,
99
107
  pinnedEdge: true,
100
108
  emptyLabel: "Nenhum registro encontrado",
101
109
  emptyIcon: "i-lucide-inbox",
@@ -128,6 +136,13 @@ const skeletonColumns = computed((): AdsTableSkeletonAlign[] => {
128
136
  });
129
137
  });
130
138
 
139
+ /** Altura estimada da linha pela densidade; a medida real corrige linhas com conteúdo maior. */
140
+ const virtualizeOptions = computed(() =>
141
+ props.virtualize
142
+ ? { estimateSize: props.density === "md" ? 64 : 40, overscan: 12 }
143
+ : false,
144
+ );
145
+
131
146
  const tableUi = computed(() => {
132
147
  const base = buildAdsTableUi({
133
148
  density: props.density,
@@ -98,6 +98,9 @@ export const buildAdsTableUi = ({
98
98
  return {
99
99
  root: [
100
100
  "relative overflow-auto bg-[var(--ads-surface-card)]",
101
+ // O cabeçalho gruda na rolagem da própria tabela: sem altura máxima ela não rola e o
102
+ // cabeçalho sai junto com a página. Uma classe max-h do consumidor sobrescreve esta.
103
+ stickyHeader ? "max-h-[70vh]" : "",
101
104
  "[scrollbar-color:var(--ads-border-subtle)_transparent] [scrollbar-width:thin]",
102
105
  framed ? "rounded-[var(--ads-radius-md)] border border-[var(--ads-border-subtle)]" : "",
103
106
  ].join(" "),
package/package.json CHANGED
@@ -1,55 +1,56 @@
1
- {
2
- "name": "ads-nuxt",
3
- "version": "0.3.0",
4
- "license": "MIT",
5
- "description": "Alquimia Design System para Nuxt, construído sobre Nuxt UI",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/jbfarmarcas/alquimia-design-system.git"
9
- },
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "type": "module",
14
- "packageManager": "pnpm@10.4.1",
15
- "main": "./nuxt.config.ts",
16
- "files": [
17
- "app",
18
- "nuxt.config.ts"
19
- ],
20
- "scripts": {
21
- "dev": "nuxt dev playground --port 3010",
22
- "build": "nuxt build playground",
23
- "preview": "nuxt preview playground --port 3010",
24
- "prepare": "nuxt prepare playground",
25
- "skill:reference": "node scripts/generate-skill-reference.mjs",
26
- "skill:check": "node scripts/generate-skill-reference.mjs --check"
27
- },
28
- "dependencies": {
29
- "@iconify-json/lucide": "^1.2.104"
30
- },
31
- "peerDependencies": {
32
- "@internationalized/date": "^3.12.4",
33
- "@nuxt/fonts": "^0.12.1 || ^0.14.0",
34
- "@nuxt/icon": "^2.2.0",
35
- "@nuxt/ui": "^4.3.0",
36
- "@vueuse/core": "^14.0.0",
37
- "@vueuse/nuxt": "^14.0.0",
38
- "nuxt": "^4.0.0",
39
- "tailwindcss": "^4.0.15",
40
- "vue": "^3.5.18"
41
- },
42
- "devDependencies": {
43
- "@internationalized/date": "^3.12.4",
44
- "@nuxt/fonts": "^0.12.1",
45
- "@nuxt/icon": "^2.2.0",
46
- "@nuxt/ui": "^4.3.0",
47
- "@vueuse/core": "^14.0.0",
48
- "@vueuse/nuxt": "^14.0.0",
49
- "nuxt": "^4.0.0",
50
- "tailwindcss": "^4.0.15",
51
- "typescript": "^5.6.3",
52
- "vue": "^3.5.18",
53
- "vue-router": "^4.5.0"
54
- }
55
- }
1
+ {
2
+ "name": "ads-nuxt",
3
+ "version": "0.4.0",
4
+ "license": "MIT",
5
+ "description": "Alquimia Design System para Nuxt, construído sobre Nuxt UI",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/jbfarmarcas/alquimia-design-system.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "type": "module",
14
+ "packageManager": "pnpm@10.4.1",
15
+ "main": "./nuxt.config.ts",
16
+ "files": [
17
+ "app",
18
+ "nuxt.config.ts"
19
+ ],
20
+ "scripts": {
21
+ "dev": "nuxt dev playground --port 3010",
22
+ "build": "nuxt build playground",
23
+ "preview": "nuxt preview playground --port 3010",
24
+ "prepare": "nuxt prepare playground",
25
+ "skill:reference": "node scripts/generate-skill-reference.mjs",
26
+ "skill:check": "node scripts/generate-skill-reference.mjs --check"
27
+ },
28
+ "dependencies": {
29
+ "@iconify-json/lucide": "^1.2.104",
30
+ "@tanstack/vue-virtual": "^3.13.49"
31
+ },
32
+ "peerDependencies": {
33
+ "@internationalized/date": "^3.12.4",
34
+ "@nuxt/fonts": "^0.12.1 || ^0.14.0",
35
+ "@nuxt/icon": "^2.2.0",
36
+ "@nuxt/ui": "^4.3.0",
37
+ "@vueuse/core": "^14.0.0",
38
+ "@vueuse/nuxt": "^14.0.0",
39
+ "nuxt": "^4.0.0",
40
+ "tailwindcss": "^4.0.15",
41
+ "vue": "^3.5.18"
42
+ },
43
+ "devDependencies": {
44
+ "@internationalized/date": "^3.12.4",
45
+ "@nuxt/fonts": "^0.12.1",
46
+ "@nuxt/icon": "^2.2.0",
47
+ "@nuxt/ui": "^4.3.0",
48
+ "@vueuse/core": "^14.0.0",
49
+ "@vueuse/nuxt": "^14.0.0",
50
+ "nuxt": "^4.0.0",
51
+ "tailwindcss": "^4.0.15",
52
+ "typescript": "^5.6.3",
53
+ "vue": "^3.5.18",
54
+ "vue-router": "^4.5.0"
55
+ }
56
+ }