@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,197 @@
|
|
|
1
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
import { Avatar } from './avatar';
|
|
4
|
+
import { Badge } from './badge';
|
|
5
|
+
import { Panel } from './card';
|
|
6
|
+
|
|
7
|
+
// tokens-ok-ligacao: só estrutura e tokens: ícone, título, texto e as ações que o app passa.
|
|
8
|
+
|
|
9
|
+
function Empty({ className, ...props }: React.ComponentProps<'div'>) {
|
|
10
|
+
return (
|
|
11
|
+
<div
|
|
12
|
+
data-slot="empty"
|
|
13
|
+
className={cn(
|
|
14
|
+
'flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-card border-dashed p-6 text-center text-balance',
|
|
15
|
+
className,
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function EmptyHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
data-slot="empty-header"
|
|
26
|
+
className={cn('flex max-w-sm flex-col items-center gap-2', className)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Ícone (variant="icon"), D-710: solto, sem o quadrado atrás, em 24px, 20px com size="sm" ou 40px com size="lg",
|
|
33
|
+
// como nas páginas de erro. O tom pinta só o ícone: erro, aviso, informação ou sucesso.
|
|
34
|
+
const emptyMediaVariants = cva(
|
|
35
|
+
'mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0',
|
|
36
|
+
{
|
|
37
|
+
variants: {
|
|
38
|
+
variant: {
|
|
39
|
+
default: 'bg-transparent',
|
|
40
|
+
icon: "flex shrink-0 items-center justify-center text-muted-foreground [&_svg:not([class*='size-'])]:size-6",
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
sm: '',
|
|
44
|
+
default: '',
|
|
45
|
+
lg: '',
|
|
46
|
+
},
|
|
47
|
+
tone: {
|
|
48
|
+
default: '',
|
|
49
|
+
neutral: 'text-muted-foreground',
|
|
50
|
+
error: 'text-destructive',
|
|
51
|
+
warning: 'text-warning',
|
|
52
|
+
info: 'text-info',
|
|
53
|
+
success: 'text-success',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
compoundVariants: [
|
|
57
|
+
// D-858: pequeno, 20px, para o vazio dentro de um cartão estreito.
|
|
58
|
+
{
|
|
59
|
+
variant: 'icon',
|
|
60
|
+
size: 'sm',
|
|
61
|
+
className: "[&_svg:not([class*='size-'])]:size-5",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
variant: 'icon',
|
|
65
|
+
size: 'lg',
|
|
66
|
+
className: "[&_svg:not([class*='size-'])]:size-10",
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
defaultVariants: {
|
|
70
|
+
variant: 'default',
|
|
71
|
+
size: 'default',
|
|
72
|
+
tone: 'default',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
function EmptyMedia({
|
|
78
|
+
className,
|
|
79
|
+
variant = 'default',
|
|
80
|
+
size = 'default',
|
|
81
|
+
tone = 'default',
|
|
82
|
+
...props
|
|
83
|
+
}: React.ComponentProps<'div'> & VariantProps<typeof emptyMediaVariants>) {
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
data-slot="empty-icon"
|
|
87
|
+
data-variant={variant}
|
|
88
|
+
data-size={size}
|
|
89
|
+
data-tone={tone}
|
|
90
|
+
className={cn(
|
|
91
|
+
emptyMediaVariants({
|
|
92
|
+
variant,
|
|
93
|
+
size,
|
|
94
|
+
tone: variant === 'icon' ? tone : 'default',
|
|
95
|
+
className,
|
|
96
|
+
}),
|
|
97
|
+
)}
|
|
98
|
+
{...props}
|
|
99
|
+
/>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function EmptyTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
|
104
|
+
return <div data-slot="empty-title" className={cn('text-title-page', className)} {...props} />;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function EmptyDescription({ className, ...props }: React.ComponentProps<'p'>) {
|
|
108
|
+
return (
|
|
109
|
+
<div
|
|
110
|
+
data-slot="empty-description"
|
|
111
|
+
className={cn(
|
|
112
|
+
'text-body-13 text-muted-foreground [&>a]:font-semibold [&>a]:text-link [&>a:hover]:text-link-hover',
|
|
113
|
+
className,
|
|
114
|
+
)}
|
|
115
|
+
{...props}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function EmptyContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
121
|
+
return (
|
|
122
|
+
<div
|
|
123
|
+
data-slot="empty-content"
|
|
124
|
+
className={cn(
|
|
125
|
+
'flex w-full max-w-sm min-w-0 flex-col items-center gap-2.5 text-body-13 text-balance',
|
|
126
|
+
className,
|
|
127
|
+
)}
|
|
128
|
+
{...props}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Prévia apagada da própria tela preenchida, D-831, para a tela vazia de primeiro uso: ensina
|
|
135
|
+
* mostrando como a tela fica com dados, no lugar de um ícone solto. Fica bem apagada, some para
|
|
136
|
+
* baixo e não recebe clique nem leitura de tela, para não parecer dado real. Dentro vão linhas de
|
|
137
|
+
* exemplo, pelo `EmptyPreviewRows`, ou o que a tela pedir.
|
|
138
|
+
*/
|
|
139
|
+
function EmptyPreview({ className, children }: { className?: string; children: React.ReactNode }) {
|
|
140
|
+
return (
|
|
141
|
+
<Panel
|
|
142
|
+
padding="none"
|
|
143
|
+
data-slot="empty-preview"
|
|
144
|
+
aria-hidden
|
|
145
|
+
inert
|
|
146
|
+
className={cn(
|
|
147
|
+
'pointer-events-none mb-1 max-h-44 w-full max-w-md overflow-hidden text-left opacity-70 mask-b-from-35% mask-b-to-100% select-none',
|
|
148
|
+
className,
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
{children}
|
|
152
|
+
</Panel>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type EmptyPreviewRow = {
|
|
157
|
+
/** Nome de exemplo, como "Ana Souza". */
|
|
158
|
+
title: string;
|
|
159
|
+
/** Segunda linha, como "Compradora na Loja Bela Vista". */
|
|
160
|
+
text?: string;
|
|
161
|
+
/** Selo de exemplo, como "Cliente". */
|
|
162
|
+
badge?: string;
|
|
163
|
+
/** Valor à direita, como "R$ 2.400,00". */
|
|
164
|
+
value?: string;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** Linhas de exemplo da prévia: avatar, nome, segunda linha e, à direita, selo ou valor. */
|
|
168
|
+
function EmptyPreviewRows({ rows, className }: { rows: EmptyPreviewRow[]; className?: string }) {
|
|
169
|
+
return (
|
|
170
|
+
<div data-slot="empty-preview-rows" className={cn('divide-y', className)}>
|
|
171
|
+
{rows.map((r) => (
|
|
172
|
+
<div key={r.title} className="flex items-center gap-3 px-card py-2.5">
|
|
173
|
+
<Avatar name={r.title} size="sm" />
|
|
174
|
+
<div className="grid min-w-0 flex-1">
|
|
175
|
+
<span className="truncate text-body-13-medium">{r.title}</span>
|
|
176
|
+
{r.text && (
|
|
177
|
+
<span className="truncate text-body-12 text-muted-foreground">{r.text}</span>
|
|
178
|
+
)}
|
|
179
|
+
</div>
|
|
180
|
+
{r.badge && <Badge variant="secondary">{r.badge}</Badge>}
|
|
181
|
+
{r.value && <span className="shrink-0 text-body-13 tabular-nums">{r.value}</span>}
|
|
182
|
+
</div>
|
|
183
|
+
))}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
Empty,
|
|
190
|
+
EmptyHeader,
|
|
191
|
+
EmptyTitle,
|
|
192
|
+
EmptyDescription,
|
|
193
|
+
EmptyContent,
|
|
194
|
+
EmptyMedia,
|
|
195
|
+
EmptyPreview,
|
|
196
|
+
EmptyPreviewRows,
|
|
197
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
|
|
7
|
+
import { Label } from './label';
|
|
8
|
+
import { Separator } from './separator';
|
|
9
|
+
|
|
10
|
+
function FieldSet({ className, ...props }: React.ComponentProps<'fieldset'>) {
|
|
11
|
+
return (
|
|
12
|
+
<fieldset
|
|
13
|
+
data-slot="field-set"
|
|
14
|
+
className={cn(
|
|
15
|
+
'flex flex-col gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3',
|
|
16
|
+
className,
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function FieldLegend({
|
|
24
|
+
className,
|
|
25
|
+
variant = 'legend',
|
|
26
|
+
...props
|
|
27
|
+
}: React.ComponentProps<'legend'> & { variant?: 'legend' | 'label' }) {
|
|
28
|
+
return (
|
|
29
|
+
<legend
|
|
30
|
+
data-slot="field-legend"
|
|
31
|
+
data-variant={variant}
|
|
32
|
+
className={cn(
|
|
33
|
+
'mb-1.5 data-[variant=label]:text-body-13-medium data-[variant=legend]:text-body-14-medium',
|
|
34
|
+
className,
|
|
35
|
+
)}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function FieldGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
data-slot="field-group"
|
|
45
|
+
className={cn(
|
|
46
|
+
'group/field-group @container/field-group flex w-full flex-col gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4',
|
|
47
|
+
className,
|
|
48
|
+
)}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const fieldVariants = cva('group/field flex w-full gap-2 data-[invalid=true]:text-text-error', {
|
|
55
|
+
variants: {
|
|
56
|
+
orientation: {
|
|
57
|
+
vertical: 'flex-col *:w-full [&>.sr-only]:w-auto',
|
|
58
|
+
horizontal:
|
|
59
|
+
'flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
60
|
+
responsive:
|
|
61
|
+
'flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
defaultVariants: {
|
|
65
|
+
orientation: 'vertical',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function Field({
|
|
70
|
+
className,
|
|
71
|
+
orientation = 'vertical',
|
|
72
|
+
...props
|
|
73
|
+
}: React.ComponentProps<'div'> & VariantProps<typeof fieldVariants>) {
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
role="group"
|
|
77
|
+
data-slot="field"
|
|
78
|
+
data-orientation={orientation}
|
|
79
|
+
className={cn(fieldVariants({ orientation }), className)}
|
|
80
|
+
{...props}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function FieldContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
86
|
+
return (
|
|
87
|
+
<div
|
|
88
|
+
data-slot="field-content"
|
|
89
|
+
className={cn('group/field-content flex flex-1 flex-col gap-0.5', className)}
|
|
90
|
+
{...props}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>) {
|
|
96
|
+
return (
|
|
97
|
+
<Label
|
|
98
|
+
data-slot="field-label"
|
|
99
|
+
className={cn(
|
|
100
|
+
'group/field-label peer/field-label flex w-fit gap-2 group-data-[disabled=true]/field:opacity-50 has-[>[data-slot=field]]:has-data-checked:border-selected-strong has-[>[data-slot=field]]:rounded-control has-[>[data-slot=field]]:border has-[>[data-slot=field]]:not-has-[:disabled,[data-disabled]]:hover:bg-hover has-[>[data-slot=field]]:has-[:focus-visible]:border-ring has-[>[data-slot=field]]:has-[:focus-visible]:focus-ring *:data-[slot=field]:p-2.5 dark:has-data-checked:border-selected-strong dark:has-data-checked:bg-hover',
|
|
101
|
+
'has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col',
|
|
102
|
+
className,
|
|
103
|
+
)}
|
|
104
|
+
{...props}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function FieldTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
|
110
|
+
return (
|
|
111
|
+
<div
|
|
112
|
+
data-slot="field-label"
|
|
113
|
+
className={cn(
|
|
114
|
+
'flex w-fit items-center gap-2 text-body-13-medium group-data-[disabled=true]/field:opacity-50',
|
|
115
|
+
className,
|
|
116
|
+
)}
|
|
117
|
+
{...props}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function FieldDescription({ className, ...props }: React.ComponentProps<'p'>) {
|
|
123
|
+
return (
|
|
124
|
+
<p
|
|
125
|
+
data-slot="field-description"
|
|
126
|
+
className={cn(
|
|
127
|
+
'text-left text-body-13 text-muted-foreground group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5',
|
|
128
|
+
'last:mt-0 nth-last-2:-mt-1',
|
|
129
|
+
'[&>a]:font-semibold [&>a]:text-link [&>a:hover]:text-link-hover',
|
|
130
|
+
className,
|
|
131
|
+
)}
|
|
132
|
+
{...props}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Linha que divide o formulário, com texto no meio opcional, como "ou". Com texto, são duas linhas,
|
|
138
|
+
// uma de cada lado: o fundo é o do lugar onde está, cartão, página ou janela, sem mancha.
|
|
139
|
+
function FieldSeparator({
|
|
140
|
+
children,
|
|
141
|
+
className,
|
|
142
|
+
...props
|
|
143
|
+
}: React.ComponentProps<'div'> & {
|
|
144
|
+
children?: React.ReactNode;
|
|
145
|
+
}) {
|
|
146
|
+
return (
|
|
147
|
+
<div
|
|
148
|
+
data-slot="field-separator"
|
|
149
|
+
data-content={!!children}
|
|
150
|
+
className={cn(
|
|
151
|
+
'relative -my-2 flex h-5 items-center gap-2 text-body-13 group-data-[variant=outline]/field-group:-mb-2',
|
|
152
|
+
className,
|
|
153
|
+
)}
|
|
154
|
+
{...props}
|
|
155
|
+
>
|
|
156
|
+
<Separator className="flex-1" />
|
|
157
|
+
{children && (
|
|
158
|
+
<>
|
|
159
|
+
<span className="block w-fit text-muted-foreground" data-slot="field-separator-content">
|
|
160
|
+
{children}
|
|
161
|
+
</span>
|
|
162
|
+
<Separator className="flex-1" />
|
|
163
|
+
</>
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function FieldError({
|
|
170
|
+
className,
|
|
171
|
+
children,
|
|
172
|
+
errors,
|
|
173
|
+
...props
|
|
174
|
+
}: React.ComponentProps<'div'> & {
|
|
175
|
+
errors?: Array<{ message?: string } | undefined>;
|
|
176
|
+
}) {
|
|
177
|
+
const content = useMemo(() => {
|
|
178
|
+
if (children) {
|
|
179
|
+
return children;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!errors?.length) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const uniqueErrors = [...new Map(errors.map((error) => [error?.message, error])).values()];
|
|
187
|
+
|
|
188
|
+
if (uniqueErrors?.length == 1) {
|
|
189
|
+
return uniqueErrors[0]?.message;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<ul className="ml-4 flex list-disc flex-col gap-1">
|
|
194
|
+
{uniqueErrors.map((error, index) => error?.message && <li key={index}>{error.message}</li>)}
|
|
195
|
+
</ul>
|
|
196
|
+
);
|
|
197
|
+
}, [children, errors]);
|
|
198
|
+
|
|
199
|
+
if (!content) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div
|
|
205
|
+
role="alert"
|
|
206
|
+
data-slot="field-error"
|
|
207
|
+
className={cn('text-body-13 text-text-error', className)}
|
|
208
|
+
{...props}
|
|
209
|
+
>
|
|
210
|
+
{content}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
Field,
|
|
217
|
+
FieldLabel,
|
|
218
|
+
FieldDescription,
|
|
219
|
+
FieldError,
|
|
220
|
+
FieldGroup,
|
|
221
|
+
FieldLegend,
|
|
222
|
+
FieldSeparator,
|
|
223
|
+
FieldSet,
|
|
224
|
+
FieldContent,
|
|
225
|
+
FieldTitle,
|
|
226
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
FileIcon,
|
|
5
|
+
FileImageIcon,
|
|
6
|
+
FileSpreadsheetIcon,
|
|
7
|
+
FileTextIcon,
|
|
8
|
+
TrashIcon,
|
|
9
|
+
UploadIcon,
|
|
10
|
+
} from 'lucide-react';
|
|
11
|
+
import { useRef, useState, type ReactNode } from 'react';
|
|
12
|
+
import { Button } from './button';
|
|
13
|
+
import { Progress } from './progress';
|
|
14
|
+
import { fileSize } from '../lib/file-accept';
|
|
15
|
+
import { cn } from '../lib/utils';
|
|
16
|
+
import { Panel } from './card';
|
|
17
|
+
|
|
18
|
+
// Envio de arquivos (D-309): área para soltar ou escolher e a linha de cada arquivo, com ícone pelo
|
|
19
|
+
// tipo, tamanho, andamento e remover. Confere o tipo e o tamanho antes de entregar ao app. Para a
|
|
20
|
+
// foto de uma pessoa ou o logo de uma empresa, use o PictureUpload, que é o próprio avatar.
|
|
21
|
+
|
|
22
|
+
export { fileSize };
|
|
23
|
+
|
|
24
|
+
function iconOf(name: string) {
|
|
25
|
+
const ext = name.split('.').pop()?.toLowerCase() ?? '';
|
|
26
|
+
if (['png', 'jpg', 'jpeg', 'webp', 'gif', 'svg'].includes(ext)) return FileImageIcon;
|
|
27
|
+
if (ext === 'pdf') return FileTextIcon;
|
|
28
|
+
if (['csv', 'xls', 'xlsx'].includes(ext)) return FileSpreadsheetIcon;
|
|
29
|
+
return FileIcon;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function FileUpload({
|
|
33
|
+
onFiles,
|
|
34
|
+
accept,
|
|
35
|
+
multiple = false,
|
|
36
|
+
maxSize,
|
|
37
|
+
hint,
|
|
38
|
+
disabled,
|
|
39
|
+
compact = false,
|
|
40
|
+
className,
|
|
41
|
+
}: {
|
|
42
|
+
/** Recebe só os arquivos que passaram na conferência de tipo e tamanho. */
|
|
43
|
+
onFiles: (files: File[]) => void;
|
|
44
|
+
/** Tipos aceitos, como "image/*,.pdf". */
|
|
45
|
+
accept?: string;
|
|
46
|
+
multiple?: boolean;
|
|
47
|
+
/** Tamanho máximo de cada arquivo, em bytes. */
|
|
48
|
+
maxSize?: number;
|
|
49
|
+
/** Texto embaixo, como "PNG ou JPG, até 5 MB". */
|
|
50
|
+
hint?: ReactNode;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/** Uma linha só, para formulários apertados. */
|
|
53
|
+
compact?: boolean;
|
|
54
|
+
className?: string;
|
|
55
|
+
}) {
|
|
56
|
+
const picker = useRef<HTMLInputElement>(null);
|
|
57
|
+
const [over, setOver] = useState(false);
|
|
58
|
+
const [error, setError] = useState('');
|
|
59
|
+
|
|
60
|
+
function take(list: FileList | null) {
|
|
61
|
+
if (!list) return;
|
|
62
|
+
const all = Array.from(list).slice(0, multiple ? undefined : 1);
|
|
63
|
+
const big = maxSize ? all.filter((f) => f.size > maxSize) : [];
|
|
64
|
+
const ok = all.filter((f) => !big.includes(f));
|
|
65
|
+
setError(
|
|
66
|
+
big.length
|
|
67
|
+
? `${big.length === 1 ? 'Um arquivo passou' : `${big.length} arquivos passaram`} de ${fileSize(maxSize ?? 0)}.`
|
|
68
|
+
: '',
|
|
69
|
+
);
|
|
70
|
+
if (ok.length) onFiles(ok);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div data-slot="file-upload" className={cn('grid gap-1.5', className)}>
|
|
75
|
+
<Panel
|
|
76
|
+
padding="none"
|
|
77
|
+
interactive
|
|
78
|
+
render={<button type="button" disabled={disabled} />}
|
|
79
|
+
onClick={() => picker.current?.click()}
|
|
80
|
+
onDragOver={(e) => {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
setOver(true);
|
|
83
|
+
}}
|
|
84
|
+
onDragLeave={() => setOver(false)}
|
|
85
|
+
onDrop={(e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
setOver(false);
|
|
88
|
+
take(e.dataTransfer.files);
|
|
89
|
+
}}
|
|
90
|
+
data-over={over || undefined}
|
|
91
|
+
className={cn(
|
|
92
|
+
'flex w-full items-center border-dashed border-border-strong text-left disabled:pointer-events-none disabled:opacity-50 data-over:border-selected-strong data-over:bg-selected',
|
|
93
|
+
compact ? 'gap-3 px-2.5 py-2.5' : 'flex-col justify-center gap-2 px-6 py-8 text-center',
|
|
94
|
+
)}
|
|
95
|
+
>
|
|
96
|
+
<span className="grid size-10 shrink-0 place-items-center rounded-card bg-muted">
|
|
97
|
+
<UploadIcon className="size-icon-xl" />
|
|
98
|
+
</span>
|
|
99
|
+
<span className="grid gap-0.5">
|
|
100
|
+
<span className="text-body-13-medium">
|
|
101
|
+
{over ? 'Solte para enviar' : 'Arraste o arquivo ou clique para escolher'}
|
|
102
|
+
</span>
|
|
103
|
+
{hint && <span className="text-body-13 text-muted-foreground">{hint}</span>}
|
|
104
|
+
</span>
|
|
105
|
+
</Panel>
|
|
106
|
+
{error && (
|
|
107
|
+
<p role="alert" className="text-body-13 text-text-error">
|
|
108
|
+
{error}
|
|
109
|
+
</p>
|
|
110
|
+
)}
|
|
111
|
+
<input
|
|
112
|
+
ref={picker}
|
|
113
|
+
type="file"
|
|
114
|
+
accept={accept}
|
|
115
|
+
multiple={multiple}
|
|
116
|
+
className="sr-only"
|
|
117
|
+
tabIndex={-1}
|
|
118
|
+
aria-hidden
|
|
119
|
+
onChange={(e) => {
|
|
120
|
+
take(e.target.files);
|
|
121
|
+
e.target.value = '';
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Linha de um arquivo escolhido ou enviado. Com `progress`, mostra o andamento do envio. */
|
|
129
|
+
function FileItem({
|
|
130
|
+
name,
|
|
131
|
+
size,
|
|
132
|
+
progress,
|
|
133
|
+
onRemove,
|
|
134
|
+
href,
|
|
135
|
+
meta,
|
|
136
|
+
className,
|
|
137
|
+
}: {
|
|
138
|
+
name: string;
|
|
139
|
+
size: number;
|
|
140
|
+
/** Uma linha embaixo do nome, como "Rafael enviou em 02/11". */
|
|
141
|
+
meta?: ReactNode;
|
|
142
|
+
/** De 0 a 100 enquanto envia; sem ele, o arquivo já está salvo. */
|
|
143
|
+
progress?: number;
|
|
144
|
+
onRemove?: () => void;
|
|
145
|
+
/** Link para abrir o arquivo. */
|
|
146
|
+
href?: string;
|
|
147
|
+
className?: string;
|
|
148
|
+
}) {
|
|
149
|
+
const Icon = iconOf(name);
|
|
150
|
+
return (
|
|
151
|
+
<Panel
|
|
152
|
+
padding="none"
|
|
153
|
+
className={cn('flex items-center gap-3 px-2.5 py-2.5', className)}
|
|
154
|
+
data-slot="file-item"
|
|
155
|
+
>
|
|
156
|
+
<Icon className="size-6 shrink-0 text-muted-foreground" />
|
|
157
|
+
<div className="grid min-w-0 flex-1 gap-1">
|
|
158
|
+
<div className="flex min-w-0 items-baseline gap-2">
|
|
159
|
+
{href ? (
|
|
160
|
+
<a href={href} className="truncate text-body-13-medium hover:underline">
|
|
161
|
+
{name}
|
|
162
|
+
</a>
|
|
163
|
+
) : (
|
|
164
|
+
<span className="truncate text-body-13-medium">{name}</span>
|
|
165
|
+
)}
|
|
166
|
+
<span className="ml-auto shrink-0 text-body-13 text-muted-foreground tabular-nums">
|
|
167
|
+
{progress !== undefined && progress < 100 ? `${progress}%` : fileSize(size)}
|
|
168
|
+
</span>
|
|
169
|
+
</div>
|
|
170
|
+
{meta && (progress === undefined || progress >= 100) && (
|
|
171
|
+
<span className="truncate text-body-12 text-muted-foreground">{meta}</span>
|
|
172
|
+
)}
|
|
173
|
+
{progress !== undefined && progress < 100 && (
|
|
174
|
+
<Progress value={progress} aria-label={`Enviando ${name}`} />
|
|
175
|
+
)}
|
|
176
|
+
</div>
|
|
177
|
+
{onRemove && (
|
|
178
|
+
<Button variant="outline" size="icon-sm" aria-label={`Remover ${name}`} onClick={onRemove}>
|
|
179
|
+
<TrashIcon data-danger />
|
|
180
|
+
</Button>
|
|
181
|
+
)}
|
|
182
|
+
</Panel>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { FileUpload, FileItem };
|