@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,289 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Legend, ResponsiveContainer, Tooltip } from 'recharts';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
|
|
7
|
+
// Base dos gráficos, sobre a Recharts: cores do tema, balão de detalhe e legenda da VOWT. O app
|
|
8
|
+
// monta o gráfico com as peças da Recharts (LineChart, BarChart, Area...) dentro do ChartContainer
|
|
9
|
+
// e usa as cores pelo nome da série: stroke="var(--color-vendas)".
|
|
10
|
+
//
|
|
11
|
+
// Legenda que liga e desliga: quando o filho do ChartContainer é uma função, ela recebe as séries
|
|
12
|
+
// escondidas e cada item da legenda vira um botão. O gráfico esconde a série com `hide`. Pelo
|
|
13
|
+
// menos uma série fica sempre à vista.
|
|
14
|
+
|
|
15
|
+
export type ChartConfig = Record<string, { label: string; color: string }>;
|
|
16
|
+
|
|
17
|
+
const ChartContext = React.createContext<ChartConfig>({});
|
|
18
|
+
|
|
19
|
+
type HiddenState = {
|
|
20
|
+
hidden: ReadonlySet<string>;
|
|
21
|
+
/** Só existe quando o gráfico respeita as séries escondidas. */
|
|
22
|
+
toggle?: (key: string, keys: string[]) => void;
|
|
23
|
+
};
|
|
24
|
+
const HiddenContext = React.createContext<HiddenState>({ hidden: new Set() });
|
|
25
|
+
|
|
26
|
+
function ChartContainer({
|
|
27
|
+
config,
|
|
28
|
+
className,
|
|
29
|
+
children,
|
|
30
|
+
}: {
|
|
31
|
+
config: ChartConfig;
|
|
32
|
+
className?: string;
|
|
33
|
+
/** O gráfico, ou uma função que recebe as séries escondidas pela legenda e devolve o gráfico. */
|
|
34
|
+
children: React.ReactElement | ((hidden: ReadonlySet<string>) => React.ReactElement);
|
|
35
|
+
}) {
|
|
36
|
+
const [hidden, setHidden] = React.useState<ReadonlySet<string>>(() => new Set());
|
|
37
|
+
const interactive = typeof children === 'function';
|
|
38
|
+
const toggle = React.useCallback(
|
|
39
|
+
(key: string, keys: string[]) =>
|
|
40
|
+
setHidden((prev) => {
|
|
41
|
+
const next = new Set(prev);
|
|
42
|
+
if (next.has(key)) next.delete(key);
|
|
43
|
+
else if (keys.filter((k) => !prev.has(k)).length > 1) next.add(key);
|
|
44
|
+
else return prev;
|
|
45
|
+
return next;
|
|
46
|
+
}),
|
|
47
|
+
[],
|
|
48
|
+
);
|
|
49
|
+
const legend = React.useMemo<HiddenState>(
|
|
50
|
+
() => ({ hidden, toggle: interactive ? toggle : undefined }),
|
|
51
|
+
[hidden, interactive, toggle],
|
|
52
|
+
);
|
|
53
|
+
const vars = Object.fromEntries(
|
|
54
|
+
Object.entries(config).map(([key, v]) => [`--color-${key}`, v.color]),
|
|
55
|
+
) as React.CSSProperties;
|
|
56
|
+
return (
|
|
57
|
+
<ChartContext.Provider value={config}>
|
|
58
|
+
<HiddenContext.Provider value={legend}>
|
|
59
|
+
<div
|
|
60
|
+
data-slot="chart"
|
|
61
|
+
style={vars}
|
|
62
|
+
className={cn(
|
|
63
|
+
'aspect-video w-full text-body-12 [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line]:stroke-border [&_.recharts-surface]:outline-hidden [&_.recharts-tooltip-cursor]:stroke-border [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-hover [&_.recharts-rectangle.recharts-tooltip-cursor]:stroke-transparent',
|
|
64
|
+
className,
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
<ResponsiveContainer>
|
|
68
|
+
{typeof children === 'function' ? children(hidden) : children}
|
|
69
|
+
</ResponsiveContainer>
|
|
70
|
+
</div>
|
|
71
|
+
</HiddenContext.Provider>
|
|
72
|
+
</ChartContext.Provider>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type TooltipItem = {
|
|
77
|
+
dataKey?: string | number;
|
|
78
|
+
name?: string | number;
|
|
79
|
+
value?: unknown;
|
|
80
|
+
color?: string;
|
|
81
|
+
payload?: { key?: string | number };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Nome da série do item. Na pizza, cada fatia vem como "value"; o nome dela está em payload.key.
|
|
85
|
+
const baseKey = (item: TooltipItem, fallback?: unknown) => {
|
|
86
|
+
const slice = item.payload?.key;
|
|
87
|
+
const raw =
|
|
88
|
+
item.dataKey === 'value' && slice !== undefined
|
|
89
|
+
? slice
|
|
90
|
+
: (item.dataKey ?? fallback ?? item.name);
|
|
91
|
+
return String(raw).replace(/__(done|open)$/, '');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function ChartTooltipContent({
|
|
95
|
+
active,
|
|
96
|
+
payload,
|
|
97
|
+
label,
|
|
98
|
+
formatValue = (v) => (typeof v === 'number' ? v.toLocaleString('pt-BR') : String(v)),
|
|
99
|
+
}: {
|
|
100
|
+
active?: boolean;
|
|
101
|
+
payload?: TooltipItem[];
|
|
102
|
+
label?: React.ReactNode;
|
|
103
|
+
/** Recebe o valor e a série, para formatar cada série do seu jeito, como R$ e quantidade. */
|
|
104
|
+
formatValue?: (value: unknown, key: string) => string;
|
|
105
|
+
}) {
|
|
106
|
+
const config = React.useContext(ChartContext);
|
|
107
|
+
const { hidden } = React.useContext(HiddenContext);
|
|
108
|
+
if (!active || !payload?.length) return null;
|
|
109
|
+
// A área com o fim tracejado desenha a série duas vezes; no balão ela aparece uma só.
|
|
110
|
+
const seen = new Set<string>();
|
|
111
|
+
const items = payload.filter((item) => {
|
|
112
|
+
const key = baseKey(item);
|
|
113
|
+
if (seen.has(key) || hidden.has(key) || item.value === null || item.value === undefined)
|
|
114
|
+
return false;
|
|
115
|
+
seen.add(key);
|
|
116
|
+
return true;
|
|
117
|
+
});
|
|
118
|
+
return (
|
|
119
|
+
<div className="grid min-w-36 gap-1.5 rounded-menu bg-popover px-2.5 py-2 text-body-12 text-popover-foreground shadow-menu ring-1 ring-border">
|
|
120
|
+
{label !== undefined && <div className="text-body-12-semibold">{label}</div>}
|
|
121
|
+
{items.map((item) => {
|
|
122
|
+
const key = baseKey(item);
|
|
123
|
+
return (
|
|
124
|
+
<div key={key} className="flex items-center gap-2">
|
|
125
|
+
<span
|
|
126
|
+
// tokens-ok: marca de legenda do gráfico, menor que o menor canto da escala
|
|
127
|
+
className="size-2.5 shrink-0 rounded-[3px]"
|
|
128
|
+
style={{ background: config[key]?.color ?? item.color }}
|
|
129
|
+
/>
|
|
130
|
+
<span className="flex-1 text-muted-foreground">{config[key]?.label ?? key}</span>
|
|
131
|
+
<span className="text-body-12-semibold tabular-nums">
|
|
132
|
+
{formatValue(item.value, key)}
|
|
133
|
+
</span>
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
})}
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Balão de detalhe da VOWT. Use dentro do gráfico: <ChartTooltip />. */
|
|
142
|
+
function ChartTooltip({ formatValue }: { formatValue?: (value: unknown, key: string) => string }) {
|
|
143
|
+
return (
|
|
144
|
+
<Tooltip
|
|
145
|
+
cursor={{ strokeDasharray: '3 3' }}
|
|
146
|
+
content={(props) => (
|
|
147
|
+
<ChartTooltipContent
|
|
148
|
+
active={props.active}
|
|
149
|
+
payload={props.payload as unknown as TooltipItem[] | undefined}
|
|
150
|
+
label={props.label as React.ReactNode}
|
|
151
|
+
formatValue={formatValue}
|
|
152
|
+
/>
|
|
153
|
+
)}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function ChartLegendContent({ payload }: { payload?: TooltipItem[] }) {
|
|
159
|
+
const config = React.useContext(ChartContext);
|
|
160
|
+
const { hidden, toggle } = React.useContext(HiddenContext);
|
|
161
|
+
// As séries vêm do config, na ordem dele; sem config, do que a Recharts mandou.
|
|
162
|
+
const keys = Object.keys(config).length
|
|
163
|
+
? Object.keys(config)
|
|
164
|
+
: Array.from(
|
|
165
|
+
new Set(
|
|
166
|
+
(payload ?? []).filter((i) => i.value !== undefined).map((i) => baseKey(i, i.value)),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
if (!keys.length) return null;
|
|
170
|
+
const visible = keys.filter((k) => !hidden.has(k)).length;
|
|
171
|
+
return (
|
|
172
|
+
<div className="flex flex-wrap items-center justify-center gap-x-3 gap-y-1 pt-3">
|
|
173
|
+
{keys.map((key) => {
|
|
174
|
+
const off = hidden.has(key);
|
|
175
|
+
const item = payload?.find((i) => baseKey(i, i.value) === key);
|
|
176
|
+
const mark = (
|
|
177
|
+
<span
|
|
178
|
+
className={cn(
|
|
179
|
+
// tokens-ok: marca de legenda do gráfico, menor que o menor canto da escala
|
|
180
|
+
'size-2.5 shrink-0 rounded-[3px] transition-opacity',
|
|
181
|
+
off && 'opacity-30',
|
|
182
|
+
)}
|
|
183
|
+
style={{ background: config[key]?.color ?? item?.color }}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
const name = config[key]?.label ?? key;
|
|
187
|
+
if (!toggle)
|
|
188
|
+
return (
|
|
189
|
+
<div key={key} className="flex items-center gap-1.5 text-body-12 text-muted-foreground">
|
|
190
|
+
{mark}
|
|
191
|
+
{name}
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
// A última série à vista não desliga: o gráfico nunca fica vazio.
|
|
195
|
+
const locked = !off && visible === 1;
|
|
196
|
+
return (
|
|
197
|
+
<button
|
|
198
|
+
key={key}
|
|
199
|
+
type="button"
|
|
200
|
+
aria-pressed={!off}
|
|
201
|
+
aria-disabled={locked || undefined}
|
|
202
|
+
title={locked ? 'Pelo menos uma série fica à vista' : undefined}
|
|
203
|
+
onClick={() => !locked && toggle(key, keys)}
|
|
204
|
+
className={cn(
|
|
205
|
+
'flex items-center gap-1.5 rounded-control px-1.5 py-0.5 text-body-12 text-muted-foreground outline-none transition-colors hover:bg-hover hover:text-foreground focus-visible:focus-ring aria-disabled:cursor-default aria-disabled:hover:bg-transparent',
|
|
206
|
+
off && 'line-through',
|
|
207
|
+
)}
|
|
208
|
+
>
|
|
209
|
+
{mark}
|
|
210
|
+
{name}
|
|
211
|
+
</button>
|
|
212
|
+
);
|
|
213
|
+
})}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Legenda da VOWT. Use dentro do gráfico: <ChartLegend />. */
|
|
219
|
+
function ChartLegend() {
|
|
220
|
+
return (
|
|
221
|
+
<Legend
|
|
222
|
+
// Na ordem das séries, não em ordem alfabética.
|
|
223
|
+
itemSorter={null}
|
|
224
|
+
content={(props) => (
|
|
225
|
+
<ChartLegendContent payload={props.payload as unknown as TooltipItem[] | undefined} />
|
|
226
|
+
)}
|
|
227
|
+
/>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Peças comuns dos gráficos prontos (D-156): a série, a cor de cada série na ordem fixa do tema e
|
|
232
|
+
// o formato dos números. A cor segue a série, nunca a posição: filtrar não repinta as outras.
|
|
233
|
+
export type ChartSeries = {
|
|
234
|
+
key: string;
|
|
235
|
+
label: string;
|
|
236
|
+
/** Sem cor, usa chart-1 a chart-5 na ordem das séries. */
|
|
237
|
+
color?: string;
|
|
238
|
+
/** Linha tracejada, como o período anterior numa comparação. */
|
|
239
|
+
dashed?: boolean;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export type ChartDatum = Record<string, string | number | null | undefined>;
|
|
243
|
+
|
|
244
|
+
const CHART_COLORS = [
|
|
245
|
+
'var(--chart-1)',
|
|
246
|
+
'var(--chart-2)',
|
|
247
|
+
'var(--chart-3)',
|
|
248
|
+
'var(--chart-4)',
|
|
249
|
+
'var(--chart-5)',
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
/** Monta o ChartConfig das séries, com a cor de cada uma. Mais de 5 séries é sinal de juntar em "Outros". */
|
|
253
|
+
function seriesConfig(series: ChartSeries[]): ChartConfig {
|
|
254
|
+
return Object.fromEntries(
|
|
255
|
+
series.map((s, i) => [
|
|
256
|
+
s.key,
|
|
257
|
+
{ label: s.label, color: s.color ?? CHART_COLORS[i % CHART_COLORS.length]! },
|
|
258
|
+
]),
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const formatNumber = (v: unknown) =>
|
|
263
|
+
typeof v === 'number' ? v.toLocaleString('pt-BR') : String(v ?? '');
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Entrada dos gráficos: curta e sem espera, para o desenho não ficar pela metade enquanto a
|
|
267
|
+
* página abre. Quem pede menos movimento no sistema já vê tudo pronto: a Recharts não anima.
|
|
268
|
+
*/
|
|
269
|
+
const CHART_ANIMATION = { animationBegin: 0, animationDuration: 500 } as const;
|
|
270
|
+
|
|
271
|
+
/** Eixos discretos, iguais em todo gráfico. */
|
|
272
|
+
const AXIS = {
|
|
273
|
+
tickLine: false,
|
|
274
|
+
axisLine: false,
|
|
275
|
+
tickMargin: 8,
|
|
276
|
+
tick: { className: 'fill-muted-foreground text-body-12' },
|
|
277
|
+
} as const;
|
|
278
|
+
|
|
279
|
+
export {
|
|
280
|
+
ChartContainer,
|
|
281
|
+
ChartTooltip,
|
|
282
|
+
ChartTooltipContent,
|
|
283
|
+
ChartLegend,
|
|
284
|
+
CHART_COLORS,
|
|
285
|
+
seriesConfig,
|
|
286
|
+
formatNumber,
|
|
287
|
+
AXIS,
|
|
288
|
+
CHART_ANIMATION,
|
|
289
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox';
|
|
4
|
+
import { cn } from '../lib/utils';
|
|
5
|
+
import { CheckIcon, MinusIcon } from 'lucide-react';
|
|
6
|
+
|
|
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
|
+
// Desmarcada, a borda sai do texto a 35%, e não da borda de campo: a 10% a caixa de 16px sumia,
|
|
10
|
+
// sobretudo no escuro. O elemento é um span, então o desabilitado vem pelo data-disabled.
|
|
11
|
+
// Estado "em parte" (`indeterminate`): um traço, para grupos com só algumas opções marcadas.
|
|
12
|
+
function Checkbox({
|
|
13
|
+
className,
|
|
14
|
+
size = 'default',
|
|
15
|
+
...props
|
|
16
|
+
}: CheckboxPrimitive.Root.Props & {
|
|
17
|
+
/** Mantido por compatibilidade: desde D-403 toda caixa tem 16px. */
|
|
18
|
+
size?: 'default' | 'sm';
|
|
19
|
+
}) {
|
|
20
|
+
return (
|
|
21
|
+
<CheckboxPrimitive.Root
|
|
22
|
+
data-slot="checkbox"
|
|
23
|
+
data-size={size}
|
|
24
|
+
aria-labelledby={props.id && !props['aria-label'] ? `${props.id}-label` : undefined}
|
|
25
|
+
className={cn(
|
|
26
|
+
'group/checkbox peer relative flex size-4 shrink-0 items-center justify-center rounded-small border border-border-control-empty transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-border-control-empty after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring-strong focus-visible:focus-ring data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-ring-invalid aria-invalid:aria-checked:border-selected-strong dark:bg-input/30 dark:aria-invalid:border-border-error data-checked:border-selected-strong data-checked:bg-selected-strong data-checked:text-selected-strong-foreground data-indeterminate:border-selected-strong data-indeterminate:bg-selected-strong data-indeterminate:text-selected-strong-foreground group-has-[:focus-visible]/field-label:data-checked:border-selected-strong dark:data-checked:bg-selected-strong dark:data-indeterminate:bg-selected-strong',
|
|
27
|
+
className,
|
|
28
|
+
)}
|
|
29
|
+
{...props}
|
|
30
|
+
>
|
|
31
|
+
<CheckboxPrimitive.Indicator
|
|
32
|
+
data-slot="checkbox-indicator"
|
|
33
|
+
className="grid place-content-center text-current transition-none [&>svg]:size-icon-xs"
|
|
34
|
+
>
|
|
35
|
+
<CheckIcon className="group-data-indeterminate/checkbox:hidden" />
|
|
36
|
+
<MinusIcon className="hidden group-data-indeterminate/checkbox:block" />
|
|
37
|
+
</CheckboxPrimitive.Indicator>
|
|
38
|
+
</CheckboxPrimitive.Root>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { Checkbox };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cn } from '../lib/utils';
|
|
4
|
+
import { CopyButton } from './button';
|
|
5
|
+
import { Panel } from './card';
|
|
6
|
+
|
|
7
|
+
// Código para copiar e colar, como um comando, uma configuração ou o código de um formulário para o
|
|
8
|
+
// site da loja: a caixa do Panel, o texto em fonte de código, quebrando a linha quando é largo, sem
|
|
9
|
+
// rolagem para o lado, e o botão de copiar no canto, que copia o texto exato de uma vez. Endereço
|
|
10
|
+
// longo quebra em qualquer ponto, para o bloco caber no celular sem passar da borda.
|
|
11
|
+
function CodeBlock({
|
|
12
|
+
code,
|
|
13
|
+
label = 'código',
|
|
14
|
+
className,
|
|
15
|
+
}: {
|
|
16
|
+
code: string;
|
|
17
|
+
/** O que é copiado, para o leitor de tela e o aviso, como "comando" ou "configuração". */
|
|
18
|
+
label?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
}) {
|
|
21
|
+
return (
|
|
22
|
+
<Panel padding="none" data-slot="code-block" className={cn('relative min-w-0', className)}>
|
|
23
|
+
<pre className="py-4 pr-14 pl-5 text-mono-12 whitespace-pre-wrap wrap-anywhere">
|
|
24
|
+
<code>{code}</code>
|
|
25
|
+
</pre>
|
|
26
|
+
<CopyButton value={code} label={label} className="absolute top-3 right-3" />
|
|
27
|
+
</Panel>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ReactNode, useEffect, useState } from 'react';
|
|
4
|
+
import { ChevronDownIcon } from 'lucide-react';
|
|
5
|
+
import { Collapsible as CollapsiblePrimitive } from '@base-ui/react/collapsible';
|
|
6
|
+
import { cn } from '../lib/utils';
|
|
7
|
+
|
|
8
|
+
function Collapsible({ ...props }: CollapsiblePrimitive.Root.Props) {
|
|
9
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function CollapsibleTrigger({ ...props }: CollapsiblePrimitive.Trigger.Props) {
|
|
13
|
+
return <CollapsiblePrimitive.Trigger data-slot="collapsible-trigger" {...props} />;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function CollapsibleContent({ ...props }: CollapsiblePrimitive.Panel.Props) {
|
|
17
|
+
return <CollapsiblePrimitive.Panel data-slot="collapsible-content" {...props} />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Seção recolhível de um painel lateral, como os dados de um cliente: título com a contagem,
|
|
21
|
+
// ação opcional à direita, como "+", e o conteúdo, que abre e fecha no título (D-309). Com
|
|
22
|
+
// `storageKey`, lembra no navegador se a pessoa deixou aberta ou fechada (D-333). D-778: a ação
|
|
23
|
+
// fica à esquerda da seta, fora do gatilho, para o clique nela não abrir nem fechar a seção; a
|
|
24
|
+
// seta continua abrindo e fechando. `actionPlacement="end"` põe a ação depois da seta, como antes.
|
|
25
|
+
function CollapsibleSection({
|
|
26
|
+
title,
|
|
27
|
+
icon,
|
|
28
|
+
count,
|
|
29
|
+
action,
|
|
30
|
+
actionPlacement = 'before-chevron',
|
|
31
|
+
open,
|
|
32
|
+
onOpenChange,
|
|
33
|
+
defaultOpen,
|
|
34
|
+
storageKey,
|
|
35
|
+
children,
|
|
36
|
+
className,
|
|
37
|
+
}: {
|
|
38
|
+
title: string;
|
|
39
|
+
/** Ícone antes do título. */
|
|
40
|
+
icon?: ReactNode;
|
|
41
|
+
count?: number;
|
|
42
|
+
action?: ReactNode;
|
|
43
|
+
/** Onde fica a ação: à esquerda da seta, o padrão, ou depois dela, `end`. */
|
|
44
|
+
actionPlacement?: 'before-chevron' | 'end';
|
|
45
|
+
open?: boolean;
|
|
46
|
+
onOpenChange?: (open: boolean) => void;
|
|
47
|
+
defaultOpen?: boolean;
|
|
48
|
+
/** Chave para lembrar no navegador se ficou aberta, como "painel-contato:tarefas". */
|
|
49
|
+
storageKey?: string;
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
className?: string;
|
|
52
|
+
}) {
|
|
53
|
+
const [remembered, setRemembered] = useState(!!defaultOpen);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!storageKey) return;
|
|
56
|
+
try {
|
|
57
|
+
const saved = localStorage.getItem(storageKey);
|
|
58
|
+
if (saved !== null) setRemembered(saved === '1');
|
|
59
|
+
} catch {
|
|
60
|
+
// Sem acesso ao armazenamento, fica o padrão.
|
|
61
|
+
}
|
|
62
|
+
}, [storageKey]);
|
|
63
|
+
const remember = !!storageKey && open === undefined;
|
|
64
|
+
const chevron = (
|
|
65
|
+
<ChevronDownIcon
|
|
66
|
+
aria-hidden
|
|
67
|
+
className="ml-auto size-icon-lg shrink-0 text-muted-foreground transition-transform duration-(--duration-fast) in-data-[panel-open]:rotate-180"
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
return (
|
|
71
|
+
<Collapsible
|
|
72
|
+
data-slot="collapsible-section"
|
|
73
|
+
open={remember ? remembered : open}
|
|
74
|
+
onOpenChange={(next) => {
|
|
75
|
+
if (remember) {
|
|
76
|
+
setRemembered(next);
|
|
77
|
+
try {
|
|
78
|
+
localStorage.setItem(storageKey, next ? '1' : '0');
|
|
79
|
+
} catch {
|
|
80
|
+
// Sem acesso ao armazenamento, só não lembra.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
onOpenChange?.(next);
|
|
84
|
+
}}
|
|
85
|
+
defaultOpen={remember ? undefined : defaultOpen}
|
|
86
|
+
className={cn('border-b last:border-b-0', className)}
|
|
87
|
+
>
|
|
88
|
+
<div className="flex items-center gap-1 px-2.5 py-2">
|
|
89
|
+
<CollapsibleTrigger className="-mx-1.5 flex min-h-control min-w-0 flex-1 items-center gap-2 rounded-control border border-transparent px-1.5 py-1.5 text-left text-body-13-medium outline-none focus-visible:border-ring-strong focus-visible:focus-ring [&>svg:first-child]:size-icon-lg [&>svg:first-child]:shrink-0 [&>svg:first-child]:text-muted-foreground">
|
|
90
|
+
{icon}
|
|
91
|
+
<span className="truncate">{title}</span>
|
|
92
|
+
{count !== undefined && (
|
|
93
|
+
<span className="text-body-12 text-muted-foreground tabular-nums">{count}</span>
|
|
94
|
+
)}
|
|
95
|
+
{(!action || actionPlacement === 'end') && chevron}
|
|
96
|
+
</CollapsibleTrigger>
|
|
97
|
+
{action}
|
|
98
|
+
{/* A seta, depois da ação, também abre e fecha; o teclado usa o título. */}
|
|
99
|
+
{action && actionPlacement !== 'end' && (
|
|
100
|
+
<CollapsibleTrigger
|
|
101
|
+
tabIndex={-1}
|
|
102
|
+
aria-hidden
|
|
103
|
+
className="-mr-1.5 flex min-h-control shrink-0 items-center rounded-control px-1.5 outline-none"
|
|
104
|
+
>
|
|
105
|
+
{chevron}
|
|
106
|
+
</CollapsibleTrigger>
|
|
107
|
+
)}
|
|
108
|
+
</div>
|
|
109
|
+
<CollapsibleContent className="px-2.5 pb-3">{children}</CollapsibleContent>
|
|
110
|
+
</Collapsible>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent, CollapsibleSection };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { CheckIcon } from 'lucide-react';
|
|
4
|
+
import { Radio as RadioPrimitive } from '@base-ui/react/radio';
|
|
5
|
+
import { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';
|
|
6
|
+
import { cn } from '../lib/utils';
|
|
7
|
+
import { TAG_COLORS, tagTone } from './tag-input';
|
|
8
|
+
|
|
9
|
+
// Escolha de cor em bolinhas, D-346: as cores das tags, cada uma com o nome para o leitor de tela.
|
|
10
|
+
// As setas andam entre as bolinhas, como num grupo de opções. Com `className` em cada cor, vale
|
|
11
|
+
// outra paleta, como a do editor de texto; `size="sm"` deixa as bolinhas menores, num quadro, D-755.
|
|
12
|
+
|
|
13
|
+
export type SwatchColor = {
|
|
14
|
+
value: string;
|
|
15
|
+
label: string;
|
|
16
|
+
/** Fundo e cor do sinal da bolinha, para uma paleta fora das tags. */
|
|
17
|
+
className?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const NAMES: Record<string, string> = {
|
|
21
|
+
gray: 'Cinza',
|
|
22
|
+
'1': 'Azul',
|
|
23
|
+
'2': 'Turquesa',
|
|
24
|
+
'3': 'Verde',
|
|
25
|
+
'4': 'Oliva',
|
|
26
|
+
'5': 'Amarelo',
|
|
27
|
+
'6': 'Laranja',
|
|
28
|
+
'7': 'Vermelho',
|
|
29
|
+
'8': 'Rosa',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const SWATCH_COLORS: SwatchColor[] = TAG_COLORS.map((c) => ({
|
|
33
|
+
value: c,
|
|
34
|
+
label: NAMES[c] ?? c,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
export function ColorSwatchPicker({
|
|
38
|
+
value,
|
|
39
|
+
onValueChange,
|
|
40
|
+
colors = SWATCH_COLORS,
|
|
41
|
+
'aria-label': ariaLabel = 'Cor',
|
|
42
|
+
size = 'default',
|
|
43
|
+
className,
|
|
44
|
+
}: {
|
|
45
|
+
value: string;
|
|
46
|
+
onValueChange: (value: string) => void;
|
|
47
|
+
colors?: SwatchColor[];
|
|
48
|
+
'aria-label'?: string;
|
|
49
|
+
/** `sm`: bolinhas menores, para um quadro com muitas cores. */
|
|
50
|
+
size?: 'sm' | 'default' | 'lg';
|
|
51
|
+
className?: string;
|
|
52
|
+
}) {
|
|
53
|
+
return (
|
|
54
|
+
<RadioGroupPrimitive
|
|
55
|
+
data-slot="color-swatch-picker"
|
|
56
|
+
aria-label={ariaLabel}
|
|
57
|
+
value={value}
|
|
58
|
+
onValueChange={(v) => onValueChange(v as string)}
|
|
59
|
+
className={cn(
|
|
60
|
+
'flex flex-wrap',
|
|
61
|
+
size === 'sm' ? 'gap-1' : size === 'lg' ? 'gap-2.5' : 'gap-2',
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{colors.map((c) => (
|
|
66
|
+
<RadioPrimitive.Root
|
|
67
|
+
key={c.value}
|
|
68
|
+
value={c.value}
|
|
69
|
+
aria-label={c.label}
|
|
70
|
+
title={c.label}
|
|
71
|
+
className={cn(
|
|
72
|
+
'grid place-items-center rounded-full border outline-none transition-shadow focus-visible:focus-ring data-checked:ring-2 data-checked:ring-foreground data-checked:ring-offset-2 data-checked:ring-offset-background',
|
|
73
|
+
size === 'sm'
|
|
74
|
+
? 'size-5 data-checked:ring-offset-1'
|
|
75
|
+
: size === 'lg'
|
|
76
|
+
? 'size-10'
|
|
77
|
+
: 'size-8',
|
|
78
|
+
c.className ?? tagTone(c.value),
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
<RadioPrimitive.Indicator>
|
|
82
|
+
<CheckIcon
|
|
83
|
+
data-weight="bold"
|
|
84
|
+
className={
|
|
85
|
+
size === 'sm' ? 'size-icon-xs' : size === 'lg' ? 'size-icon-xl' : 'size-icon-lg'
|
|
86
|
+
}
|
|
87
|
+
/>
|
|
88
|
+
</RadioPrimitive.Indicator>
|
|
89
|
+
</RadioPrimitive.Root>
|
|
90
|
+
))}
|
|
91
|
+
</RadioGroupPrimitive>
|
|
92
|
+
);
|
|
93
|
+
}
|