@vowt-tech/ui 0.0.0-stage → 0.177.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.
- package/README.md +13 -2
- package/bin/vowt-ux-ui-design.mjs +483 -0
- package/guia/LEIA-PRIMEIRO.md +106 -0
- package/guia/VERSAO +1 -0
- package/guia/componentes.md +104 -0
- package/guia/regras/atualizar.md +136 -0
- package/guia/regras/componentes.md +374 -0
- package/guia/regras/fundamentos.md +257 -0
- package/guia/regras/marca.md +200 -0
- package/guia/regras/medidas.md +114 -0
- package/guia/regras/regras-de-base.md +85 -0
- package/guia/regras/telas/acoes.md +56 -0
- package/guia/regras/telas/direcao-ux.md +327 -0
- package/guia/regras/telas/padroes.md +58 -0
- package/guia/regras/telas/regras.md +171 -0
- package/guia/regras/telas/voz.md +134 -0
- package/package.json +72 -4
- package/src/brand/icons.ts +215 -0
- package/src/brand/logo.tsx +288 -0
- package/src/components/accordion.tsx +58 -0
- package/src/components/ai-orb.tsx +67 -0
- package/src/components/alert-dialog.tsx +227 -0
- package/src/components/alert.tsx +128 -0
- package/src/components/area-chart.tsx +180 -0
- package/src/components/attachment.tsx +339 -0
- package/src/components/avatar.tsx +197 -0
- package/src/components/badge.tsx +242 -0
- package/src/components/bar-chart.tsx +138 -0
- package/src/components/bar-list.tsx +85 -0
- package/src/components/brand-icon.tsx +52 -0
- package/src/components/breadcrumb.tsx +96 -0
- package/src/components/button-group.tsx +29 -0
- package/src/components/button.tsx +208 -0
- package/src/components/calendar.tsx +238 -0
- package/src/components/card.tsx +136 -0
- package/src/components/chart.tsx +289 -0
- package/src/components/checkbox.tsx +42 -0
- package/src/components/code-block.tsx +31 -0
- package/src/components/collapsible.tsx +114 -0
- package/src/components/color-picker.tsx +93 -0
- package/src/components/combo-chart.tsx +139 -0
- package/src/components/combobox.tsx +200 -0
- package/src/components/command.tsx +191 -0
- package/src/components/date-picker.tsx +435 -0
- package/src/components/description-list.tsx +280 -0
- package/src/components/dialog.tsx +192 -0
- package/src/components/diff-view.tsx +109 -0
- package/src/components/dropdown-menu.tsx +248 -0
- package/src/components/emoji-picker.tsx +299 -0
- package/src/components/empty.tsx +197 -0
- package/src/components/field.tsx +226 -0
- package/src/components/file-upload.tsx +186 -0
- package/src/components/funnel-chart.tsx +224 -0
- package/src/components/gauge-chart.tsx +109 -0
- package/src/components/heatmap.tsx +105 -0
- package/src/components/hover-card.tsx +47 -0
- package/src/components/image-viewer.tsx +174 -0
- package/src/components/input-otp.tsx +86 -0
- package/src/components/input.tsx +470 -0
- package/src/components/item.tsx +94 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +21 -0
- package/src/components/line-chart.tsx +92 -0
- package/src/components/link.tsx +34 -0
- package/src/components/message.tsx +903 -0
- package/src/components/number-field.tsx +79 -0
- package/src/components/pagination.tsx +208 -0
- package/src/components/phone-input.tsx +147 -0
- package/src/components/pie-chart.tsx +117 -0
- package/src/components/popover.tsx +102 -0
- package/src/components/powered-by.tsx +39 -0
- package/src/components/progress.tsx +278 -0
- package/src/components/prose.tsx +42 -0
- package/src/components/radar-chart.tsx +66 -0
- package/src/components/radial-chart.tsx +73 -0
- package/src/components/radio-group.tsx +135 -0
- package/src/components/rating.tsx +192 -0
- package/src/components/rich-text.tsx +1651 -0
- package/src/components/scatter-chart.tsx +115 -0
- package/src/components/scroll-area.tsx +50 -0
- package/src/components/select.tsx +193 -0
- package/src/components/separator.tsx +20 -0
- package/src/components/sheet.tsx +142 -0
- package/src/components/sidebar.tsx +570 -0
- package/src/components/skeleton.tsx +18 -0
- package/src/components/slider.tsx +47 -0
- package/src/components/sonner.tsx +178 -0
- package/src/components/sparkline.tsx +68 -0
- package/src/components/spinner.tsx +35 -0
- package/src/components/status-dot.tsx +45 -0
- package/src/components/stepper.tsx +228 -0
- package/src/components/switch.tsx +35 -0
- package/src/components/table.tsx +267 -0
- package/src/components/tabs.tsx +184 -0
- package/src/components/tag-input.tsx +238 -0
- package/src/components/textarea.tsx +47 -0
- package/src/components/time-picker.tsx +183 -0
- package/src/components/timeline.tsx +75 -0
- package/src/components/toggle-group.tsx +93 -0
- package/src/components/toggle.tsx +51 -0
- package/src/components/tooltip.tsx +160 -0
- package/src/components/tree.tsx +136 -0
- package/src/components/voice-message.tsx +193 -0
- package/src/css.d.ts +2 -0
- package/src/hooks/use-appearance.ts +57 -0
- package/src/hooks/use-mobile.ts +20 -0
- package/src/lib/appearance.ts +16 -0
- package/src/lib/button-render.ts +32 -0
- package/src/lib/char-count.tsx +67 -0
- package/src/lib/date.ts +45 -0
- package/src/lib/file-accept.ts +59 -0
- package/src/lib/markdown.ts +187 -0
- package/src/lib/utils.ts +29 -0
- package/src/lib/voice.ts +68 -0
- package/src/styles/shadcn.css +642 -0
- package/src/styles/theme.css +1825 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { CalendarIcon, ChevronDownIcon, TrashIcon } from 'lucide-react';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { Button } from './button';
|
|
6
|
+
import { Calendar } from './calendar';
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuContent,
|
|
10
|
+
DropdownMenuRadioGroup,
|
|
11
|
+
DropdownMenuRadioItem,
|
|
12
|
+
DropdownMenuTrigger,
|
|
13
|
+
} from './dropdown-menu';
|
|
14
|
+
import { Popover, PopoverContent, PopoverTrigger } from './popover';
|
|
15
|
+
import { TimePicker } from './time-picker';
|
|
16
|
+
import { cn } from '../lib/utils';
|
|
17
|
+
import { parseDate, toDateValue } from '../lib/date';
|
|
18
|
+
|
|
19
|
+
// Campo de data: botão com a cara de campo que abre o Calendar num Popover, no lugar do
|
|
20
|
+
// campo de data do navegador (que muda de cara em cada navegador). O valor continua sendo o texto
|
|
21
|
+
// "2026-10-30", como o campo nativo, para as telas não mudarem a forma de guardar.
|
|
22
|
+
|
|
23
|
+
/** Anos no topo do calendário: de 1920 (nascimentos) a 10 anos à frente (vencimentos). */
|
|
24
|
+
const FIRST = new Date(1920, 0);
|
|
25
|
+
const LAST = new Date(new Date().getFullYear() + 10, 11);
|
|
26
|
+
|
|
27
|
+
const show = new Intl.DateTimeFormat('pt-BR', {
|
|
28
|
+
day: '2-digit',
|
|
29
|
+
month: '2-digit',
|
|
30
|
+
year: 'numeric',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export function DatePicker({
|
|
34
|
+
id,
|
|
35
|
+
value,
|
|
36
|
+
onChange,
|
|
37
|
+
disabled,
|
|
38
|
+
placeholder = 'Escolha a data',
|
|
39
|
+
clearable = true,
|
|
40
|
+
size = 'default',
|
|
41
|
+
min,
|
|
42
|
+
max,
|
|
43
|
+
className,
|
|
44
|
+
'aria-required': required,
|
|
45
|
+
}: {
|
|
46
|
+
id?: string;
|
|
47
|
+
/** "2026-10-30" ou vazio. */
|
|
48
|
+
value: string;
|
|
49
|
+
onChange: (value: string) => void;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
/** Mostra "Limpar" quando há data. */
|
|
53
|
+
clearable?: boolean;
|
|
54
|
+
/** Altura 32, 40 ou 48, como o Input: o pequeno para barra de filtros. */
|
|
55
|
+
size?: 'sm' | 'default' | 'lg';
|
|
56
|
+
/** Primeiro dia que pode ser escolhido, como "2026-10-30"; os de antes ficam apagados. */
|
|
57
|
+
min?: string;
|
|
58
|
+
/** Último dia que pode ser escolhido; os de depois ficam apagados. */
|
|
59
|
+
max?: string;
|
|
60
|
+
className?: string;
|
|
61
|
+
'aria-required'?: boolean;
|
|
62
|
+
}) {
|
|
63
|
+
const [open, setOpen] = useState(false);
|
|
64
|
+
const date = parseDate(value);
|
|
65
|
+
const first = parseDate(min ?? '');
|
|
66
|
+
const last = parseDate(max ?? '');
|
|
67
|
+
const outside = [...(first ? [{ before: first }] : []), ...(last ? [{ after: last }] : [])];
|
|
68
|
+
return (
|
|
69
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
70
|
+
<PopoverTrigger
|
|
71
|
+
render={
|
|
72
|
+
<Button
|
|
73
|
+
id={id}
|
|
74
|
+
variant="outline"
|
|
75
|
+
size={size}
|
|
76
|
+
disabled={disabled}
|
|
77
|
+
aria-required={required}
|
|
78
|
+
className={cn(
|
|
79
|
+
'border-input aria-expanded:border-ring-strong w-full justify-start px-2.5 text-body-13 has-data-[icon=inline-start]:pl-3',
|
|
80
|
+
!date && 'text-muted-foreground',
|
|
81
|
+
className,
|
|
82
|
+
)}
|
|
83
|
+
/>
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
<CalendarIcon data-icon="inline-start" className="text-muted-foreground" />
|
|
87
|
+
{date ? show.format(date) : placeholder}
|
|
88
|
+
</PopoverTrigger>
|
|
89
|
+
<PopoverContent className="w-auto gap-0 p-0" align="start">
|
|
90
|
+
<Calendar
|
|
91
|
+
mode="single"
|
|
92
|
+
captionLayout="dropdown"
|
|
93
|
+
startMonth={FIRST}
|
|
94
|
+
endMonth={LAST}
|
|
95
|
+
selected={date}
|
|
96
|
+
defaultMonth={date ?? first}
|
|
97
|
+
disabled={outside.length ? outside : undefined}
|
|
98
|
+
onSelect={(d) => {
|
|
99
|
+
onChange(d ? toDateValue(d) : '');
|
|
100
|
+
setOpen(false);
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
{clearable && date && (
|
|
104
|
+
<div className="border-t p-2">
|
|
105
|
+
<Button
|
|
106
|
+
variant="secondary"
|
|
107
|
+
size="sm"
|
|
108
|
+
className="w-full"
|
|
109
|
+
onClick={() => {
|
|
110
|
+
onChange('');
|
|
111
|
+
setOpen(false);
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
<TrashIcon data-icon="inline-start" data-danger />
|
|
115
|
+
Limpar
|
|
116
|
+
</Button>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</PopoverContent>
|
|
120
|
+
</Popover>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Data e hora: o Date picker e o Time picker ao lado. O valor é o instante em ISO (ou null). */
|
|
125
|
+
export function DateTimePicker({
|
|
126
|
+
id,
|
|
127
|
+
value,
|
|
128
|
+
onChange,
|
|
129
|
+
disabled,
|
|
130
|
+
'aria-required': required,
|
|
131
|
+
}: {
|
|
132
|
+
id?: string;
|
|
133
|
+
value: string | null;
|
|
134
|
+
onChange: (value: string | null) => void;
|
|
135
|
+
disabled?: boolean;
|
|
136
|
+
'aria-required'?: boolean;
|
|
137
|
+
}) {
|
|
138
|
+
const at = value ? new Date(value) : null;
|
|
139
|
+
const day = at ? toDateValue(at) : '';
|
|
140
|
+
const time = at
|
|
141
|
+
? `${String(at.getHours()).padStart(2, '0')}:${String(at.getMinutes()).padStart(2, '0')}`
|
|
142
|
+
: '';
|
|
143
|
+
function emit(nextDay: string, nextTime: string) {
|
|
144
|
+
const d = parseDate(nextDay);
|
|
145
|
+
if (!d) return onChange(null);
|
|
146
|
+
const [h, m] = (nextTime || '00:00').split(':').map(Number);
|
|
147
|
+
d.setHours(h ?? 0, m ?? 0, 0, 0);
|
|
148
|
+
onChange(d.toISOString());
|
|
149
|
+
}
|
|
150
|
+
return (
|
|
151
|
+
<div className="flex flex-wrap gap-2">
|
|
152
|
+
<DatePicker
|
|
153
|
+
id={id}
|
|
154
|
+
value={day}
|
|
155
|
+
disabled={disabled}
|
|
156
|
+
aria-required={required}
|
|
157
|
+
onChange={(v) => emit(v, time)}
|
|
158
|
+
/>
|
|
159
|
+
<TimePicker
|
|
160
|
+
aria-label="Hora"
|
|
161
|
+
className="shrink-0"
|
|
162
|
+
disabled={disabled || !day}
|
|
163
|
+
value={time}
|
|
164
|
+
onChange={(t) => emit(day, t)}
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Período (D-309): atalhos à esquerda, como Hoje, Esta semana e Este mês, dois meses para escolher
|
|
171
|
+
// à mão e, se quiser, a comparação com o período anterior ou o mesmo período do ano passado. É o
|
|
172
|
+
// filtro de data dos painéis e relatórios. Só aplica ao clicar em Aplicar.
|
|
173
|
+
|
|
174
|
+
export type DateRange = { from: string; to: string };
|
|
175
|
+
export type CompareMode = 'previous' | 'year';
|
|
176
|
+
|
|
177
|
+
const dayOf = (d: Date, n = 0) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
|
|
178
|
+
|
|
179
|
+
export const RANGE_PRESETS: {
|
|
180
|
+
key: string;
|
|
181
|
+
label: string;
|
|
182
|
+
range: (today: Date) => [Date, Date];
|
|
183
|
+
}[] = [
|
|
184
|
+
{ key: 'today', label: 'Hoje', range: (t) => [t, t] },
|
|
185
|
+
{ key: 'yesterday', label: 'Ontem', range: (t) => [dayOf(t, -1), dayOf(t, -1)] },
|
|
186
|
+
{ key: 'last7', label: 'Últimos 7 dias', range: (t) => [dayOf(t, -6), t] },
|
|
187
|
+
{ key: 'last30', label: 'Últimos 30 dias', range: (t) => [dayOf(t, -29), t] },
|
|
188
|
+
{ key: 'week', label: 'Esta semana', range: (t) => [dayOf(t, -((t.getDay() + 6) % 7)), t] },
|
|
189
|
+
{
|
|
190
|
+
key: 'month',
|
|
191
|
+
label: 'Este mês',
|
|
192
|
+
range: (t) => [new Date(t.getFullYear(), t.getMonth(), 1), t],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
key: 'lastMonth',
|
|
196
|
+
label: 'Mês passado',
|
|
197
|
+
range: (t) => [
|
|
198
|
+
new Date(t.getFullYear(), t.getMonth() - 1, 1),
|
|
199
|
+
new Date(t.getFullYear(), t.getMonth(), 0),
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
{ key: 'last90', label: 'Últimos 90 dias', range: (t) => [dayOf(t, -89), t] },
|
|
203
|
+
{ key: 'last180', label: 'Últimos 6 meses', range: (t) => [dayOf(t, -179), t] },
|
|
204
|
+
{
|
|
205
|
+
key: 'last12m',
|
|
206
|
+
label: 'Últimos 12 meses',
|
|
207
|
+
range: (t) => [new Date(t.getFullYear() - 1, t.getMonth(), t.getDate() + 1), t],
|
|
208
|
+
},
|
|
209
|
+
{ key: 'year', label: 'Este ano', range: (t) => [new Date(t.getFullYear(), 0, 1), t] },
|
|
210
|
+
// D-705: desde o começo dos dados, 2020.
|
|
211
|
+
{ key: 'all', label: 'Todo o período', range: (t) => [new Date(2020, 0, 1), t] },
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
/** Datas de um atalho, como "last30", para o estado inicial do período. */
|
|
215
|
+
export function presetRange(key: string, today = new Date()): DateRange {
|
|
216
|
+
const p = RANGE_PRESETS.find((x) => x.key === key) ?? RANGE_PRESETS[3]!;
|
|
217
|
+
const [a, b] = p.range(dayOf(today));
|
|
218
|
+
return { from: toDateValue(a), to: toDateValue(b) };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** O atalho que bate com as datas, ou undefined quando o período foi escolhido à mão. */
|
|
222
|
+
export function presetKey(r: DateRange, today = new Date()): string | undefined {
|
|
223
|
+
return presetOf(r, dayOf(today))?.key;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Período de comparação: o anterior, com o mesmo número de dias, ou o mesmo do ano passado. */
|
|
227
|
+
export function compareRange(range: DateRange, mode: CompareMode): DateRange | null {
|
|
228
|
+
const from = parseDate(range.from);
|
|
229
|
+
const to = parseDate(range.to);
|
|
230
|
+
if (!from || !to) return null;
|
|
231
|
+
if (mode === 'year') {
|
|
232
|
+
const back = (d: Date) => new Date(d.getFullYear() - 1, d.getMonth(), d.getDate());
|
|
233
|
+
return { from: toDateValue(back(from)), to: toDateValue(back(to)) };
|
|
234
|
+
}
|
|
235
|
+
const days = Math.round((to.getTime() - from.getTime()) / 86_400_000) + 1;
|
|
236
|
+
return { from: toDateValue(dayOf(from, -days)), to: toDateValue(dayOf(from, -1)) };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Datas curtas, D-649: "5 de nov. de 2026", "1–5 de out. de 2026" no mesmo mês e
|
|
240
|
+
// "22 de out. – 3 de nov. de 2026" entre meses. O ano só aparece uma vez, no fim, quando é o mesmo.
|
|
241
|
+
const MONTHS = [
|
|
242
|
+
'jan.',
|
|
243
|
+
'fev.',
|
|
244
|
+
'mar.',
|
|
245
|
+
'abr.',
|
|
246
|
+
'mai.',
|
|
247
|
+
'jun.',
|
|
248
|
+
'jul.',
|
|
249
|
+
'ago.',
|
|
250
|
+
'set.',
|
|
251
|
+
'out.',
|
|
252
|
+
'nov.',
|
|
253
|
+
'dez.',
|
|
254
|
+
];
|
|
255
|
+
function rangeText(r: DateRange | null): string {
|
|
256
|
+
const a = r ? parseDate(r.from) : undefined;
|
|
257
|
+
const b = r ? parseDate(r.to) : undefined;
|
|
258
|
+
if (!a || !b) return '';
|
|
259
|
+
const dm = (d: Date) => `${d.getDate()} de ${MONTHS[d.getMonth()]}`;
|
|
260
|
+
const y = (d: Date) => ` de ${d.getFullYear()}`;
|
|
261
|
+
if (a.getTime() === b.getTime()) return dm(a) + y(a);
|
|
262
|
+
if (a.getFullYear() !== b.getFullYear()) return `${dm(a)}${y(a)} – ${dm(b)}${y(b)}`;
|
|
263
|
+
if (a.getMonth() === b.getMonth())
|
|
264
|
+
return `${a.getDate()}–${b.getDate()} de ${MONTHS[a.getMonth()]}${y(b)}`;
|
|
265
|
+
return `${dm(a)} – ${dm(b)}${y(b)}`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function presetOf(r: DateRange, today: Date) {
|
|
269
|
+
return RANGE_PRESETS.find((p) => {
|
|
270
|
+
const [a, b] = p.range(today);
|
|
271
|
+
return toDateValue(a) === r.from && toDateValue(b) === r.to;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const COMPARE_OPTIONS: { value: CompareMode | 'none'; label: string }[] = [
|
|
276
|
+
{ value: 'none', label: 'Sem comparação' },
|
|
277
|
+
{ value: 'previous', label: 'Período anterior' },
|
|
278
|
+
{ value: 'year', label: 'Ano anterior' },
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
// Período, D-649: o botão mostra o nome do atalho, como "Hoje" ou "Últimos 90 dias", e as datas
|
|
282
|
+
// curtas quando o período é escolhido à mão. Com `onCompareChange`, um segundo botão ao lado, ligado
|
|
283
|
+
// ao primeiro, mostra as datas da comparação e troca entre Sem comparação, Período anterior e Ano
|
|
284
|
+
// anterior. Os dois têm a setinha para baixo.
|
|
285
|
+
export function DateRangePicker({
|
|
286
|
+
value,
|
|
287
|
+
onChange,
|
|
288
|
+
compare = null,
|
|
289
|
+
onCompareChange,
|
|
290
|
+
disabled,
|
|
291
|
+
size = 'default',
|
|
292
|
+
presets,
|
|
293
|
+
custom = true,
|
|
294
|
+
className,
|
|
295
|
+
}: {
|
|
296
|
+
value: DateRange;
|
|
297
|
+
onChange: (value: DateRange) => void;
|
|
298
|
+
/** Só estes atalhos, pelas chaves, como ['last7', 'last30', 'all'], D-705. */
|
|
299
|
+
presets?: string[];
|
|
300
|
+
/** Com false, sem o calendário: só os atalhos, para telas de período fixo. */
|
|
301
|
+
custom?: boolean;
|
|
302
|
+
/** Altura dos botões, igual à dos controles ao lado (D-175): sm 32, default 36, lg 40. */
|
|
303
|
+
size?: 'sm' | 'default' | 'lg';
|
|
304
|
+
/** Comparação ligada, ou null. Sem `onCompareChange`, o botão da comparação não aparece. */
|
|
305
|
+
compare?: CompareMode | null;
|
|
306
|
+
onCompareChange?: (mode: CompareMode | null) => void;
|
|
307
|
+
disabled?: boolean;
|
|
308
|
+
className?: string;
|
|
309
|
+
}) {
|
|
310
|
+
const [open, setOpen] = useState(false);
|
|
311
|
+
const [draft, setDraft] = useState<DateRange>(value);
|
|
312
|
+
const today = dayOf(new Date());
|
|
313
|
+
const versus = compare ? compareRange(value, compare) : null;
|
|
314
|
+
const preset = presetOf(value, today);
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<div className={cn('flex flex-wrap items-center gap-2', className)}>
|
|
318
|
+
<Popover
|
|
319
|
+
open={open}
|
|
320
|
+
onOpenChange={(o) => {
|
|
321
|
+
setOpen(o);
|
|
322
|
+
if (o) setDraft(value);
|
|
323
|
+
}}
|
|
324
|
+
>
|
|
325
|
+
<PopoverTrigger
|
|
326
|
+
render={
|
|
327
|
+
<Button variant="outline" disabled={disabled} size={size} className="justify-start" />
|
|
328
|
+
}
|
|
329
|
+
>
|
|
330
|
+
<CalendarIcon data-icon="inline-start" className="text-muted-foreground" />
|
|
331
|
+
{preset?.label ?? rangeText(value)}
|
|
332
|
+
<ChevronDownIcon data-icon="inline-end" className="text-muted-foreground" />
|
|
333
|
+
</PopoverTrigger>
|
|
334
|
+
<PopoverContent align="start" className="w-auto max-w-[calc(100vw-2rem)] gap-0 p-0">
|
|
335
|
+
<div className="flex flex-col sm:flex-row">
|
|
336
|
+
<ul
|
|
337
|
+
aria-label="Atalhos"
|
|
338
|
+
className={cn(
|
|
339
|
+
'flex gap-1 overflow-x-auto p-2 sm:w-40 sm:flex-col',
|
|
340
|
+
custom && 'border-b sm:border-r sm:border-b-0',
|
|
341
|
+
)}
|
|
342
|
+
>
|
|
343
|
+
{RANGE_PRESETS.filter((p) => !presets || presets.includes(p.key)).map((p) => (
|
|
344
|
+
<li key={p.key}>
|
|
345
|
+
<button
|
|
346
|
+
type="button"
|
|
347
|
+
aria-pressed={presetOf(draft, today)?.key === p.key}
|
|
348
|
+
onClick={() => {
|
|
349
|
+
const [a, b] = p.range(today);
|
|
350
|
+
const next = { from: toDateValue(a), to: toDateValue(b) };
|
|
351
|
+
setDraft(next);
|
|
352
|
+
// Sem calendário, o atalho já vale.
|
|
353
|
+
if (!custom) {
|
|
354
|
+
onChange(next);
|
|
355
|
+
setOpen(false);
|
|
356
|
+
}
|
|
357
|
+
}}
|
|
358
|
+
className="h-control-sm w-full rounded-control px-2 text-left text-body-13 whitespace-nowrap outline-none hover:bg-hover focus-visible:focus-ring aria-pressed:bg-selected aria-pressed:text-body-13-semibold"
|
|
359
|
+
>
|
|
360
|
+
{p.label}
|
|
361
|
+
</button>
|
|
362
|
+
</li>
|
|
363
|
+
))}
|
|
364
|
+
</ul>
|
|
365
|
+
{custom && (
|
|
366
|
+
<div className="grid">
|
|
367
|
+
<Calendar
|
|
368
|
+
mode="range"
|
|
369
|
+
numberOfMonths={2}
|
|
370
|
+
showOutsideDays={false}
|
|
371
|
+
defaultMonth={dayOf(parseDate(draft.to) ?? today, -31)}
|
|
372
|
+
selected={{ from: parseDate(draft.from), to: parseDate(draft.to) }}
|
|
373
|
+
onSelect={(r) => {
|
|
374
|
+
if (r?.from)
|
|
375
|
+
setDraft({ from: toDateValue(r.from), to: toDateValue(r.to ?? r.from) });
|
|
376
|
+
}}
|
|
377
|
+
disabled={{ after: today }}
|
|
378
|
+
/>
|
|
379
|
+
<div className="flex flex-wrap items-center gap-2 border-t p-3">
|
|
380
|
+
<span className="text-body-13 text-muted-foreground">
|
|
381
|
+
{presetOf(draft, today)?.label ?? 'Personalizado'} · {rangeText(draft)}
|
|
382
|
+
</span>
|
|
383
|
+
<div className="ml-auto flex gap-2">
|
|
384
|
+
<Button variant="secondary" size="sm" onClick={() => setOpen(false)}>
|
|
385
|
+
Cancelar
|
|
386
|
+
</Button>
|
|
387
|
+
<Button
|
|
388
|
+
size="sm"
|
|
389
|
+
onClick={() => {
|
|
390
|
+
onChange(draft);
|
|
391
|
+
setOpen(false);
|
|
392
|
+
}}
|
|
393
|
+
>
|
|
394
|
+
Aplicar
|
|
395
|
+
</Button>
|
|
396
|
+
</div>
|
|
397
|
+
</div>
|
|
398
|
+
</div>
|
|
399
|
+
)}
|
|
400
|
+
</div>
|
|
401
|
+
</PopoverContent>
|
|
402
|
+
</Popover>
|
|
403
|
+
{onCompareChange && (
|
|
404
|
+
<DropdownMenu>
|
|
405
|
+
<DropdownMenuTrigger
|
|
406
|
+
render={
|
|
407
|
+
<Button
|
|
408
|
+
variant="outline"
|
|
409
|
+
disabled={disabled}
|
|
410
|
+
size={size}
|
|
411
|
+
aria-label="Período de comparação"
|
|
412
|
+
/>
|
|
413
|
+
}
|
|
414
|
+
>
|
|
415
|
+
<CalendarIcon data-icon="inline-start" className="text-muted-foreground" />
|
|
416
|
+
{versus ? rangeText(versus) : 'Sem comparação'}
|
|
417
|
+
<ChevronDownIcon data-icon="inline-end" className="text-muted-foreground" />
|
|
418
|
+
</DropdownMenuTrigger>
|
|
419
|
+
<DropdownMenuContent align="start" className="min-w-52">
|
|
420
|
+
<DropdownMenuRadioGroup
|
|
421
|
+
value={compare ?? 'none'}
|
|
422
|
+
onValueChange={(v) => onCompareChange(v === 'none' ? null : (v as CompareMode))}
|
|
423
|
+
>
|
|
424
|
+
{COMPARE_OPTIONS.map((o) => (
|
|
425
|
+
<DropdownMenuRadioItem key={o.value} value={o.value}>
|
|
426
|
+
{o.label}
|
|
427
|
+
</DropdownMenuRadioItem>
|
|
428
|
+
))}
|
|
429
|
+
</DropdownMenuRadioGroup>
|
|
430
|
+
</DropdownMenuContent>
|
|
431
|
+
</DropdownMenu>
|
|
432
|
+
)}
|
|
433
|
+
</div>
|
|
434
|
+
);
|
|
435
|
+
}
|