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,163 +1,163 @@
1
- import {
2
- CalendarDate,
3
- isEqualMonth,
4
- parseDate,
5
- toCalendarDate,
6
- type DateValue,
7
- } from "@internationalized/date";
8
-
9
- const DATE_ONLY_REGEX = /^\d{4}-\d{2}-\d{2}$/;
10
-
11
- /** Intervalo com início definido. O fim fica `undefined` enquanto o usuário escolhe. */
12
- export type CalendarDateRangeValue = {
13
- start: CalendarDate;
14
- end: CalendarDate | undefined;
15
- };
16
-
17
- /** Valor que o Nuxt UI (UCalendar, UInputDate) entrega nos eventos `update:model-value`. */
18
- export type CalendarEventValue =
19
- | DateValue
20
- | { start: DateValue | undefined; end: DateValue | undefined }
21
- | DateValue[]
22
- | null
23
- | undefined;
24
-
25
- /** Converte o intervalo do Nuxt UI. Sem início, não há intervalo. */
26
- export function toCalendarDateRange(
27
- value: { start?: DateValue; end?: DateValue } | null | undefined,
28
- ): CalendarDateRangeValue | undefined {
29
- if (!value?.start) return undefined;
30
- return {
31
- start: toCalendarDate(value.start),
32
- end: value.end ? toCalendarDate(value.end) : undefined,
33
- };
34
- }
35
-
36
- /** Converte o valor emitido pelo Nuxt UI para data única ou intervalo. Lista de datas não é usada aqui. */
37
- export function toCalendarModel(
38
- value: CalendarEventValue,
39
- ): CalendarDate | CalendarDateRangeValue | undefined {
40
- if (!value || Array.isArray(value)) return undefined;
41
- if ("start" in value) return toCalendarDateRange(value);
42
- return toCalendarDate(value);
43
- }
44
-
45
- export function dateStringToCalendarDate(
46
- value: string,
47
- ): CalendarDate | undefined {
48
- if (!DATE_ONLY_REGEX.test(value)) return undefined;
49
- return parseDate(value);
50
- }
51
-
52
- export function calendarDateToDateString(value: CalendarDate): string {
53
- return value.toString();
54
- }
55
-
56
- export function dateStringsToCalendarRange(
57
- start: string,
58
- end: string,
59
- ): CalendarDateRangeValue | undefined {
60
- const startDate = dateStringToCalendarDate(start);
61
- if (!startDate) return undefined;
62
-
63
- const endDate = dateStringToCalendarDate(end);
64
- if (!endDate) return { start: startDate, end: undefined };
65
-
66
- return { start: startDate, end: endDate };
67
- }
68
-
69
- export function calendarRangeToDateStrings(
70
- range: CalendarDateRangeValue,
71
- ): { start: string; end: string } {
72
- return {
73
- start: calendarDateToDateString(range.start),
74
- end: range.end ? calendarDateToDateString(range.end) : "",
75
- };
76
- }
77
-
78
- export function isCalendarDateRange(
79
- value: CalendarDate | CalendarDateRangeValue | undefined,
80
- ): value is CalendarDateRangeValue {
81
- return Boolean(value && typeof value === "object" && "start" in value);
82
- }
83
-
84
- /**
85
- * A seleção emite a data clicada como placeholder. Se ela já está
86
- * num dos dois meses visíveis, o par permanece. Só troca a janela
87
- * quando a data cai fora dela.
88
- */
89
- export function visibleMonthAfterPlaceholder(
90
- currentLeft: CalendarDate,
91
- incoming: CalendarDate,
92
- ): CalendarDate {
93
- const left = currentLeft.set({ day: 1 });
94
- const right = left.add({ months: 1 });
95
- if (isEqualMonth(incoming, left) || isEqualMonth(incoming, right)) return left;
96
- return incoming.set({ day: 1 });
97
- }
98
-
99
- export function shiftVisibleMonth(
100
- currentLeft: CalendarDate,
101
- delta: -1 | 1,
102
- min?: CalendarDate,
103
- max?: CalendarDate,
104
- ): CalendarDate {
105
- const left = currentLeft.set({ day: 1 });
106
- const next = left.add({ months: delta });
107
- if (delta < 0 && min) {
108
- const lastOfTarget = next.add({ months: 1 }).subtract({ days: 1 });
109
- if (lastOfTarget.compare(min) < 0) return left;
110
- }
111
- if (delta > 0 && max && next.add({ months: 1 }).compare(max) > 0) return left;
112
- return next;
113
- }
114
-
115
- export function isOutsideMaximumWindow(
116
- date: CalendarDate,
117
- anchor: CalendarDate,
118
- maximumDays: number,
119
- ): boolean {
120
- const earliest = anchor.subtract({ days: maximumDays - 1 });
121
- const latest = anchor.add({ days: maximumDays - 1 });
122
- return date.compare(earliest) < 0 || date.compare(latest) > 0;
123
- }
124
-
125
- export function inclusiveCalendarDays(
126
- start: CalendarDate,
127
- end: CalendarDate,
128
- ): number {
129
- const [from, to] = start.compare(end) <= 0 ? [start, end] : [end, start];
130
- const milliseconds = to.toDate("UTC").getTime() - from.toDate("UTC").getTime();
131
- return Math.round(milliseconds / 86_400_000) + 1;
132
- }
133
-
134
- export function calendarMonthTitle(
135
- date: CalendarDate,
136
- locale = "pt-BR",
137
- ): string {
138
- const label = new Intl.DateTimeFormat(locale, {
139
- month: "long",
140
- timeZone: "UTC",
141
- }).format(date.toDate("UTC"));
142
- return label.charAt(0).toUpperCase() + label.slice(1);
143
- }
144
-
145
- export function calendarRangesEqual(
146
- left: CalendarDate | CalendarDateRangeValue | undefined,
147
- right: CalendarDate | CalendarDateRangeValue | undefined,
148
- ): boolean {
149
- if (left === right) return true;
150
- if (!left || !right) return !left && !right;
151
-
152
- if (isCalendarDateRange(left) && isCalendarDateRange(right)) {
153
- const leftEnd = left.end?.toString() ?? "";
154
- const rightEnd = right.end?.toString() ?? "";
155
- return left.start.toString() === right.start.toString() && leftEnd === rightEnd;
156
- }
157
-
158
- if (!isCalendarDateRange(left) && !isCalendarDateRange(right)) {
159
- return left.toString() === right.toString();
160
- }
161
-
162
- return false;
163
- }
1
+ import {
2
+ CalendarDate,
3
+ isEqualMonth,
4
+ parseDate,
5
+ toCalendarDate,
6
+ type DateValue,
7
+ } from "@internationalized/date";
8
+
9
+ const DATE_ONLY_REGEX = /^\d{4}-\d{2}-\d{2}$/;
10
+
11
+ /** Intervalo com início definido. O fim fica `undefined` enquanto o usuário escolhe. */
12
+ export type CalendarDateRangeValue = {
13
+ start: CalendarDate;
14
+ end: CalendarDate | undefined;
15
+ };
16
+
17
+ /** Valor que o Nuxt UI (UCalendar, UInputDate) entrega nos eventos `update:model-value`. */
18
+ export type CalendarEventValue =
19
+ | DateValue
20
+ | { start: DateValue | undefined; end: DateValue | undefined }
21
+ | DateValue[]
22
+ | null
23
+ | undefined;
24
+
25
+ /** Converte o intervalo do Nuxt UI. Sem início, não há intervalo. */
26
+ export function toCalendarDateRange(
27
+ value: { start?: DateValue; end?: DateValue } | null | undefined,
28
+ ): CalendarDateRangeValue | undefined {
29
+ if (!value?.start) return undefined;
30
+ return {
31
+ start: toCalendarDate(value.start),
32
+ end: value.end ? toCalendarDate(value.end) : undefined,
33
+ };
34
+ }
35
+
36
+ /** Converte o valor emitido pelo Nuxt UI para data única ou intervalo. Lista de datas não é usada aqui. */
37
+ export function toCalendarModel(
38
+ value: CalendarEventValue,
39
+ ): CalendarDate | CalendarDateRangeValue | undefined {
40
+ if (!value || Array.isArray(value)) return undefined;
41
+ if ("start" in value) return toCalendarDateRange(value);
42
+ return toCalendarDate(value);
43
+ }
44
+
45
+ export function dateStringToCalendarDate(
46
+ value: string,
47
+ ): CalendarDate | undefined {
48
+ if (!DATE_ONLY_REGEX.test(value)) return undefined;
49
+ return parseDate(value);
50
+ }
51
+
52
+ export function calendarDateToDateString(value: CalendarDate): string {
53
+ return value.toString();
54
+ }
55
+
56
+ export function dateStringsToCalendarRange(
57
+ start: string,
58
+ end: string,
59
+ ): CalendarDateRangeValue | undefined {
60
+ const startDate = dateStringToCalendarDate(start);
61
+ if (!startDate) return undefined;
62
+
63
+ const endDate = dateStringToCalendarDate(end);
64
+ if (!endDate) return { start: startDate, end: undefined };
65
+
66
+ return { start: startDate, end: endDate };
67
+ }
68
+
69
+ export function calendarRangeToDateStrings(
70
+ range: CalendarDateRangeValue,
71
+ ): { start: string; end: string } {
72
+ return {
73
+ start: calendarDateToDateString(range.start),
74
+ end: range.end ? calendarDateToDateString(range.end) : "",
75
+ };
76
+ }
77
+
78
+ export function isCalendarDateRange(
79
+ value: CalendarDate | CalendarDateRangeValue | undefined,
80
+ ): value is CalendarDateRangeValue {
81
+ return Boolean(value && typeof value === "object" && "start" in value);
82
+ }
83
+
84
+ /**
85
+ * A seleção emite a data clicada como placeholder. Se ela já está
86
+ * num dos dois meses visíveis, o par permanece. Só troca a janela
87
+ * quando a data cai fora dela.
88
+ */
89
+ export function visibleMonthAfterPlaceholder(
90
+ currentLeft: CalendarDate,
91
+ incoming: CalendarDate,
92
+ ): CalendarDate {
93
+ const left = currentLeft.set({ day: 1 });
94
+ const right = left.add({ months: 1 });
95
+ if (isEqualMonth(incoming, left) || isEqualMonth(incoming, right)) return left;
96
+ return incoming.set({ day: 1 });
97
+ }
98
+
99
+ export function shiftVisibleMonth(
100
+ currentLeft: CalendarDate,
101
+ delta: -1 | 1,
102
+ min?: CalendarDate,
103
+ max?: CalendarDate,
104
+ ): CalendarDate {
105
+ const left = currentLeft.set({ day: 1 });
106
+ const next = left.add({ months: delta });
107
+ if (delta < 0 && min) {
108
+ const lastOfTarget = next.add({ months: 1 }).subtract({ days: 1 });
109
+ if (lastOfTarget.compare(min) < 0) return left;
110
+ }
111
+ if (delta > 0 && max && next.add({ months: 1 }).compare(max) > 0) return left;
112
+ return next;
113
+ }
114
+
115
+ export function isOutsideMaximumWindow(
116
+ date: CalendarDate,
117
+ anchor: CalendarDate,
118
+ maximumDays: number,
119
+ ): boolean {
120
+ const earliest = anchor.subtract({ days: maximumDays - 1 });
121
+ const latest = anchor.add({ days: maximumDays - 1 });
122
+ return date.compare(earliest) < 0 || date.compare(latest) > 0;
123
+ }
124
+
125
+ export function inclusiveCalendarDays(
126
+ start: CalendarDate,
127
+ end: CalendarDate,
128
+ ): number {
129
+ const [from, to] = start.compare(end) <= 0 ? [start, end] : [end, start];
130
+ const milliseconds = to.toDate("UTC").getTime() - from.toDate("UTC").getTime();
131
+ return Math.round(milliseconds / 86_400_000) + 1;
132
+ }
133
+
134
+ export function calendarMonthTitle(
135
+ date: CalendarDate,
136
+ locale = "pt-BR",
137
+ ): string {
138
+ const label = new Intl.DateTimeFormat(locale, {
139
+ month: "long",
140
+ timeZone: "UTC",
141
+ }).format(date.toDate("UTC"));
142
+ return label.charAt(0).toUpperCase() + label.slice(1);
143
+ }
144
+
145
+ export function calendarRangesEqual(
146
+ left: CalendarDate | CalendarDateRangeValue | undefined,
147
+ right: CalendarDate | CalendarDateRangeValue | undefined,
148
+ ): boolean {
149
+ if (left === right) return true;
150
+ if (!left || !right) return !left && !right;
151
+
152
+ if (isCalendarDateRange(left) && isCalendarDateRange(right)) {
153
+ const leftEnd = left.end?.toString() ?? "";
154
+ const rightEnd = right.end?.toString() ?? "";
155
+ return left.start.toString() === right.start.toString() && leftEnd === rightEnd;
156
+ }
157
+
158
+ if (!isCalendarDateRange(left) && !isCalendarDateRange(right)) {
159
+ return left.toString() === right.toString();
160
+ }
161
+
162
+ return false;
163
+ }
@@ -1,45 +1,45 @@
1
- export const CATEGORY_ROLES = [
2
- "destination",
3
- "routine",
4
- "seasonal",
5
- "convenience",
6
- ] as const;
7
-
8
- export type CategoryRole = (typeof CATEGORY_ROLES)[number];
9
-
10
- const CATEGORY_ROLE_LABELS: Record<CategoryRole, string> = {
11
- destination: "Destino",
12
- routine: "Rotina",
13
- seasonal: "Sazonal",
14
- convenience: "Conveniência",
15
- };
16
-
17
- export const CATEGORY_ROLE_OPTIONS = CATEGORY_ROLES.map((role) => ({
18
- label: CATEGORY_ROLE_LABELS[role],
19
- value: role,
20
- }));
21
-
22
- export const formatCategoryRole = (role: CategoryRole | null): string =>
23
- role ? CATEGORY_ROLE_LABELS[role] : "-";
24
-
25
- const stripDiacritics = (value: string): string =>
26
- value.normalize("NFD").replace(/\p{Diacritic}/gu, "");
27
-
28
- export const parseCategoryRole = (
29
- raw: string | null | undefined,
30
- ): CategoryRole | null => {
31
- const normalized = stripDiacritics(String(raw ?? "").trim()).toLowerCase();
32
-
33
- if (!normalized) return null;
34
-
35
- if (normalized.startsWith("destin")) return "destination";
36
- if (normalized.startsWith("rotin") || normalized.startsWith("routin")) {
37
- return "routine";
38
- }
39
- if (normalized.startsWith("sazon") || normalized.startsWith("season")) {
40
- return "seasonal";
41
- }
42
- if (normalized.startsWith("conven")) return "convenience";
43
-
44
- return null;
45
- };
1
+ export const CATEGORY_ROLES = [
2
+ "destination",
3
+ "routine",
4
+ "seasonal",
5
+ "convenience",
6
+ ] as const;
7
+
8
+ export type CategoryRole = (typeof CATEGORY_ROLES)[number];
9
+
10
+ const CATEGORY_ROLE_LABELS: Record<CategoryRole, string> = {
11
+ destination: "Destino",
12
+ routine: "Rotina",
13
+ seasonal: "Sazonal",
14
+ convenience: "Conveniência",
15
+ };
16
+
17
+ export const CATEGORY_ROLE_OPTIONS = CATEGORY_ROLES.map((role) => ({
18
+ label: CATEGORY_ROLE_LABELS[role],
19
+ value: role,
20
+ }));
21
+
22
+ export const formatCategoryRole = (role: CategoryRole | null): string =>
23
+ role ? CATEGORY_ROLE_LABELS[role] : "-";
24
+
25
+ const stripDiacritics = (value: string): string =>
26
+ value.normalize("NFD").replace(/\p{Diacritic}/gu, "");
27
+
28
+ export const parseCategoryRole = (
29
+ raw: string | null | undefined,
30
+ ): CategoryRole | null => {
31
+ const normalized = stripDiacritics(String(raw ?? "").trim()).toLowerCase();
32
+
33
+ if (!normalized) return null;
34
+
35
+ if (normalized.startsWith("destin")) return "destination";
36
+ if (normalized.startsWith("rotin") || normalized.startsWith("routin")) {
37
+ return "routine";
38
+ }
39
+ if (normalized.startsWith("sazon") || normalized.startsWith("season")) {
40
+ return "seasonal";
41
+ }
42
+ if (normalized.startsWith("conven")) return "convenience";
43
+
44
+ return null;
45
+ };
@@ -1,77 +1,77 @@
1
- export const numberToBRL = (
2
- price: number | undefined | null,
3
- withSignal = false
4
- ): string => {
5
- if (price == null) return "-";
6
-
7
- const sign = price < 0 ? "-" : withSignal && price > 0 ? "+" : "";
8
- const value = new Intl.NumberFormat("pt-BR", {
9
- style: "currency",
10
- currency: "BRL",
11
- }).format(Math.abs(price));
12
-
13
- return `R$ ${sign}${value.replace("R$", "").trim()}`;
14
- };
15
-
16
- const MILLION = 1_000_000;
17
- const THOUSAND = 1_000;
18
-
19
- const COMPACT_DECIMAL_FORMATTER = new Intl.NumberFormat("pt-BR", {
20
- minimumFractionDigits: 2,
21
- maximumFractionDigits: 2,
22
- });
23
-
24
- export const numberToCompactBRL = (
25
- value: number | undefined | null,
26
- ): string => {
27
- if (value == null || Number.isNaN(value)) return "-";
28
-
29
- const sign = value < 0 ? "-" : "";
30
- const absolute = Math.abs(value);
31
-
32
- if (absolute >= MILLION) {
33
- return `R$ ${sign}${COMPACT_DECIMAL_FORMATTER.format(absolute / MILLION)}MM`;
34
- }
35
-
36
- if (absolute >= THOUSAND) {
37
- return `R$ ${sign}${COMPACT_DECIMAL_FORMATTER.format(absolute / THOUSAND)}M`;
38
- }
39
-
40
- return numberToBRL(value);
41
- };
42
-
43
- export const parseStringMoneyToFloat = (value: string): number | null => {
44
- if (!value || typeof value !== "string") return null;
45
- const cleanValue = value.replace(/[^\d,.-]/g, "");
46
- if (!cleanValue) return null;
47
- const normalizedValue = cleanValue.replace(",", ".");
48
- const parsed = parseFloat(normalizedValue);
49
- return Number.isNaN(parsed) ? null : parsed;
50
- };
51
-
52
- const BRL_INPUT_FORMATTER = new Intl.NumberFormat("pt-BR", {
53
- minimumFractionDigits: 2,
54
- maximumFractionDigits: 2,
55
- });
56
-
57
- /**
58
- * Formata valor numérico para exibição em input monetário (padrão R$).
59
- * pt-BR: vírgula decimal, ponto milhares, 2 decimais. Sem símbolo R$.
60
- * Use o valor retornado apenas para exibição; persista sempre o número.
61
- */
62
- export function formatPriceInput(value?: number | null): string {
63
- if (value === undefined || value === null || Number.isNaN(value)) return "";
64
- return BRL_INPUT_FORMATTER.format(Number(value.toFixed(2)));
65
- }
66
-
67
- /**
68
- * Converte o valor digitado em máscara monetária para número em reais.
69
- * Sanitiza (apenas dígitos), interpreta como centavos (últimos 2 = decimais)
70
- * e retorna valor para persistência no backend.
71
- */
72
- export function parsePriceInput(value: string | number): number {
73
- if (typeof value === "number" && !Number.isNaN(value))
74
- return Math.round(value * 100) / 100;
75
- const digits = String(value ?? "").replace(/\D/g, "");
76
- return parseInt(digits || "0", 10) / 100;
77
- }
1
+ export const numberToBRL = (
2
+ price: number | undefined | null,
3
+ withSignal = false
4
+ ): string => {
5
+ if (price == null) return "-";
6
+
7
+ const sign = price < 0 ? "-" : withSignal && price > 0 ? "+" : "";
8
+ const value = new Intl.NumberFormat("pt-BR", {
9
+ style: "currency",
10
+ currency: "BRL",
11
+ }).format(Math.abs(price));
12
+
13
+ return `R$ ${sign}${value.replace("R$", "").trim()}`;
14
+ };
15
+
16
+ const MILLION = 1_000_000;
17
+ const THOUSAND = 1_000;
18
+
19
+ const COMPACT_DECIMAL_FORMATTER = new Intl.NumberFormat("pt-BR", {
20
+ minimumFractionDigits: 2,
21
+ maximumFractionDigits: 2,
22
+ });
23
+
24
+ export const numberToCompactBRL = (
25
+ value: number | undefined | null,
26
+ ): string => {
27
+ if (value == null || Number.isNaN(value)) return "-";
28
+
29
+ const sign = value < 0 ? "-" : "";
30
+ const absolute = Math.abs(value);
31
+
32
+ if (absolute >= MILLION) {
33
+ return `R$ ${sign}${COMPACT_DECIMAL_FORMATTER.format(absolute / MILLION)}MM`;
34
+ }
35
+
36
+ if (absolute >= THOUSAND) {
37
+ return `R$ ${sign}${COMPACT_DECIMAL_FORMATTER.format(absolute / THOUSAND)}M`;
38
+ }
39
+
40
+ return numberToBRL(value);
41
+ };
42
+
43
+ export const parseStringMoneyToFloat = (value: string): number | null => {
44
+ if (!value || typeof value !== "string") return null;
45
+ const cleanValue = value.replace(/[^\d,.-]/g, "");
46
+ if (!cleanValue) return null;
47
+ const normalizedValue = cleanValue.replace(",", ".");
48
+ const parsed = parseFloat(normalizedValue);
49
+ return Number.isNaN(parsed) ? null : parsed;
50
+ };
51
+
52
+ const BRL_INPUT_FORMATTER = new Intl.NumberFormat("pt-BR", {
53
+ minimumFractionDigits: 2,
54
+ maximumFractionDigits: 2,
55
+ });
56
+
57
+ /**
58
+ * Formata valor numérico para exibição em input monetário (padrão R$).
59
+ * pt-BR: vírgula decimal, ponto milhares, 2 decimais. Sem símbolo R$.
60
+ * Use o valor retornado apenas para exibição; persista sempre o número.
61
+ */
62
+ export function formatPriceInput(value?: number | null): string {
63
+ if (value === undefined || value === null || Number.isNaN(value)) return "";
64
+ return BRL_INPUT_FORMATTER.format(Number(value.toFixed(2)));
65
+ }
66
+
67
+ /**
68
+ * Converte o valor digitado em máscara monetária para número em reais.
69
+ * Sanitiza (apenas dígitos), interpreta como centavos (últimos 2 = decimais)
70
+ * e retorna valor para persistência no backend.
71
+ */
72
+ export function parsePriceInput(value: string | number): number {
73
+ if (typeof value === "number" && !Number.isNaN(value))
74
+ return Math.round(value * 100) / 100;
75
+ const digits = String(value ?? "").replace(/\D/g, "");
76
+ return parseInt(digits || "0", 10) / 100;
77
+ }
@@ -1,8 +1,8 @@
1
- const NOTABILITY_LABELS: Record<string, string> = {
2
- traffic: "Gerador de Tráfego",
3
- image: "Formador de Imagem",
4
- profit: "Gerador de Lucro",
5
- };
6
-
7
- export const formatNotability = (notability: string): string =>
8
- NOTABILITY_LABELS[notability] ?? notability;
1
+ const NOTABILITY_LABELS: Record<string, string> = {
2
+ traffic: "Gerador de Tráfego",
3
+ image: "Formador de Imagem",
4
+ profit: "Gerador de Lucro",
5
+ };
6
+
7
+ export const formatNotability = (notability: string): string =>
8
+ NOTABILITY_LABELS[notability] ?? notability;