ads-nuxt 0.2.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.
Files changed (44) hide show
  1. package/README.md +6 -4
  2. package/app/assets/css/component-tokens.css +369 -367
  3. package/app/assets/css/main.css +26 -65
  4. package/app/components/AdsBadge.vue +3 -3
  5. package/app/components/AdsBroadcast.vue +1 -1
  6. package/app/components/AdsButton.vue +13 -5
  7. package/app/components/AdsButtonMenu.vue +2 -2
  8. package/app/components/AdsCharttip.vue +3 -2
  9. package/app/components/AdsCheckbox.vue +77 -77
  10. package/app/components/AdsDatePicker.vue +23 -6
  11. package/app/components/AdsEmptyState.vue +6 -3
  12. package/app/components/AdsHeavyTable.vue +4 -0
  13. package/app/components/AdsInput.vue +3 -2
  14. package/app/components/AdsMenuBar.vue +8 -1
  15. package/app/components/AdsMetricCard.vue +1 -1
  16. package/app/components/AdsModal.vue +7 -4
  17. package/app/components/AdsNavbarApp.vue +1 -1
  18. package/app/components/AdsNavbarDesk.vue +14 -9
  19. package/app/components/AdsNumberInput.vue +8 -8
  20. package/app/components/AdsPagination.vue +91 -91
  21. package/app/components/AdsPill.vue +1 -1
  22. package/app/components/AdsProductTag.vue +21 -2
  23. package/app/components/AdsRadio.vue +70 -70
  24. package/app/components/AdsSearchInput.vue +2 -2
  25. package/app/components/AdsSelect.vue +18 -1
  26. package/app/components/AdsSelectPanel.vue +103 -32
  27. package/app/components/AdsSteptip.vue +104 -101
  28. package/app/components/AdsSwitch.vue +59 -59
  29. package/app/components/AdsTable.vue +16 -1
  30. package/app/components/AdsTextarea.vue +2 -2
  31. package/app/components/AdsToast.vue +6 -5
  32. package/app/components/AdsTooltip.vue +2 -2
  33. package/app/components/OverlayLoading.vue +313 -173
  34. package/app/composables/useOverlayLoading.ts +31 -9
  35. package/app/theme/ads-theme.ts +1 -1
  36. package/app/theme/component-tokens.json +368 -366
  37. package/app/theme/component-tokens.ts +809 -807
  38. package/app/types/overlay-loading.types.ts +11 -2
  39. package/app/utils/ads-table.ts +3 -0
  40. package/package.json +56 -55
  41. package/app/assets/animations/Error.gif +0 -0
  42. package/app/assets/animations/Loading.gif +0 -0
  43. package/app/assets/animations/Search.gif +0 -0
  44. package/app/assets/animations/Success.gif +0 -0
