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,62 +1,62 @@
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)] px-[var(--ads-navbar-desk-padding-x)] 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-2">
8
- <AdsBroadcast v-if="showBroadcast" />
9
- <button
10
- v-for="action in actions"
11
- :key="action.id"
12
- type="button"
13
- 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)]"
14
- :aria-label="action.label"
15
- @click="emit('action', action.id)"
16
- >
17
- <UIcon :name="action.icon" class="size-[18px]" />
18
- </button>
19
- <span class="flex size-[var(--ads-navbar-desk-avatar)] items-center justify-center overflow-hidden rounded-full bg-ads-neutro-claro-30" aria-hidden="true">
20
- <img v-if="avatarUrl" :src="avatarUrl" alt="" class="size-full object-cover" />
21
- <UIcon v-else name="i-lucide-user" class="size-4 text-[var(--ads-text-secondary)]" />
22
- </span>
23
- </div>
24
- </header>
25
- </template>
26
-
27
- <script setup lang="ts">
28
- import radarUrl from "../assets/brand/radar.svg?url";
29
- import AdsBroadcast from "./AdsBroadcast.vue";
30
- import AdsProductTag, { type AdsProductTagName } from "./AdsProductTag.vue";
31
-
32
- export type AdsNavbarDeskAction = {
33
- id: string;
34
- label: string;
35
- icon: string;
36
- };
37
-
38
- withDefaults(
39
- defineProps<{
40
- product?: AdsProductTagName | null;
41
- productLabel?: string;
42
- showBroadcast?: boolean;
43
- avatarUrl?: string;
44
- actions?: AdsNavbarDeskAction[];
45
- }>(),
46
- {
47
- product: "performance",
48
- productLabel: "performance",
49
- showBroadcast: true,
50
- avatarUrl: "",
51
- actions: () => [
52
- { id: "alerts", label: "Alertas", icon: "i-lucide-bell" },
53
- { id: "settings", label: "Configurações", icon: "i-lucide-settings" },
54
- { id: "apps", label: "Aplicativos", icon: "i-lucide-layout-grid" },
55
- ],
56
- },
57
- );
58
-
59
- const emit = defineEmits<{
60
- action: [id: string];
61
- }>();
62
- </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)] px-[var(--ads-navbar-desk-padding-x)] 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-2">
8
+ <AdsPill v-if="showBroadcast" variant="broadcast" status="warning" />
9
+ <button
10
+ v-for="action in actions"
11
+ :key="action.id"
12
+ type="button"
13
+ 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)]"
14
+ :aria-label="action.label"
15
+ @click="emit('action', action.id)"
16
+ >
17
+ <UIcon :name="action.icon" class="size-[18px]" />
18
+ </button>
19
+ <span class="flex size-[var(--ads-navbar-desk-avatar)] items-center justify-center overflow-hidden rounded-full bg-ads-neutro-claro-30" aria-hidden="true">
20
+ <img v-if="avatarUrl" :src="avatarUrl" alt="" class="size-full object-cover" />
21
+ <UIcon v-else name="i-lucide-user" class="size-4 text-[var(--ads-text-secondary)]" />
22
+ </span>
23
+ </div>
24
+ </header>
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ import radarUrl from "../assets/brand/radar.svg?url";
29
+ import AdsPill from "./AdsPill.vue";
30
+ import AdsProductTag, { type AdsProductTagName } from "./AdsProductTag.vue";
31
+
32
+ export type AdsNavbarDeskAction = {
33
+ id: string;
34
+ label: string;
35
+ icon: string;
36
+ };
37
+
38
+ withDefaults(
39
+ defineProps<{
40
+ product?: AdsProductTagName | null;
41
+ productLabel?: string;
42
+ showBroadcast?: boolean;
43
+ avatarUrl?: string;
44
+ actions?: AdsNavbarDeskAction[];
45
+ }>(),
46
+ {
47
+ product: "performance",
48
+ productLabel: "performance",
49
+ showBroadcast: true,
50
+ avatarUrl: "",
51
+ actions: () => [
52
+ { id: "alerts", label: "Alertas", icon: "i-lucide-bell" },
53
+ { id: "settings", label: "Configurações", icon: "i-lucide-settings" },
54
+ { id: "apps", label: "Aplicativos", icon: "i-lucide-layout-grid" },
55
+ ],
56
+ },
57
+ );
58
+
59
+ const emit = defineEmits<{
60
+ action: [id: string];
61
+ }>();
62
+ </script>
@@ -1,27 +1,24 @@
1
- <template>
2
- <span
3
- class="inline-flex h-[var(--ads-notability-height)] min-w-[var(--ads-notability-min-width)] shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full px-[var(--ads-notability-padding-x)] py-1 text-center text-[length:var(--ads-notability-font-size)] [font-weight:var(--ads-notability-weight)] leading-[1.2] whitespace-nowrap"
4
- :class="surfaceClass"
5
- >
6
- {{ resolvedLabel }}
7
- </span>
8
- </template>
9
-
10
- <script setup lang="ts">
11
- import { computed } from "vue";
12
- import { formatNotability } from "../utils/notability";
13
-
14
- const props = defineProps<{
15
- notability: string;
16
- label?: string;
17
- }>();
18
-
19
- const surfaces: Record<string, string> = {
20
- image: "bg-[var(--ads-status-new-100)] text-[var(--ads-status-new-800)]",
21
- traffic: "bg-[var(--ads-status-success-100)] text-[var(--ads-status-success-800)]",
22
- profit: "bg-[var(--ads-status-innovation-100)] text-[var(--ads-status-innovation-800)]",
23
- };
24
-
25
- const surfaceClass = computed(() => surfaces[props.notability] ?? surfaces.image);
26
- const resolvedLabel = computed(() => props.label ?? formatNotability(props.notability));
27
- </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,166 +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] outline-none placeholder:text-current disabled:cursor-not-allowed [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
- <div class="flex shrink-0 flex-col">
40
- <button
41
- type="button"
42
- class="inline-flex size-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
43
- aria-label="Aumentar valor"
44
- :disabled="isDisabled"
45
- @mousedown.prevent="stepBy(1)"
46
- >
47
- <UIcon name="i-lucide-chevron-up" class="size-3.5" />
48
- </button>
49
- <button
50
- type="button"
51
- class="inline-flex size-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
52
- aria-label="Diminuir valor"
53
- :disabled="isDisabled"
54
- @mousedown.prevent="stepBy(-1)"
55
- >
56
- <UIcon name="i-lucide-chevron-down" class="size-3.5" />
57
- </button>
58
- </div>
59
- <span v-if="suffix" class="shrink-0 text-[length:var(--ads-number-font-size)] leading-[1.3]">{{ suffix }}</span>
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";
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
- }>(),
93
- {
94
- label: "",
95
- hint: "",
96
- info: "",
97
- error: "",
98
- placeholder: "",
99
- suffix: "",
100
- disabled: false,
101
- state: null,
102
- },
103
- );
104
-
105
- const model = defineModel<string | number>({ default: "" });
106
-
107
- const emit = defineEmits<{
108
- focus: [event: FocusEvent];
109
- blur: [event: FocusEvent];
110
- }>();
111
-
112
- const fieldId = useId();
113
- const supportId = useId();
114
- const inputEl = useTemplateRef<HTMLInputElement>("inputEl");
115
-
116
- const displayValue = computed(() =>
117
- model.value === undefined || model.value === null ? "" : String(model.value),
118
- );
119
-
120
- const onInput = (event: Event) => {
121
- model.value = (event.target as HTMLInputElement).value;
122
- };
123
-
124
- const isDisabled = computed(() => props.disabled || props.state === "disabled");
125
-
126
- const stepBy = (direction: 1 | -1) => {
127
- const input = inputEl.value;
128
- if (!input || isDisabled.value) return;
129
- if (input.value === "") input.value = String(props.min ?? 0);
130
- if (direction > 0) input.stepUp();
131
- else input.stepDown();
132
- model.value = input.value;
133
- };
134
-
135
- const visualState = computed<AdsNumberInputState>(() => {
136
- if (isDisabled.value) return "disabled";
137
- if (props.state) return props.state;
138
- if (props.error) return "error";
139
- return displayValue.value ? "active" : "default";
140
- });
141
-
142
- const supportText = computed(() => props.error || props.hint);
143
- const supportClass = computed(() =>
144
- visualState.value === "disabled"
145
- ? "text-[var(--ads-text-tertiary)]"
146
- : "text-[var(--ads-text-secondary)]",
147
- );
148
-
149
- const fieldClass = computed(() => {
150
- const interactiveFocus = props.state === null && !isDisabled.value && !props.error;
151
- const focus = interactiveFocus
152
- ? "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)]"
153
- : "";
154
-
155
- if (visualState.value === "disabled") {
156
- return "border border-[var(--ads-number-disabled-border)] bg-[var(--ads-number-disabled-background)] text-[var(--ads-number-disabled-text)]";
157
- }
158
- if (visualState.value === "error") {
159
- return `border-(length:--ads-border-width-slim) border-[var(--ads-number-error-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
160
- }
161
- if (visualState.value === "focus") {
162
- return "border-(length:--ads-border-width-slim) border-[var(--ads-number-focus-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)]";
163
- }
164
- return `border border-[var(--ads-number-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
165
- });
166
- </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] outline-none placeholder:text-current disabled:cursor-not-allowed [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
+ <div class="flex shrink-0 flex-col">
40
+ <button
41
+ type="button"
42
+ class="inline-flex size-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
43
+ aria-label="Aumentar valor"
44
+ :disabled="isDisabled"
45
+ @mousedown.prevent="stepBy(1)"
46
+ >
47
+ <UIcon name="i-lucide-chevron-up" class="size-3.5" />
48
+ </button>
49
+ <button
50
+ type="button"
51
+ class="inline-flex size-4 items-center justify-center rounded-sm text-current hover:bg-[var(--ads-button-secondary-hover)] disabled:cursor-not-allowed"
52
+ aria-label="Diminuir valor"
53
+ :disabled="isDisabled"
54
+ @mousedown.prevent="stepBy(-1)"
55
+ >
56
+ <UIcon name="i-lucide-chevron-down" class="size-3.5" />
57
+ </button>
58
+ </div>
59
+ <span v-if="suffix" class="shrink-0 text-[length:var(--ads-number-font-size)] leading-[1.3]">{{ suffix }}</span>
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-text-tertiary)]"
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-button-ia-border)] bg-[var(--ads-surface-ai)] text-[var(--ads-text-ai)] ${focus}`;
170
+ }
171
+ return `border border-[var(--ads-number-border)] bg-[var(--ads-number-background)] text-[var(--ads-number-text)] ${focus}`;
172
+ });
173
+ </script>