@vowt-tech/ui 0.0.0-stage → 0.177.1
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,267 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ChevronDownIcon, ChevronUpIcon, ChevronsUpDownIcon, PencilIcon } from 'lucide-react';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
import { Input } from './input';
|
|
7
|
+
|
|
8
|
+
// Variações (D-309), que podem se juntar: `striped` alterna o fundo das linhas, `lines` põe
|
|
9
|
+
// divisória entre as colunas, `borderless` tira as linhas entre as linhas e `compact` aperta a
|
|
10
|
+
// altura, para listas longas. Sem cabeçalho é só não usar o TableHeader. Tabela mais larga que a
|
|
11
|
+
// tela rola de lado, com a borda esmaecida para mostrar que há mais colunas.
|
|
12
|
+
function Table({
|
|
13
|
+
className,
|
|
14
|
+
striped,
|
|
15
|
+
lines,
|
|
16
|
+
borderless,
|
|
17
|
+
compact,
|
|
18
|
+
...props
|
|
19
|
+
}: React.ComponentProps<'table'> & {
|
|
20
|
+
striped?: boolean;
|
|
21
|
+
lines?: boolean;
|
|
22
|
+
borderless?: boolean;
|
|
23
|
+
compact?: boolean;
|
|
24
|
+
}) {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
data-slot="table-container"
|
|
28
|
+
className="relative w-full overflow-x-auto scroll-fade-x [--scroll-fade-size:--spacing(6)] not-supports-[animation-timeline:scroll()]:[--scroll-fade-size:0px]"
|
|
29
|
+
>
|
|
30
|
+
<table
|
|
31
|
+
data-slot="table"
|
|
32
|
+
data-striped={striped || undefined}
|
|
33
|
+
data-lines={lines || undefined}
|
|
34
|
+
data-borderless={borderless || undefined}
|
|
35
|
+
data-compact={compact || undefined}
|
|
36
|
+
className={cn('group/table w-full caption-bottom text-body-13 tabular-nums', className)}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function TableHeader({ className, ...props }: React.ComponentProps<'thead'>) {
|
|
44
|
+
return <thead data-slot="table-header" className={cn('[&_tr]:border-b', className)} {...props} />;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function TableBody({ className, ...props }: React.ComponentProps<'tbody'>) {
|
|
48
|
+
return (
|
|
49
|
+
<tbody
|
|
50
|
+
data-slot="table-body"
|
|
51
|
+
className={cn('[&_tr:last-child]:border-0', className)}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function TableFooter({ className, ...props }: React.ComponentProps<'tfoot'>) {
|
|
58
|
+
return (
|
|
59
|
+
<tfoot
|
|
60
|
+
data-slot="table-footer"
|
|
61
|
+
className={cn('border-t bg-muted/50 font-medium [&>tr]:last:border-b-0', className)}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function TableRow({ className, ...props }: React.ComponentProps<'tr'>) {
|
|
68
|
+
return (
|
|
69
|
+
<tr
|
|
70
|
+
data-slot="table-row"
|
|
71
|
+
className={cn(
|
|
72
|
+
// Linha (D-152): fundo de hover ao passar o mouse e de selecionado quando marcada.
|
|
73
|
+
'border-b transition-colors hover:bg-hover has-aria-expanded:bg-hover data-[state=selected]:bg-selected',
|
|
74
|
+
// Zebra: no escuro, o cinza suave a 50% sumia no cartão; vira o texto a 4%, abaixo do hover.
|
|
75
|
+
'group-data-borderless/table:border-0 group-data-striped/table:in-data-[slot=table-body]:even:bg-muted/50 dark:group-data-striped/table:in-data-[slot=table-body]:even:bg-foreground/4',
|
|
76
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
{...props}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// D-829: coluna de número ou de dinheiro alinha à direita, no título e na célula, com algarismos de
|
|
84
|
+
// mesma largura, para o olho comparar as casas de cima a baixo. `numeric` no TableHead e no
|
|
85
|
+
// TableCell; no Data table, `numeric` na coluna.
|
|
86
|
+
const NUMERIC = 'text-right tabular-nums';
|
|
87
|
+
|
|
88
|
+
function TableHead({
|
|
89
|
+
className,
|
|
90
|
+
numeric,
|
|
91
|
+
...props
|
|
92
|
+
}: React.ComponentProps<'th'> & {
|
|
93
|
+
/** Coluna de número ou dinheiro: título à direita, como as células. */
|
|
94
|
+
numeric?: boolean;
|
|
95
|
+
}) {
|
|
96
|
+
return (
|
|
97
|
+
<th
|
|
98
|
+
data-slot="table-head"
|
|
99
|
+
data-numeric={numeric || undefined}
|
|
100
|
+
className={cn(
|
|
101
|
+
'px-3 py-2 text-left align-middle text-body-12-medium whitespace-nowrap text-label-foreground group-data-compact/table:py-1.5 group-data-lines/table:border-r group-data-lines/table:last:border-r-0 [&:has([role=checkbox])]:pr-0',
|
|
102
|
+
numeric && NUMERIC,
|
|
103
|
+
className,
|
|
104
|
+
)}
|
|
105
|
+
{...props}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function TableCell({
|
|
111
|
+
className,
|
|
112
|
+
numeric,
|
|
113
|
+
...props
|
|
114
|
+
}: React.ComponentProps<'td'> & {
|
|
115
|
+
/** Número ou dinheiro: à direita, com algarismos de mesma largura. */
|
|
116
|
+
numeric?: boolean;
|
|
117
|
+
}) {
|
|
118
|
+
return (
|
|
119
|
+
<td
|
|
120
|
+
data-slot="table-cell"
|
|
121
|
+
data-numeric={numeric || undefined}
|
|
122
|
+
className={cn(
|
|
123
|
+
'px-3 py-2 align-middle whitespace-nowrap group-data-compact/table:py-1.5 group-data-lines/table:border-r group-data-lines/table:last:border-r-0 [&:has([role=checkbox])]:pr-0',
|
|
124
|
+
numeric && NUMERIC,
|
|
125
|
+
className,
|
|
126
|
+
)}
|
|
127
|
+
{...props}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Célula que edita no lugar (D-309), para corrigir um dado sem abrir outra tela: o lápis aparece
|
|
133
|
+
// ao passar o mouse; clicar troca pelo campo, Enter ou sair do campo salva, Esc desiste. A edição é
|
|
134
|
+
// discreta, igual à do PropertyRow em description-list.tsx: o campo fica na mesma caixa da leitura, sem
|
|
135
|
+
// borda, fundo ou anel próprios, e só o contorno fino avisa que está editando. A altura não muda
|
|
136
|
+
// entre ler, passar o mouse e editar. Mudou aqui, mudar lá também.
|
|
137
|
+
const INLINE_EDIT =
|
|
138
|
+
'ring-1 ring-ring-strong [&_:is(input,[data-slot=select-trigger])]:outline-none! [&_:is(input,[data-slot=select-trigger])]:h-5! [&_:is(input,[data-slot=select-trigger])]:w-full! [&_:is(input,[data-slot=select-trigger])]:rounded-none! [&_:is(input,[data-slot=select-trigger])]:border-0! [&_:is(input,[data-slot=select-trigger])]:bg-transparent! [&_:is(input,[data-slot=select-trigger])]:p-0! [&_:is(input,[data-slot=select-trigger])]:text-body-13! [&_:is(input,[data-slot=select-trigger])]:shadow-none! [&_:is(input,[data-slot=select-trigger])]:ring-0!';
|
|
139
|
+
const EDIT_BOX = '-mx-2 flex h-7 w-[calc(100%+1rem)] items-center gap-2 rounded-control px-2';
|
|
140
|
+
function TableCellEditable({
|
|
141
|
+
value,
|
|
142
|
+
onSave,
|
|
143
|
+
label,
|
|
144
|
+
className,
|
|
145
|
+
inputClassName,
|
|
146
|
+
}: {
|
|
147
|
+
value: string;
|
|
148
|
+
onSave: (value: string) => void;
|
|
149
|
+
/** Nome do dado para o leitor de tela, como "Preço da Camiseta básica". */
|
|
150
|
+
label: string;
|
|
151
|
+
className?: string;
|
|
152
|
+
inputClassName?: string;
|
|
153
|
+
}) {
|
|
154
|
+
const [editing, setEditing] = React.useState(false);
|
|
155
|
+
const [draft, setDraft] = React.useState(value);
|
|
156
|
+
const done = (save: boolean) => {
|
|
157
|
+
if (save && draft !== value) onSave(draft);
|
|
158
|
+
else setDraft(value);
|
|
159
|
+
setEditing(false);
|
|
160
|
+
};
|
|
161
|
+
return (
|
|
162
|
+
<TableCell
|
|
163
|
+
data-slot="table-cell-editable"
|
|
164
|
+
className={cn('py-3 group-data-compact/table:py-1.5', className)}
|
|
165
|
+
>
|
|
166
|
+
{editing ? (
|
|
167
|
+
<div data-editing="" className={cn(EDIT_BOX, 'bg-card', INLINE_EDIT)}>
|
|
168
|
+
<Input
|
|
169
|
+
autoFocus
|
|
170
|
+
aria-label={label}
|
|
171
|
+
value={draft}
|
|
172
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
173
|
+
onBlur={() => done(true)}
|
|
174
|
+
onKeyDown={(e) => {
|
|
175
|
+
if (e.key === 'Enter') done(true);
|
|
176
|
+
if (e.key === 'Escape') done(false);
|
|
177
|
+
}}
|
|
178
|
+
className={inputClassName}
|
|
179
|
+
/>
|
|
180
|
+
</div>
|
|
181
|
+
) : (
|
|
182
|
+
<button
|
|
183
|
+
type="button"
|
|
184
|
+
aria-label={`Editar ${label}`}
|
|
185
|
+
onClick={() => {
|
|
186
|
+
setDraft(value);
|
|
187
|
+
setEditing(true);
|
|
188
|
+
}}
|
|
189
|
+
className={cn(
|
|
190
|
+
EDIT_BOX,
|
|
191
|
+
'group/edit text-left outline-none hover:bg-card hover:ring-1 hover:ring-border focus-visible:bg-card focus-visible:ring-ring-strong',
|
|
192
|
+
)}
|
|
193
|
+
>
|
|
194
|
+
<span className="min-w-0 flex-1 truncate">{value}</span>
|
|
195
|
+
<PencilIcon
|
|
196
|
+
aria-hidden
|
|
197
|
+
className="size-icon-sm shrink-0 text-muted-foreground opacity-0 group-hover/edit:opacity-100 group-focus-visible/edit:opacity-100"
|
|
198
|
+
/>
|
|
199
|
+
</button>
|
|
200
|
+
)}
|
|
201
|
+
</TableCell>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function TableCaption({ className, ...props }: React.ComponentProps<'caption'>) {
|
|
206
|
+
return (
|
|
207
|
+
<caption
|
|
208
|
+
data-slot="table-caption"
|
|
209
|
+
className={cn('mt-4 text-body-13 text-muted-foreground', className)}
|
|
210
|
+
{...props}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Cabeçalho que ordena a coluna (D-152). Fica dentro do TableHead; o TableHead recebe aria-sort.
|
|
216
|
+
// Sem ordem, mostra as duas setas; crescente ou decrescente, só a seta da ordem atual.
|
|
217
|
+
export type SortDirection = 'asc' | 'desc' | false;
|
|
218
|
+
|
|
219
|
+
function TableSortButton({
|
|
220
|
+
direction,
|
|
221
|
+
onSort,
|
|
222
|
+
className,
|
|
223
|
+
children,
|
|
224
|
+
...props
|
|
225
|
+
}: Omit<React.ComponentProps<'button'>, 'onClick'> & {
|
|
226
|
+
direction: SortDirection;
|
|
227
|
+
onSort: () => void;
|
|
228
|
+
}) {
|
|
229
|
+
const Icon =
|
|
230
|
+
direction === 'asc'
|
|
231
|
+
? ChevronUpIcon
|
|
232
|
+
: direction === 'desc'
|
|
233
|
+
? ChevronDownIcon
|
|
234
|
+
: ChevronsUpDownIcon;
|
|
235
|
+
return (
|
|
236
|
+
<button
|
|
237
|
+
type="button"
|
|
238
|
+
data-slot="table-sort-button"
|
|
239
|
+
onClick={onSort}
|
|
240
|
+
className={cn(
|
|
241
|
+
'group/sort inline-flex h-5 items-center gap-1 rounded-small outline-none hover:text-foreground focus-visible:focus-ring in-[.text-right]:flex-row-reverse',
|
|
242
|
+
direction && 'text-foreground',
|
|
243
|
+
className,
|
|
244
|
+
)}
|
|
245
|
+
{...props}
|
|
246
|
+
>
|
|
247
|
+
{children}
|
|
248
|
+
<Icon
|
|
249
|
+
aria-hidden
|
|
250
|
+
className={cn('size-icon-sm', !direction && 'opacity-50 group-hover/sort:opacity-100')}
|
|
251
|
+
/>
|
|
252
|
+
</button>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
Table,
|
|
258
|
+
TableHeader,
|
|
259
|
+
TableBody,
|
|
260
|
+
TableFooter,
|
|
261
|
+
TableHead,
|
|
262
|
+
TableRow,
|
|
263
|
+
TableCell,
|
|
264
|
+
TableCaption,
|
|
265
|
+
TableSortButton,
|
|
266
|
+
TableCellEditable,
|
|
267
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type * as React from 'react';
|
|
4
|
+
import { Tabs as TabsPrimitive } from '@base-ui/react/tabs';
|
|
5
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
6
|
+
import { cn } from '../lib/utils';
|
|
7
|
+
|
|
8
|
+
function Tabs({ className, orientation = 'horizontal', ...props }: TabsPrimitive.Root.Props) {
|
|
9
|
+
return (
|
|
10
|
+
<TabsPrimitive.Root
|
|
11
|
+
data-slot="tabs"
|
|
12
|
+
data-orientation={orientation}
|
|
13
|
+
className={cn('group/tabs flex max-w-full min-w-0 gap-2 data-horizontal:flex-col', className)}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Contêiner de 36, ou 32 no pequeno, com 4 de respiro em volta da aba, em cima, embaixo e dos
|
|
20
|
+
// lados, como o Toggle group: aba de 28, ou 24 no pequeno. A variante de linha fica com 36.
|
|
21
|
+
// Quando as abas não cabem, como no celular, a fileira rola de lado e a borda que esconde aba
|
|
22
|
+
// esmaece, para mostrar que há mais. O esmaecido some sozinho quando tudo cabe.
|
|
23
|
+
const tabsListVariants = cva(
|
|
24
|
+
'group/tabs-list scroll-hairline scroll-fade-x [--scroll-fade-size:--spacing(6)] not-supports-[animation-timeline:scroll()]:[--scroll-fade-size:0px] inline-flex w-fit max-w-full items-center justify-start overflow-x-auto overflow-y-hidden rounded-control p-1 text-muted-foreground group-data-horizontal/tabs:h-control-sm group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none',
|
|
25
|
+
{
|
|
26
|
+
variants: {
|
|
27
|
+
variant: {
|
|
28
|
+
// Trilho igual ao do Segmented control: 4 de respiro e o item 8 abaixo do controle, D-689.
|
|
29
|
+
default: 'bg-muted p-1 group-data-horizontal/tabs:h-control',
|
|
30
|
+
line: 'gap-1 bg-transparent group-data-horizontal/tabs:h-control',
|
|
31
|
+
// D-695: visões de uma lista, num cartão na linha toda, acima do cartão da tabela.
|
|
32
|
+
card: 'flex w-full gap-1 border bg-card p-1.5 rounded-card group-data-horizontal/tabs:h-control-lg',
|
|
33
|
+
// D-783: pílulas soltas, como os filtros do WhatsApp; a escolhida em cinza, D-786.
|
|
34
|
+
pill: 'gap-1.5 rounded-none bg-transparent p-0 group-data-horizontal/tabs:h-control-xs',
|
|
35
|
+
},
|
|
36
|
+
size: {
|
|
37
|
+
default: '',
|
|
38
|
+
sm: '',
|
|
39
|
+
lg: '',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
compoundVariants: [
|
|
43
|
+
{ variant: 'default', size: 'sm', class: 'group-data-horizontal/tabs:h-control-sm' },
|
|
44
|
+
// D-858: grande, trilho de 40 e aba de 32.
|
|
45
|
+
{ variant: 'default', size: 'lg', class: 'group-data-horizontal/tabs:h-control-lg' },
|
|
46
|
+
],
|
|
47
|
+
defaultVariants: {
|
|
48
|
+
variant: 'default',
|
|
49
|
+
size: 'default',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
function TabsList({
|
|
55
|
+
className,
|
|
56
|
+
variant = 'default',
|
|
57
|
+
size = 'default',
|
|
58
|
+
...props
|
|
59
|
+
}: TabsPrimitive.List.Props & VariantProps<typeof tabsListVariants>) {
|
|
60
|
+
return (
|
|
61
|
+
<TabsPrimitive.List
|
|
62
|
+
data-slot="tabs-list"
|
|
63
|
+
data-variant={variant}
|
|
64
|
+
data-size={size}
|
|
65
|
+
className={cn(tabsListVariants({ variant, size }), className)}
|
|
66
|
+
{...props}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {
|
|
72
|
+
return (
|
|
73
|
+
<TabsPrimitive.Tab
|
|
74
|
+
data-slot="tabs-trigger"
|
|
75
|
+
className={cn(
|
|
76
|
+
"relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-item border border-transparent px-2.5 py-0.5 text-body-13-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring-strong focus-visible:focus-ring focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-raised group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-icon-sm",
|
|
77
|
+
'group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent',
|
|
78
|
+
// No escuro, a aba escolhida fica um tom acima do trilho; o cartão é mais escuro que ele.
|
|
79
|
+
'data-active:bg-card data-active:text-foreground dark:data-active:border-input dark:data-active:bg-surface-strong dark:data-active:text-foreground',
|
|
80
|
+
// D-789: com o número no fim, o respiro da direita diminui para a bolinha do número
|
|
81
|
+
// acompanhar a curva do canto da aba, a mesma distância em cima, embaixo e do lado.
|
|
82
|
+
'has-[>[data-slot=tabs-count]:last-child]:pr-1.25!',
|
|
83
|
+
'group-data-[variant=pill]/tabs-list:h-control-xs group-data-[variant=pill]/tabs-list:flex-none group-data-[variant=pill]/tabs-list:rounded-full group-data-[variant=pill]/tabs-list:border-border group-data-[variant=pill]/tabs-list:bg-card group-data-[variant=pill]/tabs-list:px-3 group-data-[variant=pill]/tabs-list:hover:bg-hover group-data-[variant=pill]/tabs-list:data-active:border-transparent group-data-[variant=pill]/tabs-list:data-active:bg-surface-selected group-data-[variant=pill]/tabs-list:data-active:text-foreground',
|
|
84
|
+
'group-data-[variant=card]/tabs-list:flex-none group-data-[variant=card]/tabs-list:h-control-xs group-data-[variant=card]/tabs-list:rounded-control group-data-[variant=card]/tabs-list:px-3 group-data-[variant=card]/tabs-list:data-active:bg-muted dark:group-data-[variant=card]/tabs-list:data-active:bg-surface-strong',
|
|
85
|
+
'group-data-[variant=default]/tabs-list:h-[calc(var(--scale-control)-0.5rem)] group-data-[size=sm]/tabs-list:group-data-[variant=default]/tabs-list:h-[calc(var(--scale-control-sm)-0.5rem)] group-data-[size=sm]/tabs-list:group-data-[variant=default]/tabs-list:px-2.5 group-data-[size=sm]/tabs-list:group-data-[variant=default]/tabs-list:text-body-12-medium group-data-[size=lg]/tabs-list:group-data-[variant=default]/tabs-list:h-[calc(var(--scale-control-lg)-0.5rem)] group-data-[size=lg]/tabs-list:group-data-[variant=default]/tabs-list:px-3.5 group-data-[size=lg]/tabs-list:group-data-[variant=default]/tabs-list:text-body-14-medium',
|
|
86
|
+
'after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100',
|
|
87
|
+
className,
|
|
88
|
+
)}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Contagem ao lado do nome da aba, como "Pagos 180": abas que filtram uma lista (D-309).
|
|
95
|
+
function TabsCount({ className, ...props }: React.ComponentProps<'span'>) {
|
|
96
|
+
return (
|
|
97
|
+
<span
|
|
98
|
+
data-slot="tabs-count"
|
|
99
|
+
className={cn(
|
|
100
|
+
// D-696: número pequeno, com contorno, que aparece no cinza da aba escolhida e no branco.
|
|
101
|
+
'rounded-full border bg-card px-1.5 text-body-10-semibold leading-4 text-muted-foreground tabular-nums group-data-[variant=default]/tabs-list:bg-background',
|
|
102
|
+
className,
|
|
103
|
+
)}
|
|
104
|
+
{...props}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {
|
|
110
|
+
return (
|
|
111
|
+
<TabsPrimitive.Panel
|
|
112
|
+
data-slot="tabs-content"
|
|
113
|
+
className={cn('flex-1 text-body-13 outline-none', className)}
|
|
114
|
+
{...props}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// D-698: atalho das Tabs. Escolha de uma opção entre poucas, sempre visíveis, como "Funil · Lista"
|
|
120
|
+
// ou "Dia · Semana · Mês", sem conteúdo embaixo. O desenho é o das Tabs, trilho ou cartão, para as
|
|
121
|
+
// três peças, Tabs, Segmented control e Saved filters, parecerem uma só. Para muitas opções, use o
|
|
122
|
+
// Select.
|
|
123
|
+
|
|
124
|
+
export type SegmentedOption = { value: string; label: React.ReactNode; icon?: React.ReactNode };
|
|
125
|
+
|
|
126
|
+
// Com `iconOnly`, cada opção mostra só o ícone, num quadrado, e o nome fica para o leitor de tela
|
|
127
|
+
// e na dica ao parar o mouse, como o tema Claro, Escuro e Sistema.
|
|
128
|
+
// Com `variant="card"`, o trilho vira o cartão branco das Tabs, para o fundo cinza da página.
|
|
129
|
+
|
|
130
|
+
function SegmentedControl({
|
|
131
|
+
options,
|
|
132
|
+
value,
|
|
133
|
+
onValueChange,
|
|
134
|
+
size = 'default',
|
|
135
|
+
iconOnly = false,
|
|
136
|
+
variant = 'default',
|
|
137
|
+
className,
|
|
138
|
+
'aria-label': ariaLabel,
|
|
139
|
+
}: {
|
|
140
|
+
options: SegmentedOption[];
|
|
141
|
+
value: string;
|
|
142
|
+
onValueChange: (value: string) => void;
|
|
143
|
+
size?: 'sm' | 'default' | 'lg';
|
|
144
|
+
/** Só o ícone de cada opção, num quadrado. */
|
|
145
|
+
iconOnly?: boolean;
|
|
146
|
+
/** `card`: cartão branco com borda, para o fundo da página. */
|
|
147
|
+
variant?: 'default' | 'card';
|
|
148
|
+
className?: string;
|
|
149
|
+
'aria-label': string;
|
|
150
|
+
}) {
|
|
151
|
+
return (
|
|
152
|
+
<Tabs
|
|
153
|
+
data-slot="segmented-control"
|
|
154
|
+
value={value}
|
|
155
|
+
onValueChange={(v) => v !== value && onValueChange(String(v))}
|
|
156
|
+
className={cn('w-fit max-w-full', className)}
|
|
157
|
+
>
|
|
158
|
+
<TabsList
|
|
159
|
+
aria-label={ariaLabel}
|
|
160
|
+
variant={variant === 'card' ? 'card' : 'default'}
|
|
161
|
+
size={size}
|
|
162
|
+
className={cn(variant === 'card' && 'w-fit')}
|
|
163
|
+
>
|
|
164
|
+
{options.map((o) => (
|
|
165
|
+
<TabsTrigger
|
|
166
|
+
key={o.value}
|
|
167
|
+
value={o.value}
|
|
168
|
+
title={iconOnly && typeof o.label === 'string' ? o.label : undefined}
|
|
169
|
+
data-slot="segmented-control-item"
|
|
170
|
+
className={cn(
|
|
171
|
+
'[&_svg]:size-icon-sm',
|
|
172
|
+
iconOnly && 'aspect-square flex-none px-0 group-data-[variant=card]/tabs-list:px-0',
|
|
173
|
+
)}
|
|
174
|
+
>
|
|
175
|
+
{o.icon}
|
|
176
|
+
{iconOnly ? <span className="sr-only">{o.label}</span> : o.label}
|
|
177
|
+
</TabsTrigger>
|
|
178
|
+
))}
|
|
179
|
+
</TabsList>
|
|
180
|
+
</Tabs>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { Tabs, TabsList, TabsTrigger, TabsCount, TabsContent, tabsListVariants, SegmentedControl };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { CheckIcon, PlusIcon, TagIcon } from 'lucide-react';
|
|
4
|
+
import { type ReactElement, type ReactNode, useState } from 'react';
|
|
5
|
+
import { Badge } from './badge';
|
|
6
|
+
import { Button } from './button';
|
|
7
|
+
import { Input } from './input';
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger } from './popover';
|
|
9
|
+
import { cn } from '../lib/utils';
|
|
10
|
+
|
|
11
|
+
// Tag input: a tag, que é um Badge colorido, e o seletor que busca as que existem e cria a nova na
|
|
12
|
+
// hora, sem repetir com outra caixa. As cores são os tons dos avatares e o cinza.
|
|
13
|
+
|
|
14
|
+
export type TagItem = { id: string; name: string; color: string };
|
|
15
|
+
|
|
16
|
+
export const TAG_COLORS = ['gray', '1', '2', '3', '4', '5', '6', '7', '8'] as const;
|
|
17
|
+
|
|
18
|
+
const TONE: Record<string, string> = {
|
|
19
|
+
gray: 'bg-muted text-foreground',
|
|
20
|
+
'1': 'bg-avatar-1 text-avatar-1-foreground',
|
|
21
|
+
'2': 'bg-avatar-2 text-avatar-2-foreground',
|
|
22
|
+
'3': 'bg-avatar-3 text-avatar-3-foreground',
|
|
23
|
+
'4': 'bg-avatar-4 text-avatar-4-foreground',
|
|
24
|
+
'5': 'bg-avatar-5 text-avatar-5-foreground',
|
|
25
|
+
'6': 'bg-avatar-6 text-avatar-6-foreground',
|
|
26
|
+
'7': 'bg-avatar-7 text-avatar-7-foreground',
|
|
27
|
+
'8': 'bg-avatar-8 text-avatar-8-foreground',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function tagTone(color: string): string {
|
|
31
|
+
return TONE[color] ?? TONE.gray ?? '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Tag é um Badge na cor dela; com `onRemove`, ganha o x. */
|
|
35
|
+
export function TagBadge({
|
|
36
|
+
tag,
|
|
37
|
+
onRemove,
|
|
38
|
+
className,
|
|
39
|
+
}: {
|
|
40
|
+
tag: TagItem;
|
|
41
|
+
onRemove?: () => void;
|
|
42
|
+
className?: string;
|
|
43
|
+
}) {
|
|
44
|
+
return (
|
|
45
|
+
<Badge
|
|
46
|
+
data-slot="tag"
|
|
47
|
+
variant="secondary"
|
|
48
|
+
onRemove={onRemove}
|
|
49
|
+
removeLabel={`Tirar a tag ${tag.name}`}
|
|
50
|
+
className={cn('max-w-40', tagTone(tag.color), className)}
|
|
51
|
+
>
|
|
52
|
+
<span className="truncate">{tag.name}</span>
|
|
53
|
+
</Badge>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Até N tags e "+X" para o resto, para lista e cartão. */
|
|
58
|
+
export function TagList({ tags, max = 2 }: { tags: TagItem[]; max?: number }) {
|
|
59
|
+
if (tags.length === 0) return <span className="text-muted-foreground">Sem tags</span>;
|
|
60
|
+
return (
|
|
61
|
+
<span className="flex flex-wrap items-center gap-1">
|
|
62
|
+
{tags.slice(0, max).map((t) => (
|
|
63
|
+
<TagBadge key={t.id} tag={t} />
|
|
64
|
+
))}
|
|
65
|
+
{tags.length > max && (
|
|
66
|
+
<span className="text-muted-foreground text-body-12">+{tags.length - max}</span>
|
|
67
|
+
)}
|
|
68
|
+
</span>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Escolhe tags: busca nas que existem e, se não achar, "Criar …". `onCreate` cria na API e
|
|
74
|
+
* devolve a tag (a API devolve a existente se o nome já estiver em uso com outra caixa).
|
|
75
|
+
*/
|
|
76
|
+
export function TagPicker({
|
|
77
|
+
all,
|
|
78
|
+
value,
|
|
79
|
+
onChange,
|
|
80
|
+
onCreate,
|
|
81
|
+
disabled,
|
|
82
|
+
label = 'Tags',
|
|
83
|
+
trigger = 'button',
|
|
84
|
+
open: openProp,
|
|
85
|
+
onOpenChange,
|
|
86
|
+
triggerElement,
|
|
87
|
+
triggerContent,
|
|
88
|
+
}: {
|
|
89
|
+
/**
|
|
90
|
+
* Gatilho próprio, no lugar dos de `trigger`, como o botão Adicionar tag das ações do painel do
|
|
91
|
+
* contato (D-793). O conteúdo dele vai em `triggerContent`.
|
|
92
|
+
*/
|
|
93
|
+
triggerElement?: ReactElement;
|
|
94
|
+
triggerContent?: ReactNode;
|
|
95
|
+
all: TagItem[];
|
|
96
|
+
value: TagItem[];
|
|
97
|
+
onChange: (tags: TagItem[]) => void;
|
|
98
|
+
onCreate?: (name: string) => Promise<TagItem | null>;
|
|
99
|
+
disabled?: boolean;
|
|
100
|
+
label?: string;
|
|
101
|
+
/**
|
|
102
|
+
* "button": botão "+ Tag" (ficha); "field": campo com as tags dentro (formulário); "icon": só o
|
|
103
|
+
* "+", para o título de uma seção (as tags ficam na própria seção); "add": o mesmo "+", discreto,
|
|
104
|
+
* do tamanho dos outros botões de ícone do painel (D-785).
|
|
105
|
+
*/
|
|
106
|
+
trigger?: 'button' | 'field' | 'icon' | 'add';
|
|
107
|
+
/** Aberto por fora (ex.: o botão "Tag" das ações rápidas de um painel lateral). */
|
|
108
|
+
open?: boolean;
|
|
109
|
+
onOpenChange?: (open: boolean) => void;
|
|
110
|
+
}) {
|
|
111
|
+
const [openState, setOpenState] = useState(false);
|
|
112
|
+
const open = openProp ?? openState;
|
|
113
|
+
const setOpen = (o: boolean) => {
|
|
114
|
+
setOpenState(o);
|
|
115
|
+
onOpenChange?.(o);
|
|
116
|
+
};
|
|
117
|
+
const [q, setQ] = useState('');
|
|
118
|
+
const chosen = new Set(value.map((t) => t.id));
|
|
119
|
+
const term = q.trim().toLowerCase();
|
|
120
|
+
const shown = all.filter((t) => t.name.toLowerCase().includes(term)).slice(0, 30);
|
|
121
|
+
const exact = all.some((t) => t.name.toLowerCase() === term);
|
|
122
|
+
|
|
123
|
+
const toggle = (tag: TagItem) =>
|
|
124
|
+
onChange(chosen.has(tag.id) ? value.filter((t) => t.id !== tag.id) : [...value, tag]);
|
|
125
|
+
|
|
126
|
+
async function create() {
|
|
127
|
+
if (!onCreate || !q.trim()) return;
|
|
128
|
+
const tag = await onCreate(q.trim());
|
|
129
|
+
if (tag && !chosen.has(tag.id)) onChange([...value, tag]);
|
|
130
|
+
setQ('');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div data-slot="tag-picker" className="flex flex-wrap items-center gap-1.5">
|
|
135
|
+
{trigger === 'button' &&
|
|
136
|
+
!triggerElement &&
|
|
137
|
+
value.map((t) => (
|
|
138
|
+
<TagBadge key={t.id} tag={t} onRemove={disabled ? undefined : () => toggle(t)} />
|
|
139
|
+
))}
|
|
140
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
141
|
+
<PopoverTrigger
|
|
142
|
+
disabled={disabled}
|
|
143
|
+
render={
|
|
144
|
+
triggerElement ? (
|
|
145
|
+
triggerElement
|
|
146
|
+
) : trigger === 'icon' ? (
|
|
147
|
+
<Button
|
|
148
|
+
type="button"
|
|
149
|
+
variant="outline"
|
|
150
|
+
size="icon-xs"
|
|
151
|
+
aria-label={`Adicionar ${label}`}
|
|
152
|
+
/>
|
|
153
|
+
) : trigger === 'add' ? (
|
|
154
|
+
// D-785: o + discreto do título de uma seção, igual aos outros do painel.
|
|
155
|
+
<Button
|
|
156
|
+
type="button"
|
|
157
|
+
variant="ghost"
|
|
158
|
+
size="icon-sm"
|
|
159
|
+
aria-label={`Adicionar ${label}`}
|
|
160
|
+
/>
|
|
161
|
+
) : trigger === 'button' ? (
|
|
162
|
+
<Button type="button" variant="outline" size="xs" aria-label={`Adicionar ${label}`} />
|
|
163
|
+
) : (
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
aria-label={label}
|
|
167
|
+
className="border-input hover:bg-hover flex min-h-control-sm w-full flex-wrap items-center gap-1 rounded-control border px-2 py-1 text-left text-body-13"
|
|
168
|
+
/>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
>
|
|
172
|
+
{triggerElement ? (
|
|
173
|
+
triggerContent
|
|
174
|
+
) : trigger === 'icon' || trigger === 'add' ? (
|
|
175
|
+
<PlusIcon />
|
|
176
|
+
) : trigger === 'button' ? (
|
|
177
|
+
<>
|
|
178
|
+
<PlusIcon /> Tag
|
|
179
|
+
</>
|
|
180
|
+
) : value.length > 0 ? (
|
|
181
|
+
value.map((t) => <TagBadge key={t.id} tag={t} />)
|
|
182
|
+
) : (
|
|
183
|
+
<span className="text-muted-foreground flex items-center gap-1.5">
|
|
184
|
+
<TagIcon className="size-icon-sm" /> Escolher tags
|
|
185
|
+
</span>
|
|
186
|
+
)}
|
|
187
|
+
</PopoverTrigger>
|
|
188
|
+
<PopoverContent align="start" className="w-64 gap-2 p-2">
|
|
189
|
+
<Input
|
|
190
|
+
autoFocus
|
|
191
|
+
aria-label="Buscar ou criar tag"
|
|
192
|
+
placeholder="Buscar ou criar tag"
|
|
193
|
+
value={q}
|
|
194
|
+
onChange={(e) => setQ(e.target.value)}
|
|
195
|
+
onKeyDown={(e) => {
|
|
196
|
+
if (e.key === 'Enter') {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
const match = shown.find((t) => t.name.toLowerCase() === term) ?? shown[0];
|
|
199
|
+
if (!exact && term) void create();
|
|
200
|
+
else if (match) toggle(match);
|
|
201
|
+
}
|
|
202
|
+
}}
|
|
203
|
+
/>
|
|
204
|
+
<ul className="max-h-56 overflow-y-auto" aria-label="Tags">
|
|
205
|
+
{shown.map((t) => (
|
|
206
|
+
<li key={t.id}>
|
|
207
|
+
<button
|
|
208
|
+
type="button"
|
|
209
|
+
onClick={() => toggle(t)}
|
|
210
|
+
className="hover:bg-hover flex w-full items-center justify-between gap-2 rounded-control px-2 py-1.5 text-left"
|
|
211
|
+
>
|
|
212
|
+
<TagBadge tag={t} />
|
|
213
|
+
{chosen.has(t.id) && (
|
|
214
|
+
<CheckIcon className="size-icon-lg" aria-label="escolhida" />
|
|
215
|
+
)}
|
|
216
|
+
</button>
|
|
217
|
+
</li>
|
|
218
|
+
))}
|
|
219
|
+
{shown.length === 0 && !term && (
|
|
220
|
+
<li className="text-muted-foreground px-2 py-1.5 text-body-13">Nenhuma tag ainda.</li>
|
|
221
|
+
)}
|
|
222
|
+
</ul>
|
|
223
|
+
{onCreate && term && !exact && (
|
|
224
|
+
<Button
|
|
225
|
+
type="button"
|
|
226
|
+
variant="ghost"
|
|
227
|
+
size="sm"
|
|
228
|
+
className="justify-start"
|
|
229
|
+
onClick={() => void create()}
|
|
230
|
+
>
|
|
231
|
+
<PlusIcon /> Criar “{q.trim()}”
|
|
232
|
+
</Button>
|
|
233
|
+
)}
|
|
234
|
+
</PopoverContent>
|
|
235
|
+
</Popover>
|
|
236
|
+
</div>
|
|
237
|
+
);
|
|
238
|
+
}
|