ads-nuxt 0.4.1 → 0.4.2

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 (76) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +574 -574
  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 -9
  8. package/app/assets/brand/radar.svg +9 -9
  9. package/app/assets/css/ads-colors.css +257 -257
  10. package/app/assets/css/main.css +585 -585
  11. package/app/components/AdsBadge.vue +47 -47
  12. package/app/components/AdsBroadcast.vue +24 -24
  13. package/app/components/AdsButton.vue +547 -547
  14. package/app/components/AdsButtonGroup.vue +39 -39
  15. package/app/components/AdsButtonMenu.vue +48 -48
  16. package/app/components/AdsCard.vue +188 -188
  17. package/app/components/AdsCardHint.vue +56 -56
  18. package/app/components/AdsCardPeriod.vue +43 -43
  19. package/app/components/AdsCardVariation.vue +31 -31
  20. package/app/components/AdsCharttip.vue +79 -79
  21. package/app/components/AdsDatePicker.vue +509 -509
  22. package/app/components/AdsDropdownMenu.vue +30 -30
  23. package/app/components/AdsEmptyState.vue +61 -61
  24. package/app/components/AdsFeatureCard.vue +292 -292
  25. package/app/components/AdsFileCard.vue +98 -98
  26. package/app/components/AdsFooter.vue +25 -25
  27. package/app/components/AdsHeavyAccountCell.vue +59 -59
  28. package/app/components/AdsHeavyHeaderCell.vue +70 -70
  29. package/app/components/AdsHeavyTable.vue +135 -135
  30. package/app/components/AdsInput.vue +148 -148
  31. package/app/components/AdsLoading.vue +217 -217
  32. package/app/components/AdsMenuBar.vue +110 -110
  33. package/app/components/AdsMetricCard.vue +226 -226
  34. package/app/components/AdsModal.vue +160 -160
  35. package/app/components/AdsMonthPicker.vue +80 -80
  36. package/app/components/AdsNavbarApp.vue +67 -67
  37. package/app/components/AdsNavbarDesk.vue +67 -67
  38. package/app/components/AdsNotabilityPill.vue +24 -24
  39. package/app/components/AdsNumberInput.vue +173 -173
  40. package/app/components/AdsPanelCard.vue +99 -99
  41. package/app/components/AdsPill.vue +144 -144
  42. package/app/components/AdsProductTag.vue +80 -80
  43. package/app/components/AdsSearchInput.vue +122 -122
  44. package/app/components/AdsSegmentedTabs.vue +62 -62
  45. package/app/components/AdsSelect.vue +283 -283
  46. package/app/components/AdsSelectItem.vue +128 -128
  47. package/app/components/AdsSelectPanel.vue +221 -221
  48. package/app/components/AdsSideMenu.vue +101 -101
  49. package/app/components/AdsSmalltip.vue +44 -44
  50. package/app/components/AdsStepper.vue +222 -222
  51. package/app/components/AdsTable.vue +172 -172
  52. package/app/components/AdsTableHeaderCell.vue +80 -80
  53. package/app/components/AdsTableSkeleton.vue +113 -113
  54. package/app/components/AdsTableToolbar.vue +44 -44
  55. package/app/components/AdsTabs.vue +51 -51
  56. package/app/components/AdsTextarea.vue +116 -116
  57. package/app/components/AdsToast.vue +184 -184
  58. package/app/components/AdsTooltip.vue +73 -73
  59. package/app/components/ProgressBarLoading.vue +235 -235
  60. package/app/composables/useOverlayLoading.ts +88 -88
  61. package/app/constants/ads-color-swatches.ts +240 -240
  62. package/app/locale/pt-br.ts +6 -6
  63. package/app/plugins/ads-toast.client.ts +24 -24
  64. package/app/theme/ads-theme.ts +374 -374
  65. package/app/theme/ads-tokens.ts +391 -391
  66. package/app/types/overlay-loading.types.ts +32 -32
  67. package/app/utils/ads-filter-select.ts +191 -191
  68. package/app/utils/ads-table.ts +416 -416
  69. package/app/utils/calendar-date.ts +163 -163
  70. package/app/utils/category-role.ts +45 -45
  71. package/app/utils/money.ts +77 -77
  72. package/app/utils/notability.ts +8 -8
  73. package/app/utils/parser.ts +134 -134
  74. package/app/utils/percentage.ts +54 -54
  75. package/nuxt.config.ts +31 -31
  76. package/package.json +57 -57
