@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,178 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type * as React from 'react';
|
|
4
|
+
import { useTheme } from 'next-themes';
|
|
5
|
+
import { Toaster as Sonner, toast, type ToasterProps } from 'sonner';
|
|
6
|
+
import { Avatar } from './avatar';
|
|
7
|
+
import { Button } from './button';
|
|
8
|
+
import { Spinner } from './spinner';
|
|
9
|
+
import { CheckCircleIcon, InfoIcon, TriangleAlertIcon, XCircleIcon, XIcon } from 'lucide-react';
|
|
10
|
+
import { cn } from '../lib/utils';
|
|
11
|
+
|
|
12
|
+
const ICONS = {
|
|
13
|
+
success: <CheckCircleIcon className="text-icon-success size-icon-lg" />,
|
|
14
|
+
info: <InfoIcon className="text-icon-info size-icon-lg" />,
|
|
15
|
+
warning: <TriangleAlertIcon className="text-icon-warning size-icon-lg" />,
|
|
16
|
+
error: <XCircleIcon className="text-icon-error size-icon-lg" />,
|
|
17
|
+
loading: <Spinner />,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const Toaster = ({ ...props }: ToasterProps) => {
|
|
21
|
+
const { theme = 'system' } = useTheme();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Sonner
|
|
25
|
+
theme={theme as ToasterProps['theme']}
|
|
26
|
+
className="toaster group"
|
|
27
|
+
icons={ICONS}
|
|
28
|
+
// D-772: todo aviso do canto com o X, para fechar o que ficou por cima da tela.
|
|
29
|
+
closeButton
|
|
30
|
+
style={
|
|
31
|
+
{
|
|
32
|
+
'--normal-bg': 'var(--popover)',
|
|
33
|
+
'--normal-text': 'var(--popover-foreground)',
|
|
34
|
+
'--normal-border': 'var(--border)',
|
|
35
|
+
'--border-radius': 'var(--radius-menu)',
|
|
36
|
+
} as React.CSSProperties
|
|
37
|
+
}
|
|
38
|
+
toastOptions={{
|
|
39
|
+
classNames: {
|
|
40
|
+
toast: 'cn-toast gap-3! px-5! py-4! pr-12!',
|
|
41
|
+
// O X dentro do cartão, no canto de cima à direita, no lugar da bolinha do lado de fora.
|
|
42
|
+
closeButton:
|
|
43
|
+
'left-auto! right-2! top-2! size-control-xs! transform-none! rounded-control! border-0! bg-transparent! text-muted-foreground! hover:bg-hover! hover:text-foreground! [&_svg]:size-icon-solo!',
|
|
44
|
+
},
|
|
45
|
+
}}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type ToastKind = 'default' | 'success' | 'error' | 'warning' | 'info' | 'loading';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Só a aparência do aviso, parada e no lugar, sem aparecer no canto da tela. Serve para mostrar o
|
|
55
|
+
* aviso num catálogo, num tutorial ou numa imagem de ajuda. Mesmos ícones, cores e canto do
|
|
56
|
+
* Toaster. A ação é só desenho, não clica.
|
|
57
|
+
*/
|
|
58
|
+
function ToastPreview({
|
|
59
|
+
kind = 'default',
|
|
60
|
+
title,
|
|
61
|
+
description,
|
|
62
|
+
action,
|
|
63
|
+
className,
|
|
64
|
+
...props
|
|
65
|
+
}: Omit<React.ComponentProps<'div'>, 'title'> & {
|
|
66
|
+
kind?: ToastKind;
|
|
67
|
+
title: React.ReactNode;
|
|
68
|
+
description?: React.ReactNode;
|
|
69
|
+
/** Texto do botão de ação, como "Desfazer". */
|
|
70
|
+
action?: string;
|
|
71
|
+
}) {
|
|
72
|
+
const icon = kind === 'default' ? null : kind === 'loading' ? <Spinner label="" /> : ICONS[kind];
|
|
73
|
+
return (
|
|
74
|
+
<div
|
|
75
|
+
data-slot="toast-preview"
|
|
76
|
+
className={cn(
|
|
77
|
+
'relative flex w-[356px] max-w-full items-center gap-3 rounded-menu border bg-popover py-4 pr-12 pl-5 text-body-13 text-popover-foreground shadow-popup',
|
|
78
|
+
className,
|
|
79
|
+
)}
|
|
80
|
+
{...props}
|
|
81
|
+
>
|
|
82
|
+
{icon && <span className="flex shrink-0">{icon}</span>}
|
|
83
|
+
<div className="grid min-w-0 gap-0.5">
|
|
84
|
+
<span className="text-body-13-medium">{title}</span>
|
|
85
|
+
{description && <span className="text-muted-foreground">{description}</span>}
|
|
86
|
+
</div>
|
|
87
|
+
{action && (
|
|
88
|
+
<span className="ml-auto inline-flex h-6 shrink-0 items-center rounded-control bg-popover-foreground px-2 text-body-12-semibold text-popover">
|
|
89
|
+
{action}
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
{/* O X do Toaster, só desenho, D-772. */}
|
|
93
|
+
<XIcon aria-hidden className="absolute top-3 right-3 size-icon-solo text-muted-foreground" />
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Aviso de notificação no canto da tela, D-699: chega uma mensagem ou um pedido, sobe o cartão com
|
|
100
|
+
* a foto de quem fez, o que foi e, se houver, as ações, como Recusar e Aceitar.
|
|
101
|
+
*/
|
|
102
|
+
function notify({
|
|
103
|
+
person,
|
|
104
|
+
title,
|
|
105
|
+
description,
|
|
106
|
+
accept,
|
|
107
|
+
decline,
|
|
108
|
+
onDecide,
|
|
109
|
+
onOpen,
|
|
110
|
+
}: {
|
|
111
|
+
person: { name: string; src?: string };
|
|
112
|
+
title: React.ReactNode;
|
|
113
|
+
description?: React.ReactNode;
|
|
114
|
+
accept?: string;
|
|
115
|
+
decline?: string;
|
|
116
|
+
onDecide?: (accepted: boolean) => void;
|
|
117
|
+
onOpen?: () => void;
|
|
118
|
+
}) {
|
|
119
|
+
return toast.custom(
|
|
120
|
+
(id) => (
|
|
121
|
+
<div
|
|
122
|
+
data-slot="notification-toast"
|
|
123
|
+
className="relative flex w-[356px] max-w-full items-start gap-3 rounded-card border bg-popover p-3 pr-12 text-popover-foreground shadow-popup"
|
|
124
|
+
>
|
|
125
|
+
{/* D-772: o X no canto, para fechar sem decidir. */}
|
|
126
|
+
<Button
|
|
127
|
+
variant="ghost"
|
|
128
|
+
size="icon-sm"
|
|
129
|
+
aria-label="Fechar aviso"
|
|
130
|
+
className="absolute top-1.5 right-1.5 text-muted-foreground"
|
|
131
|
+
onClick={() => toast.dismiss(id)}
|
|
132
|
+
>
|
|
133
|
+
<XIcon />
|
|
134
|
+
</Button>
|
|
135
|
+
<Avatar name={person.name} src={person.src} aria-hidden />
|
|
136
|
+
<div className="grid min-w-0 flex-1 gap-0.5">
|
|
137
|
+
<button
|
|
138
|
+
type="button"
|
|
139
|
+
className="text-left text-body-13-medium outline-none focus-visible:focus-ring"
|
|
140
|
+
onClick={() => {
|
|
141
|
+
onOpen?.();
|
|
142
|
+
toast.dismiss(id);
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{title}
|
|
146
|
+
</button>
|
|
147
|
+
{description && <span className="text-body-12 text-muted-foreground">{description}</span>}
|
|
148
|
+
{accept && onDecide && (
|
|
149
|
+
<span className="mt-1.5 flex gap-2">
|
|
150
|
+
<Button
|
|
151
|
+
variant="secondary"
|
|
152
|
+
size="xs"
|
|
153
|
+
onClick={() => {
|
|
154
|
+
onDecide(false);
|
|
155
|
+
toast.dismiss(id);
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
{decline ?? 'Recusar'}
|
|
159
|
+
</Button>
|
|
160
|
+
<Button
|
|
161
|
+
size="xs"
|
|
162
|
+
onClick={() => {
|
|
163
|
+
onDecide(true);
|
|
164
|
+
toast.dismiss(id);
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
{accept}
|
|
168
|
+
</Button>
|
|
169
|
+
</span>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
),
|
|
174
|
+
{ duration: accept ? 10000 : 5000 },
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { Toaster, ToastPreview, notify, toast };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Area, AreaChart, Bar, BarChart, ResponsiveContainer, YAxis } from 'recharts';
|
|
4
|
+
import { useId } from 'react';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
|
|
7
|
+
// Linha pequena, sem eixo nem grade (D-156): a tendência dentro de um card de número ou de uma
|
|
8
|
+
// linha da tabela. Só mostra o desenho; o número fica escrito ao lado.
|
|
9
|
+
|
|
10
|
+
function Sparkline({
|
|
11
|
+
data,
|
|
12
|
+
type = 'area',
|
|
13
|
+
color = 'var(--chart-1)',
|
|
14
|
+
className,
|
|
15
|
+
'aria-label': ariaLabel,
|
|
16
|
+
}: {
|
|
17
|
+
data: number[];
|
|
18
|
+
type?: 'area' | 'bar';
|
|
19
|
+
color?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
/** O que a linha mostra, como "Vendas dos últimos 14 dias, subindo". */
|
|
22
|
+
'aria-label': string;
|
|
23
|
+
}) {
|
|
24
|
+
const id = useId().replace(/:/g, '');
|
|
25
|
+
const rows = data.map((v, i) => ({ i, v }));
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
data-slot="sparkline"
|
|
29
|
+
role="img"
|
|
30
|
+
aria-label={ariaLabel}
|
|
31
|
+
className={cn('h-10 w-28', className)}
|
|
32
|
+
>
|
|
33
|
+
<ResponsiveContainer>
|
|
34
|
+
{type === 'bar' ? (
|
|
35
|
+
<BarChart
|
|
36
|
+
data={rows}
|
|
37
|
+
margin={{ top: 2, right: 0, left: 0, bottom: 0 }}
|
|
38
|
+
barCategoryGap={2}
|
|
39
|
+
>
|
|
40
|
+
<YAxis hide domain={[0, 'dataMax']} />
|
|
41
|
+
<Bar dataKey="v" fill={color} radius={[2, 2, 0, 0]} isAnimationActive={false} />
|
|
42
|
+
</BarChart>
|
|
43
|
+
) : (
|
|
44
|
+
<AreaChart data={rows} margin={{ top: 2, right: 2, left: 2, bottom: 2 }}>
|
|
45
|
+
<defs>
|
|
46
|
+
<linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
|
|
47
|
+
<stop offset="0%" stopColor={color} stopOpacity={0.25} />
|
|
48
|
+
<stop offset="100%" stopColor={color} stopOpacity={0} />
|
|
49
|
+
</linearGradient>
|
|
50
|
+
</defs>
|
|
51
|
+
<YAxis hide domain={['dataMin', 'dataMax']} />
|
|
52
|
+
<Area
|
|
53
|
+
dataKey="v"
|
|
54
|
+
type="monotone"
|
|
55
|
+
stroke={color}
|
|
56
|
+
strokeWidth={1.5}
|
|
57
|
+
fill={`url(#${id})`}
|
|
58
|
+
isAnimationActive={false}
|
|
59
|
+
dot={false}
|
|
60
|
+
/>
|
|
61
|
+
</AreaChart>
|
|
62
|
+
)}
|
|
63
|
+
</ResponsiveContainer>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { Sparkline };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
|
|
4
|
+
// Carregando: um anel em degradê que não fecha, do transparente à cor cheia, girando (D-148).
|
|
5
|
+
// A cor vem do texto, como os ícones. Sozinho, avisa o leitor de tela com "Carregando"; dentro de um
|
|
6
|
+
// botão, o texto do botão já diz o que está acontecendo: use label="" e ele fica mudo, sem o papel
|
|
7
|
+
// de status. O tamanho segue o dos ícones do Button e do Badge em que estiver, pela variável
|
|
8
|
+
// --spinner-size; uma classe size-* no próprio Spinner ainda manda.
|
|
9
|
+
function Spinner({
|
|
10
|
+
className,
|
|
11
|
+
label = 'Carregando',
|
|
12
|
+
style,
|
|
13
|
+
...props
|
|
14
|
+
}: React.ComponentProps<'span'> & { label?: string }) {
|
|
15
|
+
return (
|
|
16
|
+
<span
|
|
17
|
+
data-slot="spinner"
|
|
18
|
+
role={label ? 'status' : undefined}
|
|
19
|
+
aria-label={label || undefined}
|
|
20
|
+
aria-hidden={label ? undefined : true}
|
|
21
|
+
className={cn(
|
|
22
|
+
'inline-block size-[var(--spinner-size,1rem)] shrink-0 animate-spin rounded-full',
|
|
23
|
+
className,
|
|
24
|
+
)}
|
|
25
|
+
style={{
|
|
26
|
+
background: 'conic-gradient(from 0deg, transparent 0 12%, currentColor)',
|
|
27
|
+
mask: 'radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px))',
|
|
28
|
+
...style,
|
|
29
|
+
}}
|
|
30
|
+
{...props}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { Spinner };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
|
|
4
|
+
// Situação de algo, com um ponto colorido e o texto ao lado: "Online", "Sincronizando", "Falhou".
|
|
5
|
+
// O texto é obrigatório, porque a cor sozinha não basta.
|
|
6
|
+
|
|
7
|
+
const TONES = {
|
|
8
|
+
neutral: 'bg-icon-secondary',
|
|
9
|
+
success: 'bg-icon-success',
|
|
10
|
+
warning: 'bg-icon-warning',
|
|
11
|
+
error: 'bg-icon-error',
|
|
12
|
+
info: 'bg-icon-info',
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
function StatusDot({
|
|
16
|
+
tone = 'neutral',
|
|
17
|
+
pulse = false,
|
|
18
|
+
children,
|
|
19
|
+
className,
|
|
20
|
+
}: {
|
|
21
|
+
tone?: keyof typeof TONES;
|
|
22
|
+
/** Pulsa enquanto algo acontece agora, como uma sincronização. */
|
|
23
|
+
pulse?: boolean;
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
className?: string;
|
|
26
|
+
}) {
|
|
27
|
+
return (
|
|
28
|
+
<span
|
|
29
|
+
data-slot="status-dot"
|
|
30
|
+
className={cn('inline-flex items-center gap-2 text-body-13', className)}
|
|
31
|
+
>
|
|
32
|
+
<span className="relative flex size-2 shrink-0">
|
|
33
|
+
{pulse && (
|
|
34
|
+
<span
|
|
35
|
+
className={cn('absolute inset-0 animate-ping rounded-full opacity-60', TONES[tone])}
|
|
36
|
+
/>
|
|
37
|
+
)}
|
|
38
|
+
<span className={cn('relative size-2 rounded-full', TONES[tone])} />
|
|
39
|
+
</span>
|
|
40
|
+
{children}
|
|
41
|
+
</span>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { StatusDot };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CheckIcon } from 'lucide-react';
|
|
3
|
+
import { cn } from '../lib/utils';
|
|
4
|
+
|
|
5
|
+
// tokens-ok-ligacao: estrutura e tokens; o nome da etapa vira botão só quando o app pede, como texto clicável.
|
|
6
|
+
|
|
7
|
+
// Etapas em ordem, como as de um pedido (Pago, Separado, Enviado, Entregue) ou de um cadastro.
|
|
8
|
+
// Mostra o que já foi feito, a etapa de agora e o que falta. Com `order="newest-first"`, a lista
|
|
9
|
+
// aparece do mais novo para o mais antigo, como o rastreio de uma entrega: a etapa de agora em cima.
|
|
10
|
+
// As etapas continuam na ordem do tempo em `steps` e `current`; só o desenho inverte.
|
|
11
|
+
// Com `onStepClick`, D-342, o nome de cada etapa vira botão, como na barra de etapas do negócio.
|
|
12
|
+
// Com `align="center"`, no horizontal, o nome fica centralizado embaixo do círculo.
|
|
13
|
+
// Com `variant="bar"`, D-660, cada etapa vira uma faixa na sua cor, cheia até a etapa de agora,
|
|
14
|
+
// como a barra de etapas do negócio; as cores vêm em `colors`, na ordem das etapas.
|
|
15
|
+
|
|
16
|
+
export type Step = { title: React.ReactNode; description?: React.ReactNode };
|
|
17
|
+
|
|
18
|
+
function Stepper({
|
|
19
|
+
steps,
|
|
20
|
+
current,
|
|
21
|
+
orientation = 'horizontal',
|
|
22
|
+
order = 'oldest-first',
|
|
23
|
+
onStepClick,
|
|
24
|
+
align = 'start',
|
|
25
|
+
variant = 'default',
|
|
26
|
+
colors,
|
|
27
|
+
className,
|
|
28
|
+
}: {
|
|
29
|
+
steps: Step[];
|
|
30
|
+
/** Índice da etapa de agora, começando em 0. Igual ao total quando tudo terminou. */
|
|
31
|
+
current: number;
|
|
32
|
+
orientation?: 'horizontal' | 'vertical';
|
|
33
|
+
/** Ordem do desenho: da primeira etapa à última, ou da mais nova à mais antiga. */
|
|
34
|
+
order?: 'oldest-first' | 'newest-first';
|
|
35
|
+
/** Tocar no nome da etapa, como mover o negócio para ela. */
|
|
36
|
+
onStepClick?: (index: number) => void;
|
|
37
|
+
/** No horizontal: nome à esquerda, alinhado ao círculo, ou centralizado embaixo dele. */
|
|
38
|
+
align?: 'start' | 'center';
|
|
39
|
+
/** `bar`: faixas coloridas lado a lado, uma por etapa. */
|
|
40
|
+
variant?: 'default' | 'bar';
|
|
41
|
+
/** Cor de cada etapa no `bar`, como var(--chart-1). Sem ela, a cor de seleção. */
|
|
42
|
+
colors?: string[];
|
|
43
|
+
className?: string;
|
|
44
|
+
}) {
|
|
45
|
+
if (variant === 'bar')
|
|
46
|
+
return (
|
|
47
|
+
<ol
|
|
48
|
+
data-slot="stepper"
|
|
49
|
+
data-variant="bar"
|
|
50
|
+
className={cn('grid auto-cols-fr grid-flow-col', className)}
|
|
51
|
+
>
|
|
52
|
+
{steps.map((step, i) => {
|
|
53
|
+
const state = i < current ? 'done' : i === current ? 'current' : 'upcoming';
|
|
54
|
+
const filled = state !== 'upcoming';
|
|
55
|
+
const body = (
|
|
56
|
+
<>
|
|
57
|
+
<span
|
|
58
|
+
aria-hidden
|
|
59
|
+
// D-663: faixas coladas, sem divisão; só as pontas da barra arredondam.
|
|
60
|
+
className={cn(
|
|
61
|
+
'block h-2 group-first/bar:rounded-l-full group-last/bar:rounded-r-full',
|
|
62
|
+
filled ? 'bg-selected-strong' : 'bg-muted dark:bg-surface-strong',
|
|
63
|
+
)}
|
|
64
|
+
style={
|
|
65
|
+
filled && colors?.length ? { background: colors[i % colors.length] } : undefined
|
|
66
|
+
}
|
|
67
|
+
/>
|
|
68
|
+
<span
|
|
69
|
+
className={cn(
|
|
70
|
+
'flex min-w-0 items-center gap-1 pr-2 text-body-12-medium',
|
|
71
|
+
!filled && 'text-muted-foreground',
|
|
72
|
+
state === 'current' && 'text-body-12-semibold',
|
|
73
|
+
)}
|
|
74
|
+
>
|
|
75
|
+
{state === 'done' && (
|
|
76
|
+
<CheckIcon aria-hidden data-weight="bold" className="size-icon-xs shrink-0" />
|
|
77
|
+
)}
|
|
78
|
+
<span className="truncate">{step.title}</span>
|
|
79
|
+
</span>
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
return (
|
|
83
|
+
<li
|
|
84
|
+
key={i}
|
|
85
|
+
data-state={state}
|
|
86
|
+
aria-current={state === 'current' ? 'step' : undefined}
|
|
87
|
+
className="group/bar min-w-0"
|
|
88
|
+
>
|
|
89
|
+
{onStepClick ? (
|
|
90
|
+
<button
|
|
91
|
+
type="button"
|
|
92
|
+
onClick={() => onStepClick(i)}
|
|
93
|
+
className="grid w-full gap-1.5 rounded-small text-left outline-none hover:opacity-80 focus-visible:focus-ring"
|
|
94
|
+
>
|
|
95
|
+
{body}
|
|
96
|
+
</button>
|
|
97
|
+
) : (
|
|
98
|
+
<div className="grid gap-1.5">{body}</div>
|
|
99
|
+
)}
|
|
100
|
+
</li>
|
|
101
|
+
);
|
|
102
|
+
})}
|
|
103
|
+
</ol>
|
|
104
|
+
);
|
|
105
|
+
const newestFirst = order === 'newest-first';
|
|
106
|
+
const indexes = steps.map((_, i) => i);
|
|
107
|
+
if (newestFirst) indexes.reverse();
|
|
108
|
+
const center = orientation === 'horizontal' && align === 'center';
|
|
109
|
+
const horizontalStart = orientation === 'horizontal' && !center;
|
|
110
|
+
return (
|
|
111
|
+
<ol
|
|
112
|
+
data-slot="stepper"
|
|
113
|
+
data-orientation={orientation}
|
|
114
|
+
data-order={order}
|
|
115
|
+
data-align={center ? 'center' : 'start'}
|
|
116
|
+
className={cn(
|
|
117
|
+
'flex',
|
|
118
|
+
orientation === 'vertical'
|
|
119
|
+
? 'flex-col'
|
|
120
|
+
: center
|
|
121
|
+
? 'flex-nowrap'
|
|
122
|
+
: // No celular, o horizontal passa a vertical, para os nomes e as datas não se colarem.
|
|
123
|
+
// A partir do sm, sem espaço entre as etapas: a linha fica a 8px de cada círculo.
|
|
124
|
+
'flex-col sm:flex-row sm:flex-nowrap',
|
|
125
|
+
className,
|
|
126
|
+
)}
|
|
127
|
+
>
|
|
128
|
+
{indexes.map((i, position) => {
|
|
129
|
+
const step = steps[i]!;
|
|
130
|
+
const state = i < current ? 'done' : i === current ? 'current' : 'upcoming';
|
|
131
|
+
const last = position === steps.length - 1;
|
|
132
|
+
// A linha liga esta etapa à de baixo; fica cheia quando o trecho entre as duas já passou.
|
|
133
|
+
const lineDone = newestFirst ? i <= current : i < current;
|
|
134
|
+
return (
|
|
135
|
+
<li
|
|
136
|
+
key={i}
|
|
137
|
+
data-state={state}
|
|
138
|
+
aria-current={state === 'current' ? 'step' : undefined}
|
|
139
|
+
className={cn(
|
|
140
|
+
'relative flex min-w-0 gap-3',
|
|
141
|
+
orientation === 'vertical'
|
|
142
|
+
? 'group/step'
|
|
143
|
+
: center
|
|
144
|
+
? 'flex-1 flex-col items-center'
|
|
145
|
+
: // D-654: a última etapa só ocupa o próprio tamanho, e a linha chega até ela.
|
|
146
|
+
cn('group/step sm:flex-col', last ? 'sm:flex-none' : 'sm:min-w-28 sm:flex-1'),
|
|
147
|
+
)}
|
|
148
|
+
>
|
|
149
|
+
<div
|
|
150
|
+
className={cn(
|
|
151
|
+
'flex items-center',
|
|
152
|
+
orientation === 'vertical' && 'flex-col',
|
|
153
|
+
horizontalStart && 'max-sm:flex-col',
|
|
154
|
+
)}
|
|
155
|
+
>
|
|
156
|
+
<span
|
|
157
|
+
className={cn(
|
|
158
|
+
'flex size-7 shrink-0 items-center justify-center rounded-full border text-body-12-semibold tabular-nums',
|
|
159
|
+
state === 'done' &&
|
|
160
|
+
'border-selected-strong bg-selected-strong text-selected-strong-foreground',
|
|
161
|
+
state === 'current' && 'border-2 border-selected-strong text-foreground',
|
|
162
|
+
state === 'upcoming' && 'text-muted-foreground',
|
|
163
|
+
)}
|
|
164
|
+
>
|
|
165
|
+
{state === 'done' ? (
|
|
166
|
+
<CheckIcon aria-hidden data-weight="bold" className="size-icon-sm" />
|
|
167
|
+
) : (
|
|
168
|
+
i + 1
|
|
169
|
+
)}
|
|
170
|
+
</span>
|
|
171
|
+
{!last && (
|
|
172
|
+
<span
|
|
173
|
+
aria-hidden
|
|
174
|
+
className={cn(
|
|
175
|
+
orientation === 'vertical'
|
|
176
|
+
? 'my-1 w-0.5 flex-1'
|
|
177
|
+
: center
|
|
178
|
+
? // Do meio desta etapa ao meio da próxima, a 8px de cada círculo de 28.
|
|
179
|
+
'absolute top-3.5 right-[calc(-50%+1.375rem)] left-[calc(50%+1.375rem)] h-0.5 -translate-y-1/2'
|
|
180
|
+
: 'my-1 w-0.5 flex-1 sm:mx-2 sm:my-0 sm:h-0.5 sm:w-auto',
|
|
181
|
+
lineDone ? 'bg-selected-strong' : 'bg-border',
|
|
182
|
+
)}
|
|
183
|
+
/>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
{/* No vertical, o espaço fica no texto, para a linha entre as etapas ir até a próxima. */}
|
|
187
|
+
<div
|
|
188
|
+
className={cn(
|
|
189
|
+
'grid min-w-0 content-start gap-0.5',
|
|
190
|
+
center ? 'justify-items-center px-1 text-center' : 'pr-2',
|
|
191
|
+
orientation === 'vertical' && 'pb-6 group-last/step:pb-0',
|
|
192
|
+
horizontalStart && 'max-sm:pb-6 max-sm:group-last/step:pb-0',
|
|
193
|
+
)}
|
|
194
|
+
>
|
|
195
|
+
{onStepClick ? (
|
|
196
|
+
<button
|
|
197
|
+
type="button"
|
|
198
|
+
onClick={() => onStepClick(i)}
|
|
199
|
+
className={cn(
|
|
200
|
+
'w-fit rounded-small text-body-13-medium underline-offset-4 outline-none hover:underline focus-visible:focus-ring',
|
|
201
|
+
center ? 'text-center' : 'text-left',
|
|
202
|
+
state === 'upcoming' && 'text-muted-foreground',
|
|
203
|
+
)}
|
|
204
|
+
>
|
|
205
|
+
{step.title}
|
|
206
|
+
</button>
|
|
207
|
+
) : (
|
|
208
|
+
<span
|
|
209
|
+
className={cn(
|
|
210
|
+
'text-body-13-medium',
|
|
211
|
+
state === 'upcoming' && 'text-muted-foreground',
|
|
212
|
+
)}
|
|
213
|
+
>
|
|
214
|
+
{step.title}
|
|
215
|
+
</span>
|
|
216
|
+
)}
|
|
217
|
+
{step.description && (
|
|
218
|
+
<span className="text-body-13 text-muted-foreground">{step.description}</span>
|
|
219
|
+
)}
|
|
220
|
+
</div>
|
|
221
|
+
</li>
|
|
222
|
+
);
|
|
223
|
+
})}
|
|
224
|
+
</ol>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { Stepper };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Switch as SwitchPrimitive } from '@base-ui/react/switch';
|
|
4
|
+
import { cn } from '../lib/utils';
|
|
5
|
+
|
|
6
|
+
// Trilho de 38 por 22 com bolinha de 18 e folga de 2px (D-175); o pequeno, 30 por 18.
|
|
7
|
+
// Acessibilidade: nos controles do Base UI o `id` vai para um campo invisível; o elemento
|
|
8
|
+
// que a pessoa usa recebe o nome pelo rótulo `${id}-label` (que o Label cria sozinho com o htmlFor).
|
|
9
|
+
function Switch({
|
|
10
|
+
className,
|
|
11
|
+
size = 'default',
|
|
12
|
+
...props
|
|
13
|
+
}: SwitchPrimitive.Root.Props & {
|
|
14
|
+
size?: 'sm' | 'default' | 'lg';
|
|
15
|
+
}) {
|
|
16
|
+
return (
|
|
17
|
+
<SwitchPrimitive.Root
|
|
18
|
+
data-slot="switch"
|
|
19
|
+
aria-labelledby={props.id && !props['aria-label'] ? `${props.id}-label` : undefined}
|
|
20
|
+
data-size={size}
|
|
21
|
+
className={cn(
|
|
22
|
+
'peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring-strong focus-visible:focus-ring aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-ring-invalid p-px data-[size=default]:h-5.5 data-[size=default]:w-9.5 data-[size=sm]:h-4.5 data-[size=sm]:w-7.5 data-[size=lg]:h-6.5 data-[size=lg]:w-11.5 dark:aria-invalid:border-border-error data-checked:bg-selected-strong data-unchecked:bg-border-strong data-disabled:cursor-not-allowed data-disabled:opacity-50',
|
|
23
|
+
className,
|
|
24
|
+
)}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
27
|
+
<SwitchPrimitive.Thumb
|
|
28
|
+
data-slot="switch-thumb"
|
|
29
|
+
className="pointer-events-none block rounded-full bg-card shadow-raised ring-0 transition-transform group-data-[size=default]/switch:size-4.5 group-data-[size=sm]/switch:size-3.5 group-data-[size=lg]/switch:size-5.5 group-data-[size=default]/switch:data-checked:translate-x-4 group-data-[size=sm]/switch:data-checked:translate-x-3 group-data-[size=lg]/switch:data-checked:translate-x-5 dark:data-checked:bg-selected-strong-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 group-data-[size=lg]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground"
|
|
30
|
+
/>
|
|
31
|
+
</SwitchPrimitive.Root>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { Switch };
|