ads-nuxt 0.1.4 → 0.2.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 (90) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +573 -577
  3. package/app/app.config.ts +25 -25
  4. package/app/assets/ads/checkbox-check.svg +5 -5
  5. package/app/assets/ads/checkbox-minus.svg +5 -5
  6. package/app/assets/brand/farmarcas.svg +6 -6
  7. package/app/assets/brand/radar-symbol.svg +9 -0
  8. package/app/assets/brand/radar.svg +9 -9
  9. package/app/assets/css/ads-colors.css +257 -246
  10. package/app/assets/css/component-tokens.css +367 -403
  11. package/app/assets/css/main.css +624 -617
  12. package/app/components/AdsBadge.vue +47 -48
  13. package/app/components/AdsBroadcast.vue +24 -45
  14. package/app/components/AdsButton.vue +539 -569
  15. package/app/components/AdsButtonGroup.vue +39 -39
  16. package/app/components/AdsButtonMenu.vue +48 -48
  17. package/app/components/AdsCard.vue +188 -117
  18. package/app/components/AdsCardHint.vue +22 -0
  19. package/app/components/AdsCardPeriod.vue +43 -0
  20. package/app/components/AdsCardVariation.vue +31 -0
  21. package/app/components/AdsCharttip.vue +78 -78
  22. package/app/components/AdsCheckbox.vue +77 -77
  23. package/app/components/AdsDatePicker.vue +492 -479
  24. package/app/components/AdsDropdownMenu.vue +30 -19
  25. package/app/components/AdsEmptyState.vue +58 -58
  26. package/app/components/AdsFeatureCard.vue +210 -219
  27. package/app/components/AdsFileCard.vue +98 -101
  28. package/app/components/AdsFooter.vue +25 -25
  29. package/app/components/AdsHeavyAccountCell.vue +59 -0
  30. package/app/components/AdsHeavyHeaderCell.vue +70 -0
  31. package/app/components/AdsHeavyTable.vue +135 -0
  32. package/app/components/AdsInput.vue +147 -143
  33. package/app/components/AdsLoading.vue +217 -109
  34. package/app/components/AdsMenuBar.vue +103 -103
  35. package/app/components/AdsMetricCard.vue +216 -119
  36. package/app/components/AdsModal.vue +157 -157
  37. package/app/components/AdsMonthPicker.vue +80 -80
  38. package/app/components/AdsNavbarApp.vue +67 -67
  39. package/app/components/AdsNavbarDesk.vue +62 -62
  40. package/app/components/AdsNotabilityPill.vue +24 -27
  41. package/app/components/AdsNumberInput.vue +173 -166
  42. package/app/components/AdsPagination.vue +91 -91
  43. package/app/components/AdsPanelCard.vue +99 -0
  44. package/app/components/AdsPill.vue +144 -92
  45. package/app/components/AdsProductTag.vue +61 -61
  46. package/app/components/AdsRadio.vue +70 -70
  47. package/app/components/AdsSearchInput.vue +122 -113
  48. package/app/components/AdsSegmentedTabs.vue +62 -28
  49. package/app/components/{AdsFilterSelect.vue → AdsSelect.vue} +266 -203
  50. package/app/components/AdsSelectItem.vue +128 -0
  51. package/app/components/AdsSelectPanel.vue +150 -0
  52. package/app/components/AdsSideMenu.vue +101 -101
  53. package/app/components/AdsSmalltip.vue +44 -44
  54. package/app/components/AdsStepper.vue +222 -0
  55. package/app/components/AdsSteptip.vue +101 -101
  56. package/app/components/AdsSwitch.vue +59 -59
  57. package/app/components/AdsTable.vue +161 -100
  58. package/app/components/AdsTableHeaderCell.vue +80 -0
  59. package/app/components/AdsTableSkeleton.vue +113 -0
  60. package/app/components/AdsTableToolbar.vue +44 -44
  61. package/app/components/AdsTabs.vue +51 -51
  62. package/app/components/AdsTextarea.vue +116 -109
  63. package/app/components/AdsToast.vue +183 -181
  64. package/app/components/AdsTooltip.vue +73 -73
  65. package/app/components/OverlayLoading.vue +173 -173
  66. package/app/components/ProgressBarLoading.vue +235 -256
  67. package/app/composables/useOverlayLoading.ts +66 -66
  68. package/app/constants/ads-color-swatches.ts +240 -239
  69. package/app/locale/pt-br.ts +6 -6
  70. package/app/plugins/ads-toast.client.ts +24 -24
  71. package/app/theme/ads-theme.ts +374 -370
  72. package/app/theme/ads-tokens.ts +391 -379
  73. package/app/theme/component-tokens.json +366 -402
  74. package/app/theme/component-tokens.ts +807 -815
  75. package/app/types/overlay-loading.types.ts +26 -26
  76. package/app/utils/ads-filter-select.ts +191 -172
  77. package/app/utils/ads-table.ts +395 -204
  78. package/app/utils/calendar-date.ts +163 -163
  79. package/app/utils/category-role.ts +45 -45
  80. package/app/utils/money.ts +77 -77
  81. package/app/utils/notability.ts +8 -8
  82. package/app/utils/parser.ts +134 -134
  83. package/app/utils/percentage.ts +54 -54
  84. package/nuxt.config.ts +31 -31
  85. package/package.json +1 -1
  86. package/app/components/AdsFarmarcasPill.vue +0 -74
  87. package/app/components/AdsFilterDropdown.vue +0 -174
  88. package/app/components/AdsFilterOption.vue +0 -74
  89. package/app/components/AdsListDropdown.vue +0 -44
  90. package/app/components/AdsMiniPill.vue +0 -40
