@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,280 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { PencilIcon } from 'lucide-react';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
import { Button } from './button';
|
|
7
|
+
import { Input } from './input';
|
|
8
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './select';
|
|
9
|
+
|
|
10
|
+
// tokens-ok-ligacao: só estrutura e tokens: pares de rótulo e valor.
|
|
11
|
+
|
|
12
|
+
// Pares de rótulo e valor, como os dados de um pedido: "Cliente · Ana Souza". Lado a lado na tela
|
|
13
|
+
// larga e um embaixo do outro no celular.
|
|
14
|
+
|
|
15
|
+
export type DescriptionItem = { term: React.ReactNode; description: React.ReactNode };
|
|
16
|
+
|
|
17
|
+
function DescriptionList({
|
|
18
|
+
items,
|
|
19
|
+
layout = 'horizontal',
|
|
20
|
+
className,
|
|
21
|
+
}: {
|
|
22
|
+
items: DescriptionItem[];
|
|
23
|
+
layout?: 'horizontal' | 'vertical';
|
|
24
|
+
className?: string;
|
|
25
|
+
}) {
|
|
26
|
+
return (
|
|
27
|
+
<dl
|
|
28
|
+
data-slot="description-list"
|
|
29
|
+
data-layout={layout}
|
|
30
|
+
className={cn('divide-y text-body-13', className)}
|
|
31
|
+
>
|
|
32
|
+
{items.map((item, i) => (
|
|
33
|
+
<div
|
|
34
|
+
key={i}
|
|
35
|
+
className={cn(
|
|
36
|
+
'grid gap-1 py-3 first:pt-0 last:pb-0',
|
|
37
|
+
layout === 'horizontal' && 'sm:grid-cols-[minmax(8rem,1fr)_2fr] sm:gap-4',
|
|
38
|
+
)}
|
|
39
|
+
>
|
|
40
|
+
<dt className="text-muted-foreground">{item.term}</dt>
|
|
41
|
+
<dd className="min-w-0 break-words text-foreground">{item.description}</dd>
|
|
42
|
+
</div>
|
|
43
|
+
))}
|
|
44
|
+
</dl>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// D-663: o lápis fica sempre à vista no campo que dá para editar, para a pessoa saber sem passar o
|
|
49
|
+
// mouse; no passar do mouse, ele escurece. D-846: `editHint="hover"` mostra o lápis só no passar do
|
|
50
|
+
// mouse e no foco, para fichas com muitos campos, como a do VOWT CRM.
|
|
51
|
+
|
|
52
|
+
// Dado de uma ficha que se edita no próprio lugar (D-341), como Cargo ou Dono. Mostra o nome e o
|
|
53
|
+
// valor; tocar no valor troca pelo campo, que salva sozinho ao escolher ou ao sair dele. Volta o
|
|
54
|
+
// Inline field que saiu na D-309. Vazio, mostra o texto em cinza, como "Sem cargo".
|
|
55
|
+
//
|
|
56
|
+
// D-846, pedido do VOWT CRM: um padrão só de edição na linha, com editores prontos, texto e
|
|
57
|
+
// opção; valor à direita pelo `align`; e o campo de vários valores, como
|
|
58
|
+
// telefones com um principal, edita o principal na linha e tem o link Gerenciar.
|
|
59
|
+
|
|
60
|
+
// Edição discreta, igual à da TableCellEditable em table.tsx: o campo ocupa a mesma caixa da
|
|
61
|
+
// leitura, sem borda, fundo ou anel próprios, e só o contorno fino avisa que está editando. A
|
|
62
|
+
// altura não muda entre ler, passar o mouse e editar. Mudou aqui, mudar lá também.
|
|
63
|
+
// D-806: com Select, o campo ocupa a caixa toda, e a lista abre com a largura da coluna.
|
|
64
|
+
const INLINE_EDIT =
|
|
65
|
+
'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! [&_input]:p-0! [&_[data-slot=select-trigger]]:py-0! [&_[data-slot=select-trigger]]:px-1.5! has-[[data-slot=select-trigger]]:px-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!';
|
|
66
|
+
// Sem `w-full`: dentro da grade, a caixa estica até as bordas com a margem negativa, e o fim do
|
|
67
|
+
// valor alinha com o das linhas que só mostram, D-846.
|
|
68
|
+
const BOX = '-mx-1.5 flex min-h-6 min-w-0 items-center gap-2 rounded-control px-1.5 py-0.5';
|
|
69
|
+
|
|
70
|
+
function PropertyRow({
|
|
71
|
+
label,
|
|
72
|
+
children,
|
|
73
|
+
empty,
|
|
74
|
+
editor,
|
|
75
|
+
align = 'start',
|
|
76
|
+
editHint = 'always',
|
|
77
|
+
more,
|
|
78
|
+
manage,
|
|
79
|
+
className,
|
|
80
|
+
}: {
|
|
81
|
+
label: React.ReactNode;
|
|
82
|
+
/** O valor mostrado. Vazio, aparece `empty`. */
|
|
83
|
+
children?: React.ReactNode;
|
|
84
|
+
/** Texto do vazio, como "Sem cargo". */
|
|
85
|
+
empty?: React.ReactNode;
|
|
86
|
+
/**
|
|
87
|
+
* O campo de editar; chame `done` ao salvar ou cancelar. Sem ele, só leitura. Os de sempre
|
|
88
|
+
* estão prontos: PropertyTextEditor e PropertySelectEditor, D-846.
|
|
89
|
+
*/
|
|
90
|
+
editor?: (done: () => void) => React.ReactNode;
|
|
91
|
+
/** Valor encostado à esquerda, o padrão, ou à direita, D-846. */
|
|
92
|
+
align?: 'start' | 'end';
|
|
93
|
+
/**
|
|
94
|
+
* Quando o lápis aparece. `always`, o padrão da D-663, fica sempre à vista; `hover` só no passar
|
|
95
|
+
* do mouse e no foco do teclado, com o lugar reservado, para nada se mexer, D-846. Sem mouse,
|
|
96
|
+
* tocar na linha abre a edição do mesmo jeito.
|
|
97
|
+
*/
|
|
98
|
+
editHint?: 'always' | 'hover';
|
|
99
|
+
/** Campo de vários valores: quantos há além do principal, como "+2" ao lado dele. */
|
|
100
|
+
more?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Campo de vários valores, como telefones e e-mails com um principal, D-846: a linha edita só o
|
|
103
|
+
* principal, e o link Gerenciar abre a lista inteira, numa janela do app.
|
|
104
|
+
*/
|
|
105
|
+
manage?: { label?: string; onClick: () => void };
|
|
106
|
+
className?: string;
|
|
107
|
+
}) {
|
|
108
|
+
const [editing, setEditing] = React.useState(false);
|
|
109
|
+
const has = children !== undefined && children !== null && children !== '';
|
|
110
|
+
const end = align === 'end';
|
|
111
|
+
const value = (
|
|
112
|
+
<>
|
|
113
|
+
{has ? children : <span className="text-muted-foreground">{empty ?? 'Não informado'}</span>}
|
|
114
|
+
{has && more !== undefined && more > 0 && (
|
|
115
|
+
<span className="ml-1.5 text-body-12 text-muted-foreground tabular-nums">+{more}</span>
|
|
116
|
+
)}
|
|
117
|
+
</>
|
|
118
|
+
);
|
|
119
|
+
const field =
|
|
120
|
+
editing && editor ? (
|
|
121
|
+
<div
|
|
122
|
+
data-editing=""
|
|
123
|
+
className={cn(BOX, 'bg-hover', INLINE_EDIT, end && '[&_input]:text-right')}
|
|
124
|
+
>
|
|
125
|
+
{editor(() => setEditing(false))}
|
|
126
|
+
</div>
|
|
127
|
+
) : editor ? (
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
onClick={() => setEditing(true)}
|
|
131
|
+
className={cn(
|
|
132
|
+
BOX,
|
|
133
|
+
'group/prop text-left outline-none hover:bg-hover focus-visible:bg-hover focus-visible:ring-1 focus-visible:ring-ring-strong',
|
|
134
|
+
// D-846: com o valor à direita, o lápis vai para a esquerda dele, e o fim do valor alinha
|
|
135
|
+
// com o das linhas que só mostram.
|
|
136
|
+
end && 'flex-row-reverse',
|
|
137
|
+
)}
|
|
138
|
+
>
|
|
139
|
+
<span className={cn('min-w-0 flex-1 break-words', end && 'text-right')}>{value}</span>
|
|
140
|
+
<PencilIcon
|
|
141
|
+
aria-hidden
|
|
142
|
+
className={cn(
|
|
143
|
+
'size-icon-sm shrink-0 text-muted-foreground group-hover/prop:text-foreground group-focus-visible/prop:text-foreground',
|
|
144
|
+
// D-846: some sem sair do lugar, para o valor não pular quando ele aparece.
|
|
145
|
+
editHint === 'hover' &&
|
|
146
|
+
'opacity-0 group-hover/prop:opacity-100 group-focus-visible/prop:opacity-100',
|
|
147
|
+
)}
|
|
148
|
+
/>
|
|
149
|
+
<span className="sr-only">Editar</span>
|
|
150
|
+
</button>
|
|
151
|
+
) : (
|
|
152
|
+
<span className={cn('block break-words', end && 'text-right')}>{value}</span>
|
|
153
|
+
);
|
|
154
|
+
return (
|
|
155
|
+
<div
|
|
156
|
+
data-slot="property-row"
|
|
157
|
+
data-align={align}
|
|
158
|
+
className={cn('grid grid-cols-1 gap-1 py-2 sm:grid-cols-3 sm:gap-3', className)}
|
|
159
|
+
>
|
|
160
|
+
<dt className="text-body-13 text-muted-foreground">{label}</dt>
|
|
161
|
+
<dd className="grid min-w-0 text-body-13 sm:col-span-2">
|
|
162
|
+
{manage ? (
|
|
163
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
164
|
+
<div className="grid min-w-0 flex-1">{field}</div>
|
|
165
|
+
<Button
|
|
166
|
+
variant="link"
|
|
167
|
+
size="xs"
|
|
168
|
+
className="h-auto shrink-0 p-0"
|
|
169
|
+
onClick={manage.onClick}
|
|
170
|
+
>
|
|
171
|
+
{manage.label ?? 'Gerenciar'}
|
|
172
|
+
</Button>
|
|
173
|
+
</div>
|
|
174
|
+
) : (
|
|
175
|
+
field
|
|
176
|
+
)}
|
|
177
|
+
</dd>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Texto editado na linha, D-846: Enter ou sair do campo salva, Esc desiste. Só chama `onSave`
|
|
184
|
+
* quando o texto mudou.
|
|
185
|
+
*/
|
|
186
|
+
function PropertyTextEditor({
|
|
187
|
+
value,
|
|
188
|
+
onSave,
|
|
189
|
+
done,
|
|
190
|
+
label,
|
|
191
|
+
type = 'text',
|
|
192
|
+
placeholder,
|
|
193
|
+
}: {
|
|
194
|
+
value: string;
|
|
195
|
+
onSave: (value: string) => void;
|
|
196
|
+
/** O `done` que o `editor` do PropertyRow recebe. */
|
|
197
|
+
done: () => void;
|
|
198
|
+
/** Nome do campo para o leitor de tela, como "Cargo". */
|
|
199
|
+
label: string;
|
|
200
|
+
type?: 'text' | 'email' | 'tel' | 'url' | 'number';
|
|
201
|
+
placeholder?: string;
|
|
202
|
+
}) {
|
|
203
|
+
return (
|
|
204
|
+
<Input
|
|
205
|
+
autoFocus
|
|
206
|
+
type={type}
|
|
207
|
+
aria-label={label}
|
|
208
|
+
placeholder={placeholder}
|
|
209
|
+
defaultValue={value}
|
|
210
|
+
onBlur={(e) => {
|
|
211
|
+
const next = e.target.value.trim();
|
|
212
|
+
if (next !== value) onSave(next);
|
|
213
|
+
done();
|
|
214
|
+
}}
|
|
215
|
+
onKeyDown={(e) => {
|
|
216
|
+
if (e.key === 'Enter') (e.target as HTMLInputElement).blur();
|
|
217
|
+
if (e.key === 'Escape') {
|
|
218
|
+
// Desiste sem salvar: volta o texto antes de o campo sair.
|
|
219
|
+
(e.target as HTMLInputElement).value = value;
|
|
220
|
+
done();
|
|
221
|
+
}
|
|
222
|
+
}}
|
|
223
|
+
/>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export type PropertyOption = { value: string; label: string; icon?: React.ReactNode };
|
|
228
|
+
|
|
229
|
+
/** Opção de uma lista editada na linha, D-846: a lista já abre, e escolher salva. */
|
|
230
|
+
function PropertySelectEditor({
|
|
231
|
+
value,
|
|
232
|
+
options,
|
|
233
|
+
onSave,
|
|
234
|
+
done,
|
|
235
|
+
label,
|
|
236
|
+
}: {
|
|
237
|
+
value: string | null;
|
|
238
|
+
options: PropertyOption[];
|
|
239
|
+
onSave: (value: string) => void;
|
|
240
|
+
done: () => void;
|
|
241
|
+
label: string;
|
|
242
|
+
}) {
|
|
243
|
+
return (
|
|
244
|
+
<Select
|
|
245
|
+
defaultOpen
|
|
246
|
+
items={options.map((o) => ({ value: o.value, label: o.label }))}
|
|
247
|
+
value={value}
|
|
248
|
+
onValueChange={(v) => {
|
|
249
|
+
if (typeof v === 'string' && v !== value) onSave(v);
|
|
250
|
+
done();
|
|
251
|
+
}}
|
|
252
|
+
onOpenChange={(open) => {
|
|
253
|
+
if (!open) done();
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
<SelectTrigger aria-label={label}>
|
|
257
|
+
<SelectValue />
|
|
258
|
+
</SelectTrigger>
|
|
259
|
+
<SelectContent>
|
|
260
|
+
{options.map((o) => (
|
|
261
|
+
<SelectItem key={o.value} value={o.value}>
|
|
262
|
+
{o.icon}
|
|
263
|
+
{o.label}
|
|
264
|
+
</SelectItem>
|
|
265
|
+
))}
|
|
266
|
+
</SelectContent>
|
|
267
|
+
</Select>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** A lista de dados da ficha, com uma linha embaixo da outra. */
|
|
272
|
+
function PropertyList({ children, className }: { children: React.ReactNode; className?: string }) {
|
|
273
|
+
return (
|
|
274
|
+
<dl data-slot="property-list" className={cn('grid divide-y', className)}>
|
|
275
|
+
{children}
|
|
276
|
+
</dl>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export { DescriptionList, PropertyRow, PropertyList, PropertyTextEditor, PropertySelectEditor };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Dialog as DialogPrimitive } from '@base-ui/react/dialog';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
|
|
7
|
+
import { Button } from './button';
|
|
8
|
+
import { XIcon } from 'lucide-react';
|
|
9
|
+
|
|
10
|
+
function Dialog({ ...props }: DialogPrimitive.Root.Props) {
|
|
11
|
+
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {
|
|
15
|
+
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {
|
|
19
|
+
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function DialogClose({ ...props }: DialogPrimitive.Close.Props) {
|
|
23
|
+
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function DialogOverlay({ className, ...props }: DialogPrimitive.Backdrop.Props) {
|
|
27
|
+
return (
|
|
28
|
+
<DialogPrimitive.Backdrop
|
|
29
|
+
data-slot="dialog-overlay"
|
|
30
|
+
className={cn(
|
|
31
|
+
'fixed inset-0 isolate z-50 bg-surface-overlay duration-(--duration-medium) supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0',
|
|
32
|
+
className,
|
|
33
|
+
)}
|
|
34
|
+
{...props}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Foco ao abrir a janela: pelo teclado, vai para o primeiro campo ou botão, como pede a
|
|
40
|
+
// acessibilidade; pelo mouse, pelo toque ou já aberta com a página, vai para a própria janela, sem
|
|
41
|
+
// anel azul num botão nem dica aberta. Serve ao Dialog, ao Alert dialog e ao Sheet.
|
|
42
|
+
function useQuietInitialFocus(ref: React.Ref<HTMLDivElement> | undefined) {
|
|
43
|
+
const popupRef = React.useRef<HTMLDivElement | null>(null);
|
|
44
|
+
const setRef = React.useCallback(
|
|
45
|
+
(el: HTMLDivElement | null) => {
|
|
46
|
+
popupRef.current = el;
|
|
47
|
+
if (typeof ref === 'function') ref(el);
|
|
48
|
+
else if (ref) ref.current = el;
|
|
49
|
+
},
|
|
50
|
+
[ref],
|
|
51
|
+
);
|
|
52
|
+
const initialFocus = React.useCallback(
|
|
53
|
+
(type: string) => (type === 'keyboard' ? true : popupRef.current),
|
|
54
|
+
[],
|
|
55
|
+
);
|
|
56
|
+
return { ref: setRef, initialFocus };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function DialogContent({
|
|
60
|
+
className,
|
|
61
|
+
children,
|
|
62
|
+
showCloseButton = true,
|
|
63
|
+
size = 'default',
|
|
64
|
+
ref,
|
|
65
|
+
initialFocus,
|
|
66
|
+
...props
|
|
67
|
+
}: DialogPrimitive.Popup.Props & {
|
|
68
|
+
showCloseButton?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Escada de janelas, D-818. `sm`, 400: confirmar. `default`, 560: até 6 campos. `lg`, 880: duas
|
|
71
|
+
* colunas, com prévia ou resumo ao lado. Rolou demais, sobe um degrau; a grande não bastou, vira
|
|
72
|
+
* página. Nunca uma janela aberta de dentro de outra. O `xl` antigo vale como `lg`.
|
|
73
|
+
*/
|
|
74
|
+
size?: 'sm' | 'default' | 'lg' | 'xl';
|
|
75
|
+
}) {
|
|
76
|
+
const focus = useQuietInitialFocus(ref);
|
|
77
|
+
return (
|
|
78
|
+
<DialogPortal>
|
|
79
|
+
<DialogOverlay />
|
|
80
|
+
<DialogPrimitive.Popup
|
|
81
|
+
data-slot="dialog-content"
|
|
82
|
+
data-size={size}
|
|
83
|
+
className={cn(
|
|
84
|
+
// D-818: a janela nunca passa da tela. Com o Dialog body, só o meio rola, e o cabeçalho e
|
|
85
|
+
// o rodapé, com o botão principal, ficam sempre à vista; sem ele, a janela toda rola.
|
|
86
|
+
'fixed top-1/2 left-1/2 z-50 grid max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 overflow-y-auto rounded-card bg-popover p-5 shadow-dialog text-body-13 text-popover-foreground ring-1 ring-border duration-(--duration-medium) outline-none has-data-[slot=dialog-body]:flex has-data-[slot=dialog-body]:flex-col has-data-[slot=dialog-body]:overflow-hidden data-[size=default]:sm:max-w-dialog data-[size=lg]:sm:max-w-dialog-lg data-[size=xl]:sm:max-w-dialog-lg data-[size=sm]:sm:max-w-dialog-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
|
|
87
|
+
className,
|
|
88
|
+
)}
|
|
89
|
+
ref={focus.ref}
|
|
90
|
+
initialFocus={initialFocus ?? focus.initialFocus}
|
|
91
|
+
{...props}
|
|
92
|
+
>
|
|
93
|
+
{children}
|
|
94
|
+
{showCloseButton && (
|
|
95
|
+
<DialogPrimitive.Close
|
|
96
|
+
data-slot="dialog-close"
|
|
97
|
+
render={<Button variant="ghost" className="absolute top-4 right-4" size="icon-sm" />}
|
|
98
|
+
>
|
|
99
|
+
<XIcon />
|
|
100
|
+
<span className="sr-only">Fechar</span>
|
|
101
|
+
</DialogPrimitive.Close>
|
|
102
|
+
)}
|
|
103
|
+
</DialogPrimitive.Popup>
|
|
104
|
+
</DialogPortal>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function DialogHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
|
109
|
+
return (
|
|
110
|
+
<div
|
|
111
|
+
data-slot="dialog-header"
|
|
112
|
+
// O título não passa por baixo do X de fechar, que fica no canto.
|
|
113
|
+
className={cn('flex flex-col gap-2 pr-8', className)}
|
|
114
|
+
{...props}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* O meio da janela, D-818: só ele rola, e o cabeçalho e o rodapé ficam parados. Use em toda janela
|
|
121
|
+
* que pode passar da altura da tela, como a média com muitos campos e a grande em duas colunas.
|
|
122
|
+
*/
|
|
123
|
+
function DialogBody({ className, ...props }: React.ComponentProps<'div'>) {
|
|
124
|
+
return (
|
|
125
|
+
<div
|
|
126
|
+
data-slot="dialog-body"
|
|
127
|
+
// A margem negativa leva a barra de rolagem até a borda da janela.
|
|
128
|
+
className={cn('scroll-thin -mx-5 min-h-0 flex-1 overflow-y-auto px-5', className)}
|
|
129
|
+
{...props}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function DialogFooter({
|
|
135
|
+
className,
|
|
136
|
+
showCloseButton = false,
|
|
137
|
+
children,
|
|
138
|
+
...props
|
|
139
|
+
}: React.ComponentProps<'div'> & {
|
|
140
|
+
showCloseButton?: boolean;
|
|
141
|
+
}) {
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
data-slot="dialog-footer"
|
|
145
|
+
className={cn('flex flex-col-reverse gap-2 pt-1 sm:flex-row sm:justify-end', className)}
|
|
146
|
+
{...props}
|
|
147
|
+
>
|
|
148
|
+
{children}
|
|
149
|
+
{showCloseButton && (
|
|
150
|
+
<DialogPrimitive.Close render={<Button variant="outline" />}>Fechar</DialogPrimitive.Close>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
|
|
157
|
+
return (
|
|
158
|
+
<DialogPrimitive.Title
|
|
159
|
+
data-slot="dialog-title"
|
|
160
|
+
className={cn('text-title-dialog', className)}
|
|
161
|
+
{...props}
|
|
162
|
+
/>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function DialogDescription({ className, ...props }: DialogPrimitive.Description.Props) {
|
|
167
|
+
return (
|
|
168
|
+
<DialogPrimitive.Description
|
|
169
|
+
data-slot="dialog-description"
|
|
170
|
+
className={cn(
|
|
171
|
+
'text-body-13 text-muted-foreground *:[a]:font-semibold *:[a]:text-link *:[a]:hover:text-link-hover',
|
|
172
|
+
className,
|
|
173
|
+
)}
|
|
174
|
+
{...props}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
DialogBody,
|
|
181
|
+
useQuietInitialFocus,
|
|
182
|
+
Dialog,
|
|
183
|
+
DialogClose,
|
|
184
|
+
DialogContent,
|
|
185
|
+
DialogDescription,
|
|
186
|
+
DialogFooter,
|
|
187
|
+
DialogHeader,
|
|
188
|
+
DialogOverlay,
|
|
189
|
+
DialogPortal,
|
|
190
|
+
DialogTitle,
|
|
191
|
+
DialogTrigger,
|
|
192
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { cn } from '../lib/utils';
|
|
2
|
+
|
|
3
|
+
// tokens-ok-ligacao: só estrutura e tokens: linhas de texto antes e depois.
|
|
4
|
+
|
|
5
|
+
// O que mudou num texto (D-339): o que entrou em verde e o que saiu em vermelho riscado, palavra
|
|
6
|
+
// por palavra, no meio do texto de agora. Serve ao histórico e às aprovações da Base de
|
|
7
|
+
// conhecimento, e a qualquer texto com versões. Recebe o texto puro, sem formatação. Trecho que
|
|
8
|
+
// saiu colado ao que entrou ganha um respiro entre os dois, para não ler como uma palavra só; no
|
|
9
|
+
// escuro, a legenda usa a cor cheia, porque o fundo suave sumia.
|
|
10
|
+
|
|
11
|
+
type Part = { kind: 'same' | 'added' | 'removed'; text: string };
|
|
12
|
+
|
|
13
|
+
/** Separa em palavras, pontuação e espaços, para a quebra de linha continuar onde estava. */
|
|
14
|
+
const tokens = (s: string) => s.match(/\s+|[\p{L}\p{N}]+|[^\s\p{L}\p{N}]/gu) ?? [];
|
|
15
|
+
|
|
16
|
+
/** Diferença por palavra, pela maior sequência em comum. */
|
|
17
|
+
export function diffWords(before: string, after: string): Part[] {
|
|
18
|
+
const a = tokens(before);
|
|
19
|
+
const b = tokens(after);
|
|
20
|
+
const n = a.length;
|
|
21
|
+
const m = b.length;
|
|
22
|
+
const lcs: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0));
|
|
23
|
+
for (let i = n - 1; i >= 0; i--)
|
|
24
|
+
for (let j = m - 1; j >= 0; j--)
|
|
25
|
+
lcs[i]![j] =
|
|
26
|
+
a[i] === b[j] ? lcs[i + 1]![j + 1]! + 1 : Math.max(lcs[i + 1]![j]!, lcs[i]![j + 1]!);
|
|
27
|
+
const out: Part[] = [];
|
|
28
|
+
const push = (kind: Part['kind'], text: string) => {
|
|
29
|
+
const last = out[out.length - 1];
|
|
30
|
+
if (last && last.kind === kind) last.text += text;
|
|
31
|
+
else out.push({ kind, text });
|
|
32
|
+
};
|
|
33
|
+
let i = 0;
|
|
34
|
+
let j = 0;
|
|
35
|
+
while (i < n && j < m) {
|
|
36
|
+
if (a[i] === b[j]) {
|
|
37
|
+
push('same', a[i]!);
|
|
38
|
+
i++;
|
|
39
|
+
j++;
|
|
40
|
+
} else if (lcs[i + 1]![j]! >= lcs[i]![j + 1]!) push('removed', a[i++]!);
|
|
41
|
+
else push('added', b[j++]!);
|
|
42
|
+
}
|
|
43
|
+
while (i < n) push('removed', a[i++]!);
|
|
44
|
+
while (j < m) push('added', b[j++]!);
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function DiffView({
|
|
49
|
+
before,
|
|
50
|
+
after,
|
|
51
|
+
addedLabel = 'Entrou',
|
|
52
|
+
removedLabel = 'Saiu',
|
|
53
|
+
className,
|
|
54
|
+
}: {
|
|
55
|
+
before: string;
|
|
56
|
+
after: string;
|
|
57
|
+
addedLabel?: string;
|
|
58
|
+
removedLabel?: string;
|
|
59
|
+
className?: string;
|
|
60
|
+
}) {
|
|
61
|
+
const parts = diffWords(before, after);
|
|
62
|
+
const changed = parts.some((p) => p.kind !== 'same');
|
|
63
|
+
return (
|
|
64
|
+
<div data-slot="diff-view" className={cn('grid gap-3', className)}>
|
|
65
|
+
<div className="flex flex-wrap gap-3 text-body-12 text-muted-foreground">
|
|
66
|
+
<span className="flex items-center gap-1.5">
|
|
67
|
+
<span aria-hidden className="size-2.5 rounded-small bg-success-subtle dark:bg-success" />
|
|
68
|
+
{addedLabel}
|
|
69
|
+
</span>
|
|
70
|
+
<span className="flex items-center gap-1.5">
|
|
71
|
+
<span
|
|
72
|
+
aria-hidden
|
|
73
|
+
className="size-2.5 rounded-small bg-destructive-subtle dark:bg-destructive"
|
|
74
|
+
/>
|
|
75
|
+
{removedLabel}
|
|
76
|
+
</span>
|
|
77
|
+
</div>
|
|
78
|
+
{changed ? (
|
|
79
|
+
<p className="text-body-13 whitespace-pre-wrap break-words">
|
|
80
|
+
{parts.map((p, i) =>
|
|
81
|
+
p.kind === 'same' ? (
|
|
82
|
+
<span key={i}>{p.text}</span>
|
|
83
|
+
) : p.kind === 'added' ? (
|
|
84
|
+
<ins
|
|
85
|
+
key={i}
|
|
86
|
+
className="rounded-small bg-success-subtle text-success-subtle-foreground no-underline [del+&]:ml-1"
|
|
87
|
+
>
|
|
88
|
+
<span className="sr-only">{addedLabel}: </span>
|
|
89
|
+
{p.text}
|
|
90
|
+
</ins>
|
|
91
|
+
) : (
|
|
92
|
+
<del
|
|
93
|
+
key={i}
|
|
94
|
+
className="rounded-small bg-destructive-subtle text-destructive-subtle-foreground [ins+&]:ml-1"
|
|
95
|
+
>
|
|
96
|
+
<span className="sr-only">{removedLabel}: </span>
|
|
97
|
+
{p.text}
|
|
98
|
+
</del>
|
|
99
|
+
),
|
|
100
|
+
)}
|
|
101
|
+
</p>
|
|
102
|
+
) : (
|
|
103
|
+
<p className="text-body-13 text-muted-foreground">O texto não mudou.</p>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { DiffView };
|