@@ -1,173 +1,313 @@
1
- <template>
2
- <UModal
3
- :model-value="true"
4
- :dismissible="false"
5
- :close="isClosable ? { onClick: handleClose } : false"
6
- :ui="{
7
- overlay: 'backdrop-blur-lg',
8
- content: 'bg-transparent shadow-none ring-0',
9
- }"
10
- >
11
- <template #description>
12
- <div class="sr-only">
13
- {{ description }}
14
- </div>
15
- </template>
16
-
17
- <template #title>
18
- <div class="sr-only">
19
- {{ title }}
20
- </div>
21
- </template>
22
-
23
- <template #content>
24
- <div class="text-center">
25
- <div class="mb-4 flex justify-center">
26
- <div
27
- class="flex aspect-square h-20 items-center justify-center rounded-full"
28
- :class="iconWrapperClass"
29
- >
30
- <img :src="animationSrc" :alt="variant" class="w-full">
31
- </div>
32
- </div>
33
-
34
- <h3 class="mb-2 text-lg font-semibold" :class="titleColorClass">
35
- {{ title }}
36
- </h3>
37
-
38
- <p
39
- class="mb-4 text-sm tabular-nums"
40
- :class="descriptionColorClass"
41
- role="status"
42
- aria-live="polite"
43
- >
44
- {{ description }}
45
- </p>
46
-
47
- <UProgress
48
- v-if="showProgress"
49
- :model-value="progress"
50
- :max="100"
51
- size="sm"
52
- class="mx-auto mb-4 max-w-xs"
53
- />
54
-
55
- <p
56
- v-if="hint"
57
- class="mb-4 text-xs tabular-nums text-neutral-500"
58
- aria-live="polite"
59
- >
60
- {{ hint }}
61
- </p>
62
-
63
- <AdsButton
64
- v-if="actionLabel"
65
- leading
66
- icon="i-lucide-refresh-cw"
67
- :label="actionLabel"
68
- @click="onAction?.()"
69
- />
70
-
71
- <slot />
72
- </div>
73
- </template>
74
- </UModal>
75
- </template>
76
-
77
- <script setup lang="ts">
78
- import { computed } from "vue";
79
- import type { OverlayLoadingProps } from "../types/overlay-loading.types";
80
- import ErrorGif from "../assets/animations/Error.gif";
81
- import LoadingGif from "../assets/animations/Loading.gif";
82
- import SearchGif from "../assets/animations/Search.gif";
83
- import SuccessGif from "../assets/animations/Success.gif";
84
- import AdsButton from "./AdsButton.vue";
85
-
86
- const emit = defineEmits<{
87
- close: [];
88
- }>();
89
-
90
- const props = withDefaults(defineProps<OverlayLoadingProps>(), {
91
- title: "Carregando...",
92
- description: "Aguarde enquanto processamos as informações.",
93
- hint: "",
94
- showProgress: false,
95
- progress: 0,
96
- variant: "loading",
97
- iconSrc: "",
98
- actionLabel: "",
99
- onAction: undefined,
100
- onUserClose: undefined,
101
- closableVariants: () => ["success", "error"],
102
- });
103
-
104
- const isClosable = computed(() =>
105
- props.closableVariants.includes(
106
- props.variant as "success" | "error"
107
- )
108
- );
109
-
110
- const iconWrapperClass = computed(() => {
111
- switch (props.variant) {
112
- case "success":
113
- return "bg-success-100";
114
- case "error":
115
- return "bg-error-100";
116
- case "info":
117
- return "bg-primary-100";
118
- default:
119
- return "bg-neutral-100";
120
- }
121
- });
122
-
123
- const titleColorClass = computed(() => {
124
- switch (props.variant) {
125
- case "success":
126
- return "text-emerald-800";
127
- case "error":
128
- return "text-red-800";
129
- case "info":
130
- return "text-blue-800";
131
- default:
132
- return "text-gray-900";
133
- }
134
- });
135
-
136
- const descriptionColorClass = computed(() => {
137
- switch (props.variant) {
138
- case "success":
139
- return "text-success-700";
140
- case "error":
141
- return "text-error-700";
142
- case "info":
143
- return "text-primary-700";
144
- default:
145
- return "text-neutral-600";
146
- }
147
- });
148
-
149
- const animationSrc = computed(() => {
150
- if (props.iconSrc) {
151
- return props.iconSrc;
152
- }
153
-
154
- switch (props.variant) {
155
- case "success":
156
- return SuccessGif;
157
- case "error":
158
- return ErrorGif;
159
- case "search":
160
- return SearchGif;
161
- case "loading":
162
- case "info":
163
- default:
164
- return LoadingGif;
165
- }
166
- });
167
-
168
- const handleClose = () => {
169
- props.onUserClose?.();
170
- emit("close");
171
- };
172
- </script>
173
-
1
+ <template>
2
+ <UModal
3
+ :model-value="true"
4
+ :dismissible="false"
5
+ :ui="{
6
+ overlay: 'backdrop-blur-lg',
7
+ content: 'bg-transparent shadow-none ring-0',
8
+ }"
9
+ >
10
+ <template #description>
11
+ <div class="sr-only">
12
+ {{ description }}
13
+ </div>
14
+ </template>
15
+
16
+ <template #title>
17
+ <div class="sr-only">
18
+ {{ title }}
19
+ </div>
20
+ </template>
21
+
22
+ <template #content>
23
+ <div class="relative px-10 pt-2 text-center">
24
+ <!-- O slot #content substitui o cabeçalho do UModal, então o X fica aqui. -->
25
+ <button
26
+ v-if="isClosable"
27
+ type="button"
28
+ class="absolute top-0 right-0 flex size-8 items-center justify-center rounded-[var(--ads-radius-xsm)] text-[var(--ads-text-secondary)] hover:bg-black/5 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ads-text-brand)]"
29
+ aria-label="Fechar"
30
+ @click="handleClose"
31
+ >
32
+ <UIcon name="i-lucide-x" class="size-5" />
33
+ </button>
34
+ <div class="mb-4 flex justify-center">
35
+ <div
36
+ class="flex aspect-square h-20 items-center justify-center rounded-full"
37
+ :class="feedback.surface"
38
+ >
39
+ <img v-if="iconSrc" :src="iconSrc" alt="" class="w-full">
40
+ <UIcon
41
+ v-else
42
+ :key="variant"
43
+ :name="feedback.icon"
44
+ mode="svg"
45
+ class="ads-overlay-icon size-10"
46
+ :class="[feedback.color, feedback.animation]"
47
+ aria-hidden="true"
48
+ />
49
+ </div>
50
+ </div>
51
+
52
+ <h3 class="mb-2 text-lg leading-[1.3] font-bold" :class="feedback.title">
53
+ {{ title }}
54
+ </h3>
55
+
56
+ <p
57
+ class="mb-4 text-sm leading-[1.3] tabular-nums"
58
+ :class="feedback.description"
59
+ role="status"
60
+ aria-live="polite"
61
+ >
62
+ {{ description }}
63
+ </p>
64
+
65
+ <UProgress
66
+ v-if="showProgress"
67
+ :model-value="progress"
68
+ :max="100"
69
+ size="sm"
70
+ class="mx-auto mb-4 max-w-xs"
71
+ />
72
+
73
+ <p
74
+ v-if="hint"
75
+ class="mb-4 text-xs tabular-nums text-[var(--ads-text-tertiary)]"
76
+ aria-live="polite"
77
+ >
78
+ {{ hint }}
79
+ </p>
80
+
81
+ <div
82
+ v-if="actionLabel || secondaryActionLabel"
83
+ class="flex flex-wrap items-center justify-center gap-2"
84
+ >
85
+ <AdsButton
86
+ v-if="actionLabel"
87
+ :leading="Boolean(resolvedActionIcon)"
88
+ :icon="resolvedActionIcon"
89
+ :label="actionLabel"
90
+ @click="onAction?.()"
91
+ />
92
+ <AdsButton
93
+ v-if="secondaryActionLabel"
94
+ type="unfilled"
95
+ :leading="Boolean(secondaryActionIcon)"
96
+ :icon="secondaryActionIcon"
97
+ :label="secondaryActionLabel"
98
+ @click="onSecondaryClick"
99
+ />
100
+ </div>
101
+
102
+ <slot />
103
+ </div>
104
+ </template>
105
+ </UModal>
106
+ </template>
107
+
108
+ <script setup lang="ts">
109
+ import { computed } from "vue";
110
+ import type { OverlayLoadingProps, OverlayVariant } from "../types/overlay-loading.types";
111
+ import AdsButton from "./AdsButton.vue";
112
+
113
+ const emit = defineEmits<{
114
+ close: [];
115
+ }>();
116
+
117
+ const props = withDefaults(defineProps<OverlayLoadingProps>(), {
118
+ title: "Carregando...",
119
+ description: "Aguarde enquanto processamos as informações.",
120
+ hint: "",
121
+ showProgress: false,
122
+ progress: 0,
123
+ variant: "loading",
124
+ iconSrc: "",
125
+ actionLabel: "",
126
+ actionIcon: undefined,
127
+ onAction: undefined,
128
+ secondaryActionLabel: "",
129
+ secondaryActionIcon: undefined,
130
+ onSecondaryAction: undefined,
131
+ onUserClose: undefined,
132
+ closableVariants: () => ["info", "success", "error", "warning"],
133
+ });
134
+
135
+ const isClosable = computed(() =>
136
+ (props.closableVariants as OverlayVariant[]).includes(props.variant),
137
+ );
138
+
139
+ type Feedback = {
140
+ icon: string;
141
+ animation: string;
142
+ surface: string;
143
+ color: string;
144
+ title: string;
145
+ description: string;
146
+ };
147
+
148
+ const neutralText = {
149
+ title: "text-[var(--ads-text-primary)]",
150
+ description: "text-[var(--ads-text-secondary)]",
151
+ };
152
+
153
+ /**
154
+ * Cada estado usa um ícone Lucide em SVG inline (o traço pode ser animado) e as cores de status do ADS.
155
+ * - loading: loader-circle girando.
156
+ * - search: lupa percorrendo um pequeno círculo.
157
+ * - info: info pulsando.
158
+ * - success: traço desenhado e um pulo no fim.
159
+ * - error (status/warning, vermelho): traço desenhado e tremida.
160
+ * - warning (status/attention, amarelo): triângulo desenhado e balanço.
161
+ * Com movimento reduzido no sistema, os ícones aparecem parados.
162
+ */
163
+ const feedbacks: Record<OverlayVariant, Feedback> = {
164
+ loading: {
165
+ icon: "i-lucide-loader-circle",
166
+ animation: "ads-overlay-icon--loading",
167
+ surface: "bg-ads-radar-25",
168
+ color: "text-[var(--ads-text-brand)]",
169
+ ...neutralText,
170
+ },
171
+ search: {
172
+ icon: "i-lucide-search",
173
+ animation: "ads-overlay-icon--search",
174
+ surface: "bg-ads-radar-25",
175
+ color: "text-[var(--ads-text-brand)]",
176
+ ...neutralText,
177
+ },
178
+ info: {
179
+ icon: "i-lucide-info",
180
+ animation: "ads-overlay-icon--info",
181
+ surface: "bg-ads-radar-25",
182
+ color: "text-[var(--ads-text-brand)]",
183
+ ...neutralText,
184
+ },
185
+ success: {
186
+ icon: "i-lucide-circle-check",
187
+ animation: "ads-overlay-icon--draw ads-overlay-icon--success",
188
+ surface: "bg-ads-status-success-100",
189
+ color: "text-ads-status-success-700",
190
+ title: "text-ads-status-success-800",
191
+ description: "text-ads-status-success-700",
192
+ },
193
+ error: {
194
+ icon: "i-lucide-circle-x",
195
+ animation: "ads-overlay-icon--draw ads-overlay-icon--error",
196
+ surface: "bg-ads-status-warning-100",
197
+ color: "text-ads-status-warning-700",
198
+ title: "text-ads-status-warning-800",
199
+ description: "text-ads-status-warning-700",
200
+ },
201
+ warning: {
202
+ icon: "i-lucide-triangle-alert",
203
+ animation: "ads-overlay-icon--draw ads-overlay-icon--warning",
204
+ surface: "bg-ads-status-attention-100",
205
+ color: "text-ads-status-attention-700",
206
+ title: "text-ads-status-attention-800",
207
+ description: "text-ads-status-attention-700",
208
+ },
209
+ };
210
+
211
+ const feedback = computed(() => feedbacks[props.variant] ?? feedbacks.loading);
212
+
213
+ /** Sem actionIcon, só o erro ganha o ícone de tentar de novo. */
214
+ const resolvedActionIcon = computed(() =>
215
+ props.actionIcon ?? (props.variant === "error" ? "i-lucide-refresh-cw" : undefined),
216
+ );
217
+
218
+ const handleClose = () => {
219
+ props.onUserClose?.();
220
+ emit("close");
221
+ };
222
+
223
+ /** Sem onSecondaryAction, a ação secundária fecha o overlay (ex.: "Fechar" ao lado de "Tentar novamente"). */
224
+ const onSecondaryClick = () => {
225
+ if (props.onSecondaryAction) props.onSecondaryAction();
226
+ else handleClose();
227
+ };
228
+ </script>
229
+
230
+ <style>
231
+ .ads-overlay-icon--loading {
232
+ animation: ads-overlay-spin 0.9s linear infinite;
233
+ }
234
+
235
+ .ads-overlay-icon--search {
236
+ animation: ads-overlay-search 1.6s ease-in-out infinite;
237
+ }
238
+
239
+ .ads-overlay-icon--info {
240
+ animation: ads-overlay-pulse 1.6s ease-in-out infinite;
241
+ }
242
+
243
+ .ads-overlay-icon--success {
244
+ animation: ads-overlay-pop 0.45s ease-out 0.75s both;
245
+ }
246
+
247
+ .ads-overlay-icon--error {
248
+ animation: ads-overlay-shake 0.45s ease-in-out 0.75s both;
249
+ }
250
+
251
+ .ads-overlay-icon--warning {
252
+ transform-origin: 50% 85%;
253
+ animation: ads-overlay-swing 0.7s ease-in-out 0.75s both;
254
+ }
255
+
256
+ .ads-overlay-icon--draw :is(path, circle, line, polyline) {
257
+ stroke-dasharray: 80;
258
+ stroke-dashoffset: 80;
259
+ animation: ads-overlay-draw 0.5s ease-out forwards;
260
+ }
261
+
262
+ .ads-overlay-icon--draw :is(path, circle, line, polyline):not(:first-child) {
263
+ animation-delay: 0.35s;
264
+ }
265
+
266
+ @keyframes ads-overlay-spin {
267
+ to { transform: rotate(360deg); }
268
+ }
269
+
270
+ @keyframes ads-overlay-search {
271
+ 0%, 100% { transform: translate(-3px, 0); }
272
+ 25% { transform: translate(0, -3px); }
273
+ 50% { transform: translate(3px, 0); }
274
+ 75% { transform: translate(0, 3px); }
275
+ }
276
+
277
+ @keyframes ads-overlay-pulse {
278
+ 0%, 100% { transform: scale(1); opacity: 1; }
279
+ 50% { transform: scale(1.1); opacity: 0.75; }
280
+ }
281
+
282
+ @keyframes ads-overlay-draw {
283
+ to { stroke-dashoffset: 0; }
284
+ }
285
+
286
+ @keyframes ads-overlay-pop {
287
+ 0% { transform: scale(1); }
288
+ 50% { transform: scale(1.15); }
289
+ 100% { transform: scale(1); }
290
+ }
291
+
292
+ @keyframes ads-overlay-shake {
293
+ 0%, 100% { transform: translateX(0); }
294
+ 20%, 60% { transform: translateX(-3px); }
295
+ 40%, 80% { transform: translateX(3px); }
296
+ }
297
+
298
+ @keyframes ads-overlay-swing {
299
+ 0%, 100% { transform: rotate(0); }
300
+ 20% { transform: rotate(-10deg); }
301
+ 40% { transform: rotate(8deg); }
302
+ 60% { transform: rotate(-5deg); }
303
+ 80% { transform: rotate(3deg); }
304
+ }
305
+
306
+ @media (prefers-reduced-motion: reduce) {
307
+ .ads-overlay-icon,
308
+ .ads-overlay-icon * {
309
+ animation: none !important;
310
+ stroke-dashoffset: 0 !important;
311
+ }
312
+ }
313
+ </style>
@@ -12,27 +12,46 @@ export const useOverlayLoading = () => {
12
12
  close: () => void;
13
13
  patch: (props: Record<string, unknown>) => void;
14
14
  } | null = null;