@@ -1,256 +1,235 @@
1
- <template>
2
- <div :class="rootClass">
3
- <div v-if="hasHeader" class="flex items-start gap-3">
4
- <span
5
- v-if="showIcon"
6
- class="inline-flex size-10 shrink-0 items-center justify-center rounded-lg border border-primary-200 bg-primary-50"
7
- >
8
- <UIcon
9
- :name="icon"
10
- class="size-6 text-primary"
11
- :class="{ 'animate-spin': spinIcon }"
12
- aria-hidden="true"
13
- />
14
- </span>
15
- <div class="min-w-0 flex-1">
16
- <p v-if="title" class="font-semibold text-highlighted">{{ title }}</p>
17
- <p
18
- v-if="description"
19
- class="text-sm text-muted"
20
- :class="title ? 'mt-0.5' : ''"
21
- >
22
- {{ description }}
23
- </p>
24
- </div>
25
- <span
26
- v-if="reservePercentSlot"
27
- class="shrink-0 text-sm font-medium tabular-nums text-highlighted"
28
- :class="{ invisible: !isPercentVisible }"
29
- :aria-hidden="!isPercentVisible"
30
- >
31
- {{ percentClamped }}%
32
- </span>
33
- </div>
34
-
35
- <div
36
- class="h-[var(--ads-progress-height)] w-full overflow-hidden rounded-[var(--ads-progress-radius)] bg-[var(--ads-progress-track)]"
37
- role="progressbar"
38
- :aria-valuenow="indeterminate ? undefined : percentClamped"
39
- aria-valuemin="0"
40
- aria-valuemax="100"
41
- :aria-busy="indeterminate ? true : undefined"
42
- :aria-label="effectiveAriaLabel"
43
- >
44
- <div
45
- v-if="indeterminate"
46
- class="progress-bar-loading__indeterminate h-full rounded-full"
47
- :class="fillClass"
48
- />
49
- <div
50
- v-else
51
- class="h-full rounded-full transition-[width] duration-300 ease-out"
52
- :class="fillClass"
53
- :style="{ width: `${percentClamped}%` }"
54
- />
55
- </div>
56
-
57
- <div
58
- v-if="reserveElapsedTimeSlot"
59
- class="flex justify-end"
60
- >
61
- <span
62
- class="inline-flex items-center gap-1 font-mono text-xs tabular-nums text-muted"
63
- :class="{ invisible: !showElapsedTime }"
64
- role="timer"
65
- aria-live="off"
66
- :aria-hidden="!showElapsedTime"
67
- :aria-label="`Tempo decorrido: ${elapsedDisplay}`"
68
- >
69
- <UIcon
70
- name="i-lucide-timer"
71
- class="size-3.5 text-muted"
72
- aria-hidden="true"
73
- />
74
- {{ elapsedDisplay }}
75
- </span>
76
- </div>
77
- </div>
78
- </template>
79
-
80
- <script setup lang="ts">
81
- import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
82
-
83
- type ProgressBarLoadingVariant = "primary" | "success" | "error";
84
-
85
- interface Props {
86
- title?: string;
87
- description?: string;
88
- icon?: string;
89
- showIcon?: boolean;
90
- spinIcon?: boolean;
91
- indeterminate?: boolean;
92
- percent?: number;
93
- showPercent?: boolean;
94
- showElapsedTime?: boolean;
95
- ariaLabel?: string;
96
- variant?: ProgressBarLoadingVariant;
97
- rootClass?: string;
98
- }
99
-
100
- const props = withDefaults(defineProps<Props>(), {
101
- title: "",
102
- description: "",
103
- icon: "i-lucide-loader-circle",
104
- showIcon: true,
105
- spinIcon: true,
106
- indeterminate: false,
107
- percent: 0,
108
- showPercent: true,
109
- showElapsedTime: true,
110
- ariaLabel: "",
111
- variant: "primary",
112
- rootClass: "flex flex-col gap-3",
113
- });
114
-
115
- const percentClamped = computed(() =>
116
- Math.max(0, Math.min(100, Math.round(props.percent ?? 0))),
117
- );
118
-
119
- const fillClass = computed(() => {
120
- if (props.variant === "success") return "bg-success-500";
121
- if (props.variant === "error") return "bg-error-500";
122
- return "bg-[var(--ads-progress-fill)]";
123
- });
124
-
125
- const effectiveAriaLabel = computed(
126
- () => props.ariaLabel || props.title || "Carregando",
127
- );
128
-
129
- const isPercentVisible = computed(
130
- () => Boolean(props.showPercent) && !props.indeterminate,
131
- );
132
-
133
- /**
134
- * Slots reservados de forma "sticky-true": uma vez que o slot é necessário (header,
135
- * timer ou percent), mantemos o nó renderizado para sempre. Isso evita que mudanças
136
- * de status (ex.: pipeline `uploading` → `success`, `indeterminate` → determinado,
137
- * `showElapsedTime` true → false) movam outros elementos no eixo Y.
138
- *
139
- * A alternância visual é feita apenas via `invisible` (mantém o espaço reservado).
140
- */
141
- const computedHasHeader = () =>
142
- Boolean(props.showIcon) ||
143
- Boolean(props.title) ||
144
- Boolean(props.description) ||
145
- (!props.indeterminate && Boolean(props.showPercent));
146
-
147
- const hasHeader = ref(computedHasHeader());
148
- const reserveElapsedTimeSlot = ref(Boolean(props.showElapsedTime));
149
- const reservePercentSlot = ref(Boolean(props.showPercent));
150
-
151
- watch(computedHasHeader, (val) => {
152
- if (val) hasHeader.value = true;
153
- });
154
-
155
- watch(
156
- () => Boolean(props.showElapsedTime),
157
- (val) => {
158
- if (val) reserveElapsedTimeSlot.value = true;
159
- },
160
- );
161
-
162
- watch(
163
- () => Boolean(props.showPercent),
164
- (val) => {
165
- if (val) reservePercentSlot.value = true;
166
- },
167
- );
168
-
169
- const startedAt = ref<number>(0);
170
- const now = ref<number>(0);
171
- let elapsedTimerId: ReturnType<typeof setInterval> | null = null;
172
-
173
- const stopElapsedTimer = () => {
174
- if (elapsedTimerId != null) {
175
- clearInterval(elapsedTimerId);
176
- elapsedTimerId = null;
177
- }
178
- };
179
-
180
- const startElapsedTimer = () => {
181
- stopElapsedTimer();
182
- startedAt.value = Date.now();
183
- now.value = startedAt.value;
184
- if (typeof window === "undefined") {
185
- return;
186
- }
187
- elapsedTimerId = setInterval(() => {
188
- now.value = Date.now();
189
- }, 1000);
190
- };
191
-
192
- const elapsedSeconds = computed(() =>
193
- Math.max(0, Math.floor((now.value - startedAt.value) / 1000)),
194
- );
195
-
196
- const elapsedDisplay = computed(() => {
197
- const total = elapsedSeconds.value;
198
- const hours = Math.floor(total / 3600);
199
- const minutes = Math.floor((total % 3600) / 60);
200
- const seconds = total % 60;
201
- const pad = (n: number) => String(n).padStart(2, "0");
202
- if (hours > 0) {
203
- return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
204
- }
205
- return `${pad(minutes)}:${pad(seconds)}`;
206
- });
207
-
208
- watch(
209
- () => props.showElapsedTime,
210
- (enabled) => {
211
- if (enabled) {
212
- startElapsedTimer();
213
- } else {
214
- stopElapsedTimer();
215
- }
216
- },
217
- );
218
-
219
- onMounted(() => {
220
- if (props.showElapsedTime) {
221
- startElapsedTimer();
222
- }
223
- });
224
-
225
- onBeforeUnmount(() => {
226
- stopElapsedTimer();
227
- });
228
- </script>
229
-
230
- <style scoped>
231
- .progress-bar-loading__indeterminate {
232
- width: 35%;
233
- animation: progress-bar-loading-indeterminate 1.4s ease-in-out infinite;
234
- transform-origin: left;
235
- }
236
-
237
- @keyframes progress-bar-loading-indeterminate {
238
- 0% {
239
- margin-inline-start: -35%;
240
- }
241
- 60% {
242
- margin-inline-start: 100%;
243
- }
244
- 100% {
245
- margin-inline-start: 100%;
246
- }
247
- }
248
-
249
- @media (prefers-reduced-motion: reduce) {
250
- .progress-bar-loading__indeterminate {
251
- width: 100%;
252
- animation: none;
253
- opacity: 0.6;
254
- }
255
- }
256
- </style>
1
+ <template>
2
+ <div :class="rootClass">
3
+ <div v-if="hasHeader" class="flex items-start gap-2">
4
+ <UIcon
5
+ v-if="showIcon"
6
+ :name="resolvedIcon"
7
+ class="mt-px size-[18px] shrink-0"
8
+ :class="[
9
+ isSuccess ? 'text-[var(--ads-progress-success)]' : 'text-[var(--ads-progress-fill)]',
10
+ { 'animate-spin motion-reduce:animate-none': spinIcon && !isSuccess },
11
+ ]"
12
+ aria-hidden="true"
13
+ />
14
+ <div class="flex min-w-0 flex-1 flex-col gap-0.5 text-sm leading-[1.3]">
15
+ <p v-if="title" class="font-bold text-[var(--ads-text-primary)]">{{ title }}</p>
16
+ <p v-if="description" class="text-[var(--ads-text-secondary)]">{{ description }}</p>
17
+ </div>
18
+ <span
19
+ v-if="reservePercentSlot"
20
+ class="shrink-0 text-sm leading-[1.3] font-medium tabular-nums text-[var(--ads-text-primary)]"
21
+ :class="{ invisible: !showPercent }"
22
+ :aria-hidden="!showPercent"
23
+ >
24
+ {{ indeterminate ? "—" : `${percentClamped}%` }}
25
+ </span>
26
+ </div>
27
+
28
+ <div
29
+ class="relative h-[var(--ads-progress-height)] w-full overflow-hidden rounded-[var(--ads-progress-radius)] bg-[var(--ads-progress-track)]"
30
+ role="progressbar"
31
+ :aria-valuenow="indeterminate ? undefined : percentClamped"
32
+ aria-valuemin="0"
33
+ aria-valuemax="100"
34
+ :aria-busy="indeterminate ? true : undefined"
35
+ :aria-label="effectiveAriaLabel"
36
+ >
37
+ <div
38
+ v-if="indeterminate"
39
+ class="progress-bar-loading__indeterminate absolute inset-y-0 rounded-[var(--ads-progress-radius)]"
40
+ :class="fillClass"
41
+ />
42
+ <div
43
+ v-else
44
+ class="h-full rounded-[var(--ads-progress-radius)] transition-[width] duration-300 ease-out"
45
+ :class="fillClass"
46
+ :style="{ width: `${percentClamped}%` }"
47
+ />
48
+ </div>
49
+
50
+ <p
51
+ v-if="reserveElapsedTimeSlot"
52
+ class="text-xs leading-[1.2] tabular-nums text-[var(--ads-text-secondary)]"
53
+ :class="{ invisible: !showElapsedTime }"
54
+ role="timer"
55
+ aria-live="off"
56
+ :aria-hidden="!showElapsedTime"
57
+ >
58
+ Tempo decorrido: {{ elapsedDisplay }}
59
+ </p>
60
+ </div>
61
+ </template>
62
+
63
+ <script setup lang="ts">
64
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
65
+
66
+ type ProgressBarLoadingVariant = "primary" | "success";
67
+
68
+ interface Props {
69
+ title?: string;
70
+ description?: string;
71
+ /** Ícone do andamento. No sucesso vira o check verde. */
72
+ icon?: string;
73
+ showIcon?: boolean;
74
+ spinIcon?: boolean;
75
+ /** Sem percentual conhecido: mostra "—" e um trecho da barra que atravessa a trilha. */
76
+ indeterminate?: boolean;
77
+ percent?: number;
78
+ showPercent?: boolean;
79
+ /** "Tempo decorrido: 00:42", abaixo da barra. */
80
+ showElapsedTime?: boolean;
81
+ ariaLabel?: string;
82
+ variant?: ProgressBarLoadingVariant;
83
+ rootClass?: string;
84
+ }
85
+
86
+ const props = withDefaults(defineProps<Props>(), {
87
+ title: "",
88
+ description: "",
89
+ icon: "i-lucide-loader-circle",
90
+ showIcon: true,
91
+ spinIcon: true,
92
+ indeterminate: false,
93
+ percent: 0,
94
+ showPercent: true,
95
+ showElapsedTime: true,
96
+ ariaLabel: "",
97
+ variant: "primary",
98
+ rootClass: "flex w-full flex-col gap-3",
99
+ });
100
+
101
+ const percentClamped = computed(() =>
102
+ Math.max(0, Math.min(100, Math.round(props.percent ?? 0))),
103
+ );
104
+
105
+ const isSuccess = computed(() => props.variant === "success");
106
+
107
+ /** Em andamento: ícone de carregamento azul. Sucesso: check verde, como no Figma. */
108
+ const resolvedIcon = computed(() => (isSuccess.value ? "i-lucide-circle-check" : props.icon));
109
+
110
+ const fillClass = computed(() =>
111
+ isSuccess.value ? "bg-[var(--ads-progress-success)]" : "bg-[var(--ads-progress-fill)]",
112
+ );
113
+
114
+ const effectiveAriaLabel = computed(
115
+ () => props.ariaLabel || props.title || "Carregando",
116
+ );
117
+
118
+ /**
119
+ * Slots reservados de forma "sticky-true": uma vez necessário (cabeçalho, tempo ou
120
+ * percentual), o nó fica renderizado. Assim a troca de estado não move nada no eixo Y;
121
+ * a alternância visual usa só `invisible`.
122
+ */
123
+ const computedHasHeader = () =>
124
+ Boolean(props.showIcon) ||
125
+ Boolean(props.title) ||
126
+ Boolean(props.description) ||
127
+ Boolean(props.showPercent);
128
+
129
+ const hasHeader = ref(computedHasHeader());
130
+ const reserveElapsedTimeSlot = ref(Boolean(props.showElapsedTime));
131
+ const reservePercentSlot = ref(Boolean(props.showPercent));
132
+
133
+ watch(computedHasHeader, (val) => {
134
+ if (val) hasHeader.value = true;
135
+ });
136
+
137
+ watch(
138
+ () => Boolean(props.showElapsedTime),
139
+ (val) => {
140
+ if (val) reserveElapsedTimeSlot.value = true;
141
+ },
142
+ );
143
+
144
+ watch(
145
+ () => Boolean(props.showPercent),
146
+ (val) => {
147
+ if (val) reservePercentSlot.value = true;
148
+ },
149
+ );
150
+
151
+ const startedAt = ref<number>(0);
152
+ const now = ref<number>(0);
153
+ let elapsedTimerId: ReturnType<typeof setInterval> | null = null;
154
+
155
+ const stopElapsedTimer = () => {
156
+ if (elapsedTimerId != null) {
157
+ clearInterval(elapsedTimerId);
158
+ elapsedTimerId = null;
159
+ }
160
+ };
161
+
162
+ const startElapsedTimer = () => {
163
+ stopElapsedTimer();
164
+ startedAt.value = Date.now();
165
+ now.value = startedAt.value;
166
+ if (typeof window === "undefined") {
167
+ return;
168
+ }
169
+ elapsedTimerId = setInterval(() => {
170
+ now.value = Date.now();
171
+ }, 1000);
172
+ };
173
+
174
+ const elapsedSeconds = computed(() =>
175
+ Math.max(0, Math.floor((now.value - startedAt.value) / 1000)),
176
+ );
177
+
178
+ const elapsedDisplay = computed(() => {
179
+ const total = elapsedSeconds.value;
180
+ const hours = Math.floor(total / 3600);
181
+ const minutes = Math.floor((total % 3600) / 60);
182
+ const seconds = total % 60;
183
+ const pad = (n: number) => String(n).padStart(2, "0");
184
+ if (hours > 0) {
185
+ return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
186
+ }
187
+ return `${pad(minutes)}:${pad(seconds)}`;
188
+ });
189
+
190
+ watch(
191
+ () => props.showElapsedTime,
192
+ (enabled) => {
193
+ if (enabled) {
194
+ startElapsedTimer();
195
+ } else {
196
+ stopElapsedTimer();
197
+ }
198
+ },
199
+ );
200
+
201
+ onMounted(() => {
202
+ if (props.showElapsedTime) {
203
+ startElapsedTimer();
204
+ }
205
+ });
206
+
207
+ onBeforeUnmount(() => {
208
+ stopElapsedTimer();
209
+ });
210
+ </script>
211
+
212
+ <style scoped>
213
+ /* Indeterminado: trecho de 30% da trilha (no Figma, parado no meio) que atravessa a barra. */
214
+ .progress-bar-loading__indeterminate {
215
+ width: 30%;
216
+ animation: progress-bar-loading-indeterminate 1.4s ease-in-out infinite;
217
+ }
218
+
219
+ @keyframes progress-bar-loading-indeterminate {
220
+ 0% {
221
+ left: -30%;
222
+ }
223
+
224
+ 100% {
225
+ left: 100%;
226
+ }
227
+ }
228
+
229
+ @media (prefers-reduced-motion: reduce) {
230
+ .progress-bar-loading__indeterminate {
231
+ left: 35%;
232
+ animation: none;
233
+ }
234
+ }
235
+ </style>
@@ -1,66 +1,66 @@
1
- import type { OverlayLoadingOptions } from "../types/overlay-loading.types";
2
-
3
- export const useOverlayLoading = () => {
4
- const overlay = useOverlay();
5
- const OverlayLoadingComponent = defineAsyncComponent(
6
- () => import("../components/OverlayLoading.vue")
7
- );
8
-
9
- let currentOverlay: {
10
- id: symbol;
11
- open: () => void;
12
- close: () => void;
13
- patch: (props: Record<string, unknown>) => void;
14
- } | null = null;
15
- const show = (options: OverlayLoadingOptions) => {
16
- if (currentOverlay) {
17
- currentOverlay.close();
18
- }
19
- currentOverlay = overlay.create(OverlayLoadingComponent, {
20
- destroyOnClose: true,
21
- props: {
22
- isVisible: true,
23
- ...options,
24
- },
25
- });
26
-
27
- currentOverlay?.open();
28
-
29
- return currentOverlay?.id ?? null;
30
- };
31
-
32
- const close = () => {
33
- if (currentOverlay) {
34
- currentOverlay.close();
35
- currentOverlay = null;
36
- }
37
- };
38
-
39
- /**
40
- * Mescla props no componente do overlay. Props devem ser planas (title, description, …):
41
- * o `patch` do useOverlay faz `{ ...overlay.props, ...patch }`, não aceita `{ props: { … } }`.
42
- */
43
- const update = (options: Partial<OverlayLoadingOptions>) => {
44
- if (currentOverlay) {
45
- currentOverlay.patch({
46
- isVisible: true,
47
- ...options,
48
- });
49
- }
50
- };
51
-
52
- const isOpen = () => {
53
- return currentOverlay !== null;
54
- };
55
-
56
- const getCurrentId = () => currentOverlay?.id ?? null;
57
-
58
- return {
59
- show,
60
- close,
61
- update,
62
- isOpen,
63
- getCurrentId,
64
- };
65
- };
66
-
1
+ import type { OverlayLoadingOptions } from "../types/overlay-loading.types";
2
+
3
+ export const useOverlayLoading = () => {
4
+ const overlay = useOverlay();
5
+ const OverlayLoadingComponent = defineAsyncComponent(
6
+ () => import("../components/OverlayLoading.vue")
7
+ );
8
+
9
+ let currentOverlay: {
10
+ id: symbol;
11
+ open: () => void;
12
+ close: () => void;
13
+ patch: (props: Record<string, unknown>) => void;
14
+ } | null = null;
15
+ const show = (options: OverlayLoadingOptions) => {
16
+ if (currentOverlay) {
17
+ currentOverlay.close();
18
+ }
19
+ currentOverlay = overlay.create(OverlayLoadingComponent, {
20
+ destroyOnClose: true,
21
+ props: {
22
+ isVisible: true,
23
+ ...options,
24
+ },
25
+ });
26
+
27
+ currentOverlay?.open();
28
+
29
+ return currentOverlay?.id ?? null;
30
+ };
31
+
32
+ const close = () => {
33
+ if (currentOverlay) {
34
+ currentOverlay.close();
35
+ currentOverlay = null;
36
+ }
37
+ };
38
+
39
+ /**
40
+ * Mescla props no componente do overlay. Props devem ser planas (title, description, …):
41
+ * o `patch` do useOverlay faz `{ ...overlay.props, ...patch }`, não aceita `{ props: { … } }`.
42
+ */
43
+ const update = (options: Partial<OverlayLoadingOptions>) => {
44
+ if (currentOverlay) {
45
+ currentOverlay.patch({
46
+ isVisible: true,
47
+ ...options,
48
+ });
49
+ }
50
+ };
51
+
52
+ const isOpen = () => {
53
+ return currentOverlay !== null;
54
+ };
55
+
56
+ const getCurrentId = () => currentOverlay?.id ?? null;
57
+
58
+ return {
59
+ show,
60
+ close,
61
+ update,
62
+ isOpen,
63
+ getCurrentId,
64
+ };
65
+ };
66
+