@@ -1,67 +1,67 @@
1
- <template>
2
- <header class="flex h-[var(--ads-navbar-desk-height)] w-full items-center justify-between border-b border-[var(--ads-navbar-desk-border)] bg-[var(--ads-surface-card)] pl-[var(--ads-navbar-desk-padding-x)] pr-[var(--ads-navbar-desk-padding-end)] shadow-[0_2px_4px_-1px_color-mix(in_srgb,var(--color-ads-neutro-medio-60)_75%,transparent)]">
3
- <div class="flex items-center gap-3">
4
- <img :src="radarUrl" alt="RADAR" class="h-[21px] w-auto" />
5
- <AdsProductTag v-if="product" :product="product" :label="productLabel" />
6
- </div>
7
- <div class="flex items-center gap-4">
8
- <AdsPill v-if="showBroadcast && broadcastLabel" variant="broadcast" status="warning" :label="broadcastLabel" />
9
- <div class="flex items-center gap-3">
10
- <template v-for="(action, index) in actions" :key="action.id">
11
- <span v-if="index === actions.length - 1" class="flex size-[var(--ads-navbar-desk-avatar)] items-center justify-center overflow-hidden rounded-full bg-ads-neutro-claro-30" aria-hidden="true">
12
- <img v-if="avatarUrl" :src="avatarUrl" alt="" class="size-full object-cover" />
13
- <UIcon v-else name="i-lucide-user" class="size-4 text-[var(--ads-text-secondary)]" />
14
- </span>
15
- <button
16
- type="button"
17
- class="flex size-[var(--ads-navbar-desk-action)] items-center justify-center rounded-[var(--ads-radius-xsm)] p-2 text-[var(--ads-text-secondary)] hover:bg-ads-neutro-claro-20 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ads-text-brand)]"
18
- :aria-label="action.label"
19
- @click="emit('action', action.id)"
20
- >
21
- <UIcon :name="action.icon" class="size-[18px]" />
22
- </button>
23
- </template>
24
- </div>
25
- </div>
26
- </header>
27
- </template>
28
-
29
- <script setup lang="ts">
30
- import radarUrl from "../assets/brand/radar.svg?url";
31
- import AdsPill from "./AdsPill.vue";
32
- import AdsProductTag, { type AdsProductTagName } from "./AdsProductTag.vue";
33
-
34
- export type AdsNavbarDeskAction = {
35
- id: string;
36
- label: string;
37
- icon: string;
38
- };
39
-
40
- withDefaults(
41
- defineProps<{
42
- product?: AdsProductTagName | null;
43
- productLabel?: string;
44
- showBroadcast?: boolean;
45
- /** Texto da pílula de broadcast (ex.: "LIVE"). Sem valor, a pílula não aparece. */
46
- broadcastLabel?: string;
47
- avatarUrl?: string;
48
- actions?: AdsNavbarDeskAction[];
49
- }>(),
50
- {
51
- product: "performance",
52
- productLabel: "performance",
53
- showBroadcast: true,
54
- broadcastLabel: "",
55
- avatarUrl: "",
56
- actions: () => [
57
- { id: "alerts", label: "Alertas", icon: "i-lucide-bell" },
58
- { id: "settings", label: "Configurações", icon: "i-lucide-settings" },
59
- { id: "apps", label: "Aplicativos", icon: "i-lucide-layout-grid" },
60
- ],
61
- },
62
- );
63
-
64
- const emit = defineEmits<{
65
- action: [id: string];
66
- }>();
67
- </script>
1
+ <template>
2
+ <header class="flex h-[var(--ads-navbar-desk-height)] w-full items-center justify-between border-b border-[var(--ads-navbar-desk-border)] bg-[var(--ads-surface-card)] pl-[var(--ads-navbar-desk-padding-x)] pr-[var(--ads-navbar-desk-padding-end)] shadow-[0_2px_4px_-1px_color-mix(in_srgb,var(--color-ads-neutro-medio-60)_75%,transparent)]">
3
+ <div class="flex items-center gap-3">
4
+ <img :src="radarUrl" alt="RADAR" class="h-[21px] w-auto" />
5
+ <AdsProductTag v-if="product" :product="product" :label="productLabel" />
6
+ </div>
7
+ <div class="flex items-center gap-4">
8
+ <AdsPill v-if="showBroadcast && broadcastLabel" variant="broadcast" status="warning" :label="broadcastLabel" />
9
+ <div class="flex items-center gap-3">
10
+ <template v-for="(action, index) in actions" :key="action.id">
11
+ <span v-if="index === actions.length - 1" class="flex size-[var(--ads-navbar-desk-avatar)] items-center justify-center overflow-hidden rounded-full bg-ads-neutro-claro-30" aria-hidden="true">
12
+ <img v-if="avatarUrl" :src="avatarUrl" alt="" class="size-full object-cover" />
13
+ <UIcon v-else name="i-lucide-user" class="size-4 text-[var(--ads-text-secondary)]" />
14
+ </span>
15
+ <button
16
+ type="button"
17
+ class="flex size-[var(--ads-navbar-desk-action)] items-center justify-center rounded-[var(--ads-radius-xsm)] p-2 text-[var(--ads-text-secondary)] hover:bg-ads-neutro-claro-20 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ads-text-brand)]"
18
+ :aria-label="action.label"
19
+ @click="emit('action', action.id)"
20
+ >
21
+ <UIcon :name="action.icon" class="size-[18px]" />
22
+ </button>
23
+ </template>
24
+ </div>
25
+ </div>
26
+ </header>
27
+ </template>
28
+
29
+ <script setup lang="ts">
30
+ import radarUrl from "../assets/brand/radar.svg?url";
31
+ import AdsPill from "./AdsPill.vue";
32
+ import AdsProductTag, { type AdsProductTagName } from "./AdsProductTag.vue";
33
+
34
+ export type AdsNavbarDeskAction = {
35
+ id: string;
36
+ label: string;
37
+ icon: string;
38
+ };
39
+
40
+ withDefaults(
41
+ defineProps<{
42
+ product?: AdsProductTagName | null;
43
+ productLabel?: string;
44
+ showBroadcast?: boolean;
45
+ /** Texto da pílula de broadcast (ex.: "LIVE"). Sem valor, a pílula não aparece. */
46
+ broadcastLabel?: string;
47
+ avatarUrl?: string;
48
+ actions?: AdsNavbarDeskAction[];
49
+ }>(),
50
+ {
51
+ product: "performance",
52
+ productLabel: "performance",
53
+ showBroadcast: true,
54
+ broadcastLabel: "",
55
+ avatarUrl: "",
56
+ actions: () => [
57
+ { id: "alerts", label: "Alertas", icon: "i-lucide-bell" },
58
+ { id: "settings", label: "Configurações", icon: "i-lucide-settings" },
59
+ { id: "apps", label: "Aplicativos", icon: "i-lucide-layout-grid" },
60
+ ],
61
+ },
62
+ );
63
+
64
+ const emit = defineEmits<{
65
+ action: [id: string];
66
+ }>();
67
+ </script>
@@ -1,24 +1,24 @@
1
- <template>
2
- <AdsPill :label="resolvedLabel" :custom-surface="surface" />
3
- </template>
4
-
5
- <script setup lang="ts">
6
- import { computed } from "vue";
7
- import { formatNotability } from "../utils/notability";
8
- import AdsPill from "./AdsPill.vue";
9
-
10
- const props = defineProps<{
11
- notability: string;
12
- label?: string;
13
- }>();
14
-
15
- /** image → cyan (new), traffic → verde (success), profit → IA (surface-ai / text-ai). */
16
- const surface = computed(() => {
17
- if (props.notability === "traffic") return "bg-[var(--ads-status-success-100)] text-[var(--ads-status-success-800)]";
18
- if (props.notability === "profit") return "bg-[var(--ads-surface-ai)] text-[var(--ads-text-ai)]";
19
- // image (default)
20
- return "bg-[var(--ads-status-new-100)] text-[var(--ads-status-new-800)]";
21
- });
22
-
23
- const resolvedLabel = computed(() => props.label ?? formatNotability(props.notability));
24
- </script>
1
+ <template>
2
+ <AdsPill :label="resolvedLabel" :custom-surface="surface" />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { computed } from "vue";
7
+ import { formatNotability } from "../utils/notability";
8
+ import AdsPill from "./AdsPill.vue";
9
+
10
+ const props = defineProps<{
11
+ notability: string;
12
+ label?: string;
13
+ }>();
14
+
15
+ /** image → cyan (new), traffic → verde (success), profit → IA (surface-ai / text-ai). */
16
+ const surface = computed(() => {
17
+ if (props.notability === "traffic") return "bg-[var(--ads-status-success-100)] text-[var(--ads-status-success-800)]";
18
+ if (props.notability === "profit") return "bg-[var(--ads-surface-ai)] text-[var(--ads-text-ai)]";
19
+ // image (default)
20
+ return "bg-[var(--ads-status-new-100)] text-[var(--ads-status-new-800)]";
21
+ });
22
+
23
+ const resolvedLabel = computed(() => props.label ?? formatNotability(props.notability));
24
+ </script>
@@ -1,173 +1,173 @@
1
- <template>
2
- <div class="flex min-w-0 flex-col gap-0.5">
3
- <div
4
- v-if="label || info"
5
- class="flex items-center gap-0.5 text-[length:var(--ads-number-label-size)] leading-[1.2]"
6
- :class="supportClass"
7
- >
8
- <label v-if="label" :for="fieldId">{{ label }}</label>
9
- <AdsTooltip v-if="info" :description="info" :show-title="false">
10
- <span class="inline-flex">
11
- <UIcon name="i-lucide-info" class="size-3 text-xs" />
12
- </span>
13
- </AdsTooltip>
14
- </div>
15
-
16
- <div
17
- class="flex h-[var(--ads-number-height)] w-full transition-colors min-w-0 items-center gap-[var(--ads-number-gap)] rounded-[var(--ads-number-radius)] px-[var(--ads-number-padding-x)]"
18
- :class="fieldClass"
19
- :data-state="visualState"
20
- >
21
- <input
22
- :id="fieldId"
23
- ref="inputEl"
24
- :value="displayValue"
25
- type="number"
26
- inputmode="decimal"
27
- size="4"
28
- class="w-0 min-w-0 flex-1 bg-transparent text-[length:var(--ads-number-font-size)] leading-[1.3] text-[var(--ads-text-primary)] outline-none placeholder:text-[var(--ads-number-text)] disabled:cursor-not-allowed disabled:text-[var(--ads-number-disabled-text)] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
29
- :placeholder="placeholder"
30
- :disabled="isDisabled"
31
- :min="min"
32
- :step="step"
33
- :aria-invalid="error ? true : undefined"
34
- :aria-describedby="supportText ? supportId : undefined"
35
- @input="onInput"
36
- @focus="emit('focus', $event)"
37
- @blur="emit('blur', $event)"
38
- >
39
- <span v-if="suffix" class="shrink-0 text-[length:var(--ads-number-font-size)] leading-[1.3]">{{ suffix }}</span>
40
- <div class="flex shrink-0 flex-col">
41
- <button
42
- type="button"
43
- class="inline-flex h-3 w-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
44
- aria-label="Aumentar valor"
45
- :disabled="isDisabled"
46
- @mousedown.prevent="stepBy(1)"
47
- >
48
- <UIcon name="i-lucide-chevron-up" class="size-3" />
49
- </button>
50
- <button
51
- type="button"
52
- class="inline-flex h-3 w-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
53
- aria-label="Diminuir valor"
54
- :disabled="isDisabled"
55
- @mousedown.prevent="stepBy(-1)"
56
- >
57
- <UIcon name="i-lucide-chevron-down" class="size-3" />
58
- </button>
59
- </div>
60
- </div>
61
-
62
- <p
63
- v-if="supportText"
64
- :id="supportId"
65
- class="text-xs leading-[1.2]"
66
- :class="supportClass"
67
- >
68
- {{ supportText }}
69
- </p>
70
- </div>
71
- </template>
72
-
73
- <script setup lang="ts">
74
- import { computed, useId, useTemplateRef } from "vue";
75
- import AdsTooltip from "./AdsTooltip.vue";
76
-
77
- export type AdsNumberInputState = "default" | "active" | "focus" | "error" | "disabled" | "ai";
78
-
79
- const props = withDefaults(
80
- defineProps<{
81
- label?: string;
82
- hint?: string;
83
- info?: string;
84
- error?: string;
85
- placeholder?: string;
86
- suffix?: string;
87
- disabled?: boolean;
88
- min?: string | number;
89
- step?: string | number;
90
- /** Estado congelado para a documentação. `null` segue o campo. */
91
- state?: AdsNumberInputState | null;
92
- /** O valor veio de uma sugestão de IA. Quem usa limpa a marca quando a pessoa edita. */
93
- aiSuggestion?: boolean;
94
- }>(),
95
- {
96
- label: "",
97
- hint: "",
98
- info: "",
99
- error: "",
100
- placeholder: "",
101
- suffix: "",
102
- disabled: false,
103
- state: null,
104
- aiSuggestion: false,
105
- },
106
- );
107
-
108
- const model = defineModel<string | number>({ default: "" });
109
-
110
- const emit = defineEmits<{
111
- focus: [event: FocusEvent];
112
- blur: [event: FocusEvent];
113
- }>();
114
-
115
- const fieldId = useId();
116
- const supportId = useId();
117
- const inputEl = useTemplateRef<HTMLInputElement>("inputEl");
118
-
119
- const displayValue = computed(() =>
120
- model.value === undefined || model.value === null ? "" : String(model.value),
121
- );
122
-
123
- const onInput = (event: Event) => {
124
- model.value = (event.target as HTMLInputElement).value;
125
- };
126
-
127
- const isDisabled = computed(() => props.disabled || props.state === "disabled");
128
-
129
- const stepBy = (direction: 1 | -1) => {
130
- const input = inputEl.value;
131
- if (!input || isDisabled.value) return;
132
- if (input.value === "") input.value = String(props.min ?? 0);
133
- if (direction > 0) input.stepUp();
134
- else input.stepDown();
135
- model.value = input.value;
136
- };
137
-
138
- const visualState = computed<AdsNumberInputState>(() => {
139
- if (isDisabled.value) return "disabled";
140
- if (props.state) return props.state;
141
- if (props.error) return "error";
142
- if (props.aiSuggestion) return "ai";
143
- return displayValue.value ? "active" : "default";
144
- });
145
-
146
- const supportText = computed(() => props.error || props.hint);
147
- const supportClass = computed(() =>
148
- visualState.value === "disabled"
149
- ? "text-[var(--ads-number-disabled-text)]"
150
- : "text-[var(--ads-text-secondary)]",
151
- );
152
-
153
- const fieldClass = computed(() => {
154
- const interactiveFocus = props.state === null && !isDisabled.value && !props.error;
155
- const focus = interactiveFocus
156
- ? "hover:not-focus-within:border-[var(--ads-number-hover-border)] focus-within:border-(length:--ads-border-width-slim) focus-within:border-[var(--ads-number-focus-border)]"
157
- : "";
158
-
159
- if (visualState.value === "disabled") {
160
- return "border border-[var(--ads-number-disabled-border)] bg-[var(--ads-number-disabled-background)] text-[var(--ads-number-disabled-text)]";
161
- }
162
- if (visualState.value === "error") {
163
- return `border-(length:--ads-border-width-slim) border-[var(--ads-number-error-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
164
- }
165
- if (visualState.value === "focus") {
166
- return "border-(length:--ads-border-width-slim) border-[var(--ads-number-focus-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)]";
167
- }
168
- if (visualState.value === "ai") {
169
- return `border border-[var(--ads-text-ai)] bg-[var(--ads-surface-ai)] text-[var(--ads-number-text)] ${focus}`;
170
- }
171
- return `border border-[var(--ads-number-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
172
- });
173
- </script>
1
+ <template>
2
+ <div class="flex min-w-0 flex-col gap-0.5">
3
+ <div
4
+ v-if="label || info"
5
+ class="flex items-center gap-0.5 text-[length:var(--ads-number-label-size)] leading-[1.2]"
6
+ :class="supportClass"
7
+ >
8
+ <label v-if="label" :for="fieldId">{{ label }}</label>
9
+ <AdsTooltip v-if="info" :description="info" :show-title="false">
10
+ <span class="inline-flex">
11
+ <UIcon name="i-lucide-info" class="size-3 text-xs" />
12
+ </span>
13
+ </AdsTooltip>
14
+ </div>
15
+
16
+ <div
17
+ class="flex h-[var(--ads-number-height)] w-full transition-colors min-w-0 items-center gap-[var(--ads-number-gap)] rounded-[var(--ads-number-radius)] px-[var(--ads-number-padding-x)]"
18
+ :class="fieldClass"
19
+ :data-state="visualState"
20
+ >
21
+ <input
22
+ :id="fieldId"
23
+ ref="inputEl"
24
+ :value="displayValue"
25
+ type="number"
26
+ inputmode="decimal"
27
+ size="4"
28
+ class="w-0 min-w-0 flex-1 bg-transparent text-[length:var(--ads-number-font-size)] leading-[1.3] text-[var(--ads-text-primary)] outline-none placeholder:text-[var(--ads-number-text)] disabled:cursor-not-allowed disabled:text-[var(--ads-number-disabled-text)] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
29
+ :placeholder="placeholder"
30
+ :disabled="isDisabled"
31
+ :min="min"
32
+ :step="step"
33
+ :aria-invalid="error ? true : undefined"
34
+ :aria-describedby="supportText ? supportId : undefined"
35
+ @input="onInput"
36
+ @focus="emit('focus', $event)"
37
+ @blur="emit('blur', $event)"
38
+ >
39
+ <span v-if="suffix" class="shrink-0 text-[length:var(--ads-number-font-size)] leading-[1.3]">{{ suffix }}</span>
40
+ <div class="flex shrink-0 flex-col">
41
+ <button
42
+ type="button"
43
+ class="inline-flex h-3 w-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
44
+ aria-label="Aumentar valor"
45
+ :disabled="isDisabled"
46
+ @mousedown.prevent="stepBy(1)"
47
+ >
48
+ <UIcon name="i-lucide-chevron-up" class="size-3" />
49
+ </button>
50
+ <button
51
+ type="button"
52
+ class="inline-flex h-3 w-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
53
+ aria-label="Diminuir valor"
54
+ :disabled="isDisabled"
55
+ @mousedown.prevent="stepBy(-1)"
56
+ >
57
+ <UIcon name="i-lucide-chevron-down" class="size-3" />
58
+ </button>
59
+ </div>
60
+ </div>
61
+
62
+ <p
63
+ v-if="supportText"
64
+ :id="supportId"
65
+ class="text-xs leading-[1.2]"
66
+ :class="supportClass"
67
+ >
68
+ {{ supportText }}
69
+ </p>
70
+ </div>
71
+ </template>
72
+
73
+ <script setup lang="ts">
74
+ import { computed, useId, useTemplateRef } from "vue";
75
+ import AdsTooltip from "./AdsTooltip.vue";
76
+
77
+ export type AdsNumberInputState = "default" | "active" | "focus" | "error" | "disabled" | "ai";
78
+
79
+ const props = withDefaults(
80
+ defineProps<{
81
+ label?: string;
82
+ hint?: string;
83
+ info?: string;
84
+ error?: string;
85
+ placeholder?: string;
86
+ suffix?: string;
87
+ disabled?: boolean;
88
+ min?: string | number;
89
+ step?: string | number;
90
+ /** Estado congelado para a documentação. `null` segue o campo. */
91
+ state?: AdsNumberInputState | null;
92
+ /** O valor veio de uma sugestão de IA. Quem usa limpa a marca quando a pessoa edita. */
93
+ aiSuggestion?: boolean;
94
+ }>(),
95
+ {
96
+ label: "",
97
+ hint: "",
98
+ info: "",
99
+ error: "",
100
+ placeholder: "",
101
+ suffix: "",
102
+ disabled: false,
103
+ state: null,
104
+ aiSuggestion: false,
105
+ },
106
+ );
107
+
108
+ const model = defineModel<string | number>({ default: "" });
109
+
110
+ const emit = defineEmits<{
111
+ focus: [event: FocusEvent];
112
+ blur: [event: FocusEvent];
113
+ }>();
114
+
115
+ const fieldId = useId();
116
+ const supportId = useId();
117
+ const inputEl = useTemplateRef<HTMLInputElement>("inputEl");
118
+
119
+ const displayValue = computed(() =>
120
+ model.value === undefined || model.value === null ? "" : String(model.value),
121
+ );
122
+
123
+ const onInput = (event: Event) => {
124
+ model.value = (event.target as HTMLInputElement).value;
125
+ };
126
+
127
+ const isDisabled = computed(() => props.disabled || props.state === "disabled");
128
+
129
+ const stepBy = (direction: 1 | -1) => {
130
+ const input = inputEl.value;
131
+ if (!input || isDisabled.value) return;
132
+ if (input.value === "") input.value = String(props.min ?? 0);
133
+ if (direction > 0) input.stepUp();
134
+ else input.stepDown();
135
+ model.value = input.value;
136
+ };
137
+
138
+ const visualState = computed<AdsNumberInputState>(() => {
139
+ if (isDisabled.value) return "disabled";
140
+ if (props.state) return props.state;
141
+ if (props.error) return "error";
142
+ if (props.aiSuggestion) return "ai";
143
+ return displayValue.value ? "active" : "default";
144
+ });
145
+
146
+ const supportText = computed(() => props.error || props.hint);
147
+ const supportClass = computed(() =>
148
+ visualState.value === "disabled"
149
+ ? "text-[var(--ads-number-disabled-text)]"
150
+ : "text-[var(--ads-text-secondary)]",
151
+ );
152
+
153
+ const fieldClass = computed(() => {
154
+ const interactiveFocus = props.state === null && !isDisabled.value && !props.error;
155
+ const focus = interactiveFocus
156
+ ? "hover:not-focus-within:border-[var(--ads-number-hover-border)] focus-within:border-(length:--ads-border-width-slim) focus-within:border-[var(--ads-number-focus-border)]"
157
+ : "";
158
+
159
+ if (visualState.value === "disabled") {
160
+ return "border border-[var(--ads-number-disabled-border)] bg-[var(--ads-number-disabled-background)] text-[var(--ads-number-disabled-text)]";
161
+ }
162
+ if (visualState.value === "error") {
163
+ return `border-(length:--ads-border-width-slim) border-[var(--ads-number-error-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
164
+ }
165
+ if (visualState.value === "focus") {
166
+ return "border-(length:--ads-border-width-slim) border-[var(--ads-number-focus-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)]";
167
+ }
168
+ if (visualState.value === "ai") {
169
+ return `border border-[var(--ads-text-ai)] bg-[var(--ads-surface-ai)] text-[var(--ads-number-text)] ${focus}`;
170
+ }
171
+ return `border border-[var(--ads-number-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
172
+ });
173
+ </script>