15
+ /**
16
+ * O overlay é destruído ao fechar (destroyOnClose). Fechar pelo X ou pela ação emite `close`
17
+ * direto no useOverlay, sem passar por aqui; chamar close/patch depois disso lança
18
+ * "Overlay not found". Por isso a referência é limpa quando o overlay fecha, por qualquer caminho.
19
+ */
20
+ const safely = (action: () => void) => {
21
+ try {
22
+ action();
23
+ } catch {
24
+ currentOverlay = null;
25
+ }
26
+ };
27
+
15
28
  const show = (options: OverlayLoadingOptions) => {
16
29
  if (currentOverlay) {
17
- currentOverlay.close();
30
+ const previous = currentOverlay;
31
+ safely(() => previous.close());
18
32
  }
19
- currentOverlay = overlay.create(OverlayLoadingComponent, {
33
+ const created = overlay.create(OverlayLoadingComponent, {
20
34
  destroyOnClose: true,
21
35
  props: {
22
36
  isVisible: true,
23
37
  ...options,
24
38
  },
25
39
  });
40
+ currentOverlay = created;
26
41
 
27
- currentOverlay?.open();
42
+ const opened = created.open();
43
+ void Promise.resolve(opened).then(() => {
44
+ if (currentOverlay?.id === created.id) currentOverlay = null;
45
+ });
28
46
 
29
- return currentOverlay?.id ?? null;
47
+ return created.id;
30
48
  };
31
49
 
32
50
  const close = () => {
33
51
  if (currentOverlay) {
34
- currentOverlay.close();
52
+ const target = currentOverlay;
35
53
  currentOverlay = null;
54
+ safely(() => target.close());
36
55
  }
37
56
  };
38
57
 
@@ -42,10 +61,13 @@ export const useOverlayLoading = () => {
42
61
  */
43
62
  const update = (options: Partial<OverlayLoadingOptions>) => {
44
63
  if (currentOverlay) {
45
- currentOverlay.patch({
46
- isVisible: true,
47
- ...options,
48
- });
64
+ const target = currentOverlay;
65
+ safely(() =>
66
+ target.patch({
67
+ isVisible: true,
68
+ ...options,
69
+ }),
70
+ );
49
71
  }
50
72
  };
51
73
 
@@ -225,7 +225,7 @@ export const adsDropdownMenuUi = {
225
225
  "!min-w-56 !bg-[var(--ads-surface-card)] !shadow-[var(--ads-shadow-level-1)] !ring-0 !rounded-[var(--ads-radius-sm)] border border-[var(--ads-border-subtle)]",
226
226
  viewport: "!divide-y-0",
227
227
  group: "!p-0",
228
- item: "!items-center !gap-2 !rounded-none !p-0 !ps-6 !pe-3 !py-4 !text-sm !font-normal !text-[var(--ads-text-secondary)] border-b border-[#d3d8dd] last:border-b-0 before:!hidden data-highlighted:!bg-neutral-100",
228
+ item: "!items-center !gap-3 !rounded-none !p-[var(--ads-select-item-padding)] !text-sm !font-normal !text-[var(--ads-text-secondary)] border-b border-[var(--ads-select-panel-border)] last:border-b-0 before:!hidden data-highlighted:!bg-[var(--ads-select-item-hover)]",
229
229
  itemLeadingIcon: "!size-4 !text-[var(--ads-text-secondary)]",
230
230
  itemLabel: "!truncate !text-sm !font-normal !text-[var(--ads-text-secondary)]",
231
231
  } as const;