@vowt-tech/ui 0.177.3 → 0.178.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/guia/LEIA-PRIMEIRO.md +1 -1
- package/guia/VERSAO +1 -1
- package/guia/componentes.md +2 -1
- package/package.json +1 -1
- package/src/components/change-card.tsx +290 -0
package/guia/LEIA-PRIMEIRO.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Design system VOWT, guia para este app
|
|
2
2
|
|
|
3
|
-
> Pasta gerada pelo pacote @vowt-tech/ui 0.
|
|
3
|
+
> Pasta gerada pelo pacote @vowt-tech/ui 0.178.0. Não edite: ela é refeita a cada atualização
|
|
4
4
|
> do pacote pelo comando `vowt-ux-ui-design sync`. Regra própria deste app fica fora daqui.
|
|
5
5
|
|
|
6
6
|
Este app usa o design system da VOWT. Do pacote @vowt-tech/ui, o app importa os fundamentos,
|
package/guia/VERSAO
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.178.0
|
package/guia/componentes.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Componentes
|
|
2
2
|
|
|
3
|
-
> Gerado do pacote @vowt-tech/ui 0.
|
|
3
|
+
> Gerado do pacote @vowt-tech/ui 0.178.0. Cada linha traz o nome da peça, o import do pacote e
|
|
4
4
|
> a página com o exemplo.
|
|
5
5
|
|
|
6
6
|
Antes de montar uma tela, procure aqui. Cada peça é importada do pacote, como
|
|
@@ -25,6 +25,7 @@ app não copia nem altera a peça: o pedido de mudança vai ao repositório vowt
|
|
|
25
25
|
- `button`: `import { Button, StatefulButton, buttonVariants, CopyButton } from '@vowt-tech/ui/button'`. Página: https://developers.vowt.com.br/button
|
|
26
26
|
- `calendar`: `import { Calendar, CalendarDayButton } from '@vowt-tech/ui/calendar'`. Página: https://developers.vowt.com.br/calendar
|
|
27
27
|
- `card`: `import { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent, Panel, panelVariants } from '@vowt-tech/ui/card'`. Página: https://developers.vowt.com.br/card
|
|
28
|
+
- `change-card`: `import { ChangeCard } from '@vowt-tech/ui/change-card'`. Página: https://developers.vowt.com.br/change-card
|
|
28
29
|
- `chart`: `import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, CHART_COLORS, seriesConfig, formatNumber, AXIS, CHART_ANIMATION } from '@vowt-tech/ui/chart'`. Página: https://developers.vowt.com.br/chart
|
|
29
30
|
- `checkbox`: `import { Checkbox } from '@vowt-tech/ui/checkbox'`. Página: https://developers.vowt.com.br/checkbox
|
|
30
31
|
- `code-block`: `import { CodeBlock } from '@vowt-tech/ui/code-block'`. Página: https://developers.vowt.com.br/code-block
|
package/package.json
CHANGED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { CheckCircle2Icon, MinusIcon, PencilIcon, PlusIcon, TriangleAlertIcon } from 'lucide-react';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
import { Alert, AlertDescription, AlertTitle } from './alert';
|
|
7
|
+
import { Badge } from './badge';
|
|
8
|
+
import { Button } from './button';
|
|
9
|
+
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from './card';
|
|
10
|
+
import { CollapsibleSection } from './collapsible';
|
|
11
|
+
import { Spinner } from './spinner';
|
|
12
|
+
|
|
13
|
+
// Cartão de mudanças, D-865: a lista de mudanças propostas, como as que um agente de IA sugere,
|
|
14
|
+
// para a pessoa revisar antes de aplicar. Cada item diz o tipo, criar, alterar ou remover, o
|
|
15
|
+
// objeto, o campo e o valor de antes, riscado, e o de depois, em destaque de sucesso. A cor nunca
|
|
16
|
+
// fala sozinha: cada valor leva o rótulo "Antes" ou "Depois", visível e lido pelo leitor de tela.
|
|
17
|
+
// Os itens ficam agrupados por objeto; com mais de `collapseAfter` itens, cada grupo recolhe.
|
|
18
|
+
// O pacote não sabe quem pode aplicar: o app passa as ações que a pessoa pode usar, com o texto
|
|
19
|
+
// dele, e o estado. Aplicando, os botões travam contra o clique duplo.
|
|
20
|
+
|
|
21
|
+
export type ChangeKind = 'create' | 'update' | 'remove';
|
|
22
|
+
export type ChangeStatus = 'pending' | 'applying' | 'applied' | 'failed';
|
|
23
|
+
|
|
24
|
+
export type ChangeItem = {
|
|
25
|
+
id: string;
|
|
26
|
+
kind: ChangeKind;
|
|
27
|
+
/** O objeto que muda, como o nome de um registro. Os itens são agrupados por ele. */
|
|
28
|
+
object: string;
|
|
29
|
+
/** O campo, como "Telefone". Sem campo, o item fala do objeto inteiro. */
|
|
30
|
+
field?: string;
|
|
31
|
+
/** Valor de antes. Criar não tem. */
|
|
32
|
+
before?: React.ReactNode;
|
|
33
|
+
/** Valor de depois. Remover não tem. */
|
|
34
|
+
after?: React.ReactNode;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ChangeAction = { label: string; onClick: () => void; icon?: React.ReactNode };
|
|
38
|
+
|
|
39
|
+
const LABELS = {
|
|
40
|
+
create: 'Criar',
|
|
41
|
+
update: 'Alterar',
|
|
42
|
+
remove: 'Remover',
|
|
43
|
+
before: 'Antes',
|
|
44
|
+
after: 'Depois',
|
|
45
|
+
applying: 'Aplicando as mudanças',
|
|
46
|
+
applied: 'Mudanças aplicadas',
|
|
47
|
+
failed: 'Não foi possível aplicar',
|
|
48
|
+
nothingApplied: 'Nada foi aplicado.',
|
|
49
|
+
changes: (n: number) => (n === 1 ? '1 mudança' : `${n} mudanças`),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ChangeCardLabels = Partial<typeof LABELS>;
|
|
53
|
+
|
|
54
|
+
const KIND = {
|
|
55
|
+
create: { variant: 'success', icon: PlusIcon },
|
|
56
|
+
update: { variant: 'info', icon: PencilIcon },
|
|
57
|
+
remove: { variant: 'destructive', icon: MinusIcon },
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
function ChangeValue({
|
|
61
|
+
tone,
|
|
62
|
+
label,
|
|
63
|
+
children,
|
|
64
|
+
}: {
|
|
65
|
+
tone: 'before' | 'after';
|
|
66
|
+
label: string;
|
|
67
|
+
children: React.ReactNode;
|
|
68
|
+
}) {
|
|
69
|
+
return (
|
|
70
|
+
<span data-slot="change-value" data-tone={tone} className="flex min-w-0 items-baseline gap-1.5">
|
|
71
|
+
<span className="shrink-0 text-body-12 text-muted-foreground">{label}</span>
|
|
72
|
+
<span
|
|
73
|
+
className={cn(
|
|
74
|
+
'min-w-0 break-words',
|
|
75
|
+
tone === 'before'
|
|
76
|
+
? 'text-muted-foreground line-through decoration-text-error'
|
|
77
|
+
: 'text-body-13-medium text-text-success',
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
{children}
|
|
81
|
+
</span>
|
|
82
|
+
</span>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function ChangeRow({ item, labels }: { item: ChangeItem; labels: typeof LABELS }) {
|
|
87
|
+
const kind = KIND[item.kind];
|
|
88
|
+
const Icon = kind.icon;
|
|
89
|
+
return (
|
|
90
|
+
<li
|
|
91
|
+
data-slot="change-item"
|
|
92
|
+
data-kind={item.kind}
|
|
93
|
+
className="grid gap-1.5 py-2.5 first:pt-0 last:pb-0"
|
|
94
|
+
>
|
|
95
|
+
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
|
96
|
+
<Badge variant={kind.variant}>
|
|
97
|
+
<Icon data-icon="inline-start" aria-hidden />
|
|
98
|
+
{labels[item.kind]}
|
|
99
|
+
</Badge>
|
|
100
|
+
{item.field && <span className="min-w-0 text-body-13-medium">{item.field}</span>}
|
|
101
|
+
</div>
|
|
102
|
+
{(item.kind !== 'create' && item.before !== undefined) ||
|
|
103
|
+
(item.kind !== 'remove' && item.after !== undefined) ? (
|
|
104
|
+
<div className="grid gap-1">
|
|
105
|
+
{item.kind !== 'create' && item.before !== undefined && (
|
|
106
|
+
<ChangeValue tone="before" label={labels.before}>
|
|
107
|
+
{item.before}
|
|
108
|
+
</ChangeValue>
|
|
109
|
+
)}
|
|
110
|
+
{item.kind !== 'remove' && item.after !== undefined && (
|
|
111
|
+
<ChangeValue tone="after" label={labels.after}>
|
|
112
|
+
{item.after}
|
|
113
|
+
</ChangeValue>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
) : null}
|
|
117
|
+
</li>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function ChangeCard({
|
|
122
|
+
title,
|
|
123
|
+
description,
|
|
124
|
+
changes,
|
|
125
|
+
status = 'pending',
|
|
126
|
+
error,
|
|
127
|
+
primaryAction,
|
|
128
|
+
secondaryAction,
|
|
129
|
+
tertiaryAction,
|
|
130
|
+
undoAction,
|
|
131
|
+
collapseAfter = 5,
|
|
132
|
+
size = 'default',
|
|
133
|
+
labels: customLabels,
|
|
134
|
+
className,
|
|
135
|
+
}: {
|
|
136
|
+
title: React.ReactNode;
|
|
137
|
+
description?: React.ReactNode;
|
|
138
|
+
changes: ChangeItem[];
|
|
139
|
+
/** pending: esperando a decisão; applying: aplicando; applied: aplicado; failed: falhou. */
|
|
140
|
+
status?: ChangeStatus;
|
|
141
|
+
/** Mensagem do app quando falha. O cartão acrescenta que nada foi aplicado. */
|
|
142
|
+
error?: React.ReactNode;
|
|
143
|
+
/** A ação principal, como Aplicar. */
|
|
144
|
+
primaryAction?: ChangeAction;
|
|
145
|
+
/** A ação secundária, como Descartar. */
|
|
146
|
+
secondaryAction?: ChangeAction;
|
|
147
|
+
/** Uma terceira ação, opcional, como Solicitar ao Administrador. */
|
|
148
|
+
tertiaryAction?: ChangeAction;
|
|
149
|
+
/** Depois de aplicado, a ação de desfazer, se o app oferecer. */
|
|
150
|
+
undoAction?: ChangeAction;
|
|
151
|
+
/** Com mais itens que isso, cada grupo recolhe e expande. */
|
|
152
|
+
collapseAfter?: number;
|
|
153
|
+
size?: 'sm' | 'default' | 'lg';
|
|
154
|
+
/** Textos do cartão, para outro idioma. */
|
|
155
|
+
labels?: ChangeCardLabels;
|
|
156
|
+
className?: string;
|
|
157
|
+
}) {
|
|
158
|
+
const labels = { ...LABELS, ...customLabels };
|
|
159
|
+
const groups = React.useMemo(() => {
|
|
160
|
+
const map = new Map<string, ChangeItem[]>();
|
|
161
|
+
for (const c of changes) map.set(c.object, [...(map.get(c.object) ?? []), c]);
|
|
162
|
+
return [...map];
|
|
163
|
+
}, [changes]);
|
|
164
|
+
const collapsible = changes.length > collapseAfter;
|
|
165
|
+
const busy = status === 'applying';
|
|
166
|
+
const buttonSize = size === 'sm' ? 'sm' : size === 'lg' ? 'lg' : 'default';
|
|
167
|
+
const showActions = status === 'pending' || status === 'applying' || status === 'failed';
|
|
168
|
+
|
|
169
|
+
const list = (items: ChangeItem[]) => (
|
|
170
|
+
<ul className="grid divide-y">
|
|
171
|
+
{items.map((item) => (
|
|
172
|
+
<ChangeRow key={item.id} item={item} labels={labels} />
|
|
173
|
+
))}
|
|
174
|
+
</ul>
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<Card
|
|
179
|
+
data-slot="change-card"
|
|
180
|
+
data-status={status}
|
|
181
|
+
size={size}
|
|
182
|
+
aria-busy={busy || undefined}
|
|
183
|
+
className={cn(
|
|
184
|
+
size === 'sm' && '[&_[data-slot=change-item]]:text-body-12',
|
|
185
|
+
size === 'lg' && 'text-body-14',
|
|
186
|
+
className,
|
|
187
|
+
)}
|
|
188
|
+
>
|
|
189
|
+
<CardHeader>
|
|
190
|
+
<CardTitle className={cn(size === 'lg' && 'text-heading-18')}>{title}</CardTitle>
|
|
191
|
+
<CardDescription>{description ?? labels.changes(changes.length)}</CardDescription>
|
|
192
|
+
</CardHeader>
|
|
193
|
+
<CardContent className="grid gap-3">
|
|
194
|
+
{collapsible ? (
|
|
195
|
+
<div className="-mx-2.5">
|
|
196
|
+
{groups.map(([object, items], i) => (
|
|
197
|
+
<CollapsibleSection
|
|
198
|
+
key={object}
|
|
199
|
+
title={object}
|
|
200
|
+
count={items.length}
|
|
201
|
+
defaultOpen={i === 0}
|
|
202
|
+
>
|
|
203
|
+
{list(items)}
|
|
204
|
+
</CollapsibleSection>
|
|
205
|
+
))}
|
|
206
|
+
</div>
|
|
207
|
+
) : (
|
|
208
|
+
groups.map(([object, items]) => (
|
|
209
|
+
<section key={object} aria-label={object} className="grid gap-2">
|
|
210
|
+
{groups.length > 1 && (
|
|
211
|
+
<h4 className="text-body-12-medium text-muted-foreground">{object}</h4>
|
|
212
|
+
)}
|
|
213
|
+
{list(items)}
|
|
214
|
+
</section>
|
|
215
|
+
))
|
|
216
|
+
)}
|
|
217
|
+
{/* O estado é anunciado para o leitor de tela quando muda. */}
|
|
218
|
+
<div role="status" aria-live="polite" className="contents">
|
|
219
|
+
{status === 'applying' && (
|
|
220
|
+
<p className="flex items-center gap-2 text-body-13 text-muted-foreground">
|
|
221
|
+
<Spinner label="" />
|
|
222
|
+
{labels.applying}
|
|
223
|
+
</p>
|
|
224
|
+
)}
|
|
225
|
+
{status === 'applied' && (
|
|
226
|
+
<Alert variant="success">
|
|
227
|
+
<CheckCircle2Icon aria-hidden />
|
|
228
|
+
<AlertTitle>{labels.applied}</AlertTitle>
|
|
229
|
+
</Alert>
|
|
230
|
+
)}
|
|
231
|
+
{status === 'failed' && (
|
|
232
|
+
<Alert variant="destructive-subtle">
|
|
233
|
+
<TriangleAlertIcon aria-hidden />
|
|
234
|
+
<AlertTitle>{labels.failed}</AlertTitle>
|
|
235
|
+
<AlertDescription>
|
|
236
|
+
{error ? <>{error} </> : null}
|
|
237
|
+
{labels.nothingApplied}
|
|
238
|
+
</AlertDescription>
|
|
239
|
+
</Alert>
|
|
240
|
+
)}
|
|
241
|
+
</div>
|
|
242
|
+
</CardContent>
|
|
243
|
+
{((showActions && (primaryAction || secondaryAction || tertiaryAction)) ||
|
|
244
|
+
(status === 'applied' && undoAction)) && (
|
|
245
|
+
<CardFooter className="flex flex-wrap justify-end gap-2">
|
|
246
|
+
{status === 'applied' && undoAction ? (
|
|
247
|
+
<Button variant="outline" size={buttonSize} onClick={undoAction.onClick}>
|
|
248
|
+
{undoAction.icon}
|
|
249
|
+
{undoAction.label}
|
|
250
|
+
</Button>
|
|
251
|
+
) : (
|
|
252
|
+
<>
|
|
253
|
+
{tertiaryAction && (
|
|
254
|
+
<Button
|
|
255
|
+
variant="ghost"
|
|
256
|
+
size={buttonSize}
|
|
257
|
+
className="mr-auto"
|
|
258
|
+
disabled={busy}
|
|
259
|
+
onClick={tertiaryAction.onClick}
|
|
260
|
+
>
|
|
261
|
+
{tertiaryAction.icon}
|
|
262
|
+
{tertiaryAction.label}
|
|
263
|
+
</Button>
|
|
264
|
+
)}
|
|
265
|
+
{secondaryAction && (
|
|
266
|
+
<Button
|
|
267
|
+
variant="outline"
|
|
268
|
+
size={buttonSize}
|
|
269
|
+
disabled={busy}
|
|
270
|
+
onClick={secondaryAction.onClick}
|
|
271
|
+
>
|
|
272
|
+
{secondaryAction.icon}
|
|
273
|
+
{secondaryAction.label}
|
|
274
|
+
</Button>
|
|
275
|
+
)}
|
|
276
|
+
{primaryAction && (
|
|
277
|
+
<Button size={buttonSize} disabled={busy} onClick={primaryAction.onClick}>
|
|
278
|
+
{busy ? <Spinner data-icon="inline-start" label="" /> : primaryAction.icon}
|
|
279
|
+
{primaryAction.label}
|
|
280
|
+
</Button>
|
|
281
|
+
)}
|
|
282
|
+
</>
|
|
283
|
+
)}
|
|
284
|
+
</CardFooter>
|
|
285
|
+
)}
|
|
286
|
+
</Card>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { ChangeCard };
|