@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,86 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from '../lib/utils';
|
|
5
|
+
import { OTPInput, OTPInputContext } from 'input-otp';
|
|
6
|
+
import { MinusIcon } from 'lucide-react';
|
|
7
|
+
|
|
8
|
+
function InputOTP({
|
|
9
|
+
className,
|
|
10
|
+
containerClassName,
|
|
11
|
+
...props
|
|
12
|
+
}: React.ComponentProps<typeof OTPInput> & {
|
|
13
|
+
containerClassName?: string;
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<OTPInput
|
|
17
|
+
data-slot="input-otp"
|
|
18
|
+
containerClassName={cn(
|
|
19
|
+
'cn-input-otp flex max-w-full min-w-0 items-center has-disabled:opacity-50',
|
|
20
|
+
containerClassName,
|
|
21
|
+
)}
|
|
22
|
+
spellCheck={false}
|
|
23
|
+
className={cn('disabled:cursor-not-allowed', className)}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function InputOTPGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
data-slot="input-otp-group"
|
|
33
|
+
className={cn(
|
|
34
|
+
'flex min-w-0 items-center rounded-control has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-ring-invalid',
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function InputOTPSlot({
|
|
43
|
+
index,
|
|
44
|
+
className,
|
|
45
|
+
...props
|
|
46
|
+
}: React.ComponentProps<'div'> & {
|
|
47
|
+
index: number;
|
|
48
|
+
}) {
|
|
49
|
+
const inputOTPContext = React.useContext(OTPInputContext);
|
|
50
|
+
const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
data-slot="input-otp-slot"
|
|
55
|
+
data-active={isActive}
|
|
56
|
+
className={cn(
|
|
57
|
+
'relative flex size-control-lg min-w-0 shrink items-center justify-center border-y border-r border-input text-body-13 transition-all outline-none first:rounded-l-control first:border-l last:rounded-r-control aria-invalid:border-destructive dark:aria-invalid:border-border-error data-[active=true]:z-10 data-[active=true]:border-ring-strong data-[active=true]:ring-3 data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:border-destructive data-[active=true]:aria-invalid:ring-ring-invalid dark:bg-input/30',
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
{char}
|
|
63
|
+
{hasFakeCaret && (
|
|
64
|
+
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
|
|
65
|
+
{/* tokens-ok: o ritmo do cursor piscando, um segundo */}
|
|
66
|
+
<div className="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function InputOTPSeparator({ ...props }: React.ComponentProps<'div'>) {
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
data-slot="input-otp-separator"
|
|
77
|
+
className="flex items-center [&_svg:not([class*='size-'])]:size-3"
|
|
78
|
+
role="separator"
|
|
79
|
+
{...props}
|
|
80
|
+
>
|
|
81
|
+
<MinusIcon />
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator };
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Input as InputPrimitive } from '@base-ui/react/input';
|
|
5
|
+
import { NumberField } from '@base-ui/react/number-field';
|
|
6
|
+
import { EyeIcon, EyeOffIcon, SearchIcon, XIcon } from 'lucide-react';
|
|
7
|
+
import { CharCount, useCharCount } from '../lib/char-count';
|
|
8
|
+
import { cn } from '../lib/utils';
|
|
9
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
10
|
+
import { Button } from './button';
|
|
11
|
+
import { Textarea } from './textarea';
|
|
12
|
+
|
|
13
|
+
// Input group, D-854: a caixa que junta o campo com ícone, texto ou botão. Mora aqui com o Input,
|
|
14
|
+
// como peça próxima, e assim o Input e o grupo não dependem um do outro em dois arquivos.
|
|
15
|
+
// Alturas 32, 40 e 48, como o Input: o pequeno alinha com filtros e tabelas.
|
|
16
|
+
function InputGroup({
|
|
17
|
+
className,
|
|
18
|
+
size = 'default',
|
|
19
|
+
...props
|
|
20
|
+
}: React.ComponentProps<'div'> & { size?: 'sm' | 'default' | 'lg' }) {
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
data-slot="input-group"
|
|
24
|
+
data-size={size}
|
|
25
|
+
role="group"
|
|
26
|
+
className={cn(
|
|
27
|
+
'group/input-group relative flex h-control data-[size=sm]:h-control-sm data-[size=lg]:h-control-lg w-full min-w-0 items-center rounded-control border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:focus-ring-field has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-ring-invalid has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto bg-surface-control dark:has-disabled:bg-input/80 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5',
|
|
28
|
+
className,
|
|
29
|
+
)}
|
|
30
|
+
{...props}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const inputGroupAddonVariants = cva(
|
|
36
|
+
"flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-body-13-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-control [&>svg:not([class*='size-'])]:size-icon",
|
|
37
|
+
{
|
|
38
|
+
variants: {
|
|
39
|
+
align: {
|
|
40
|
+
'inline-start': 'order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]',
|
|
41
|
+
'inline-end': 'order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]',
|
|
42
|
+
'block-start':
|
|
43
|
+
'order-first w-full justify-start px-2 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2',
|
|
44
|
+
'block-end':
|
|
45
|
+
'order-last w-full justify-start px-2 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
defaultVariants: {
|
|
49
|
+
align: 'inline-start',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
function InputGroupAddon({
|
|
55
|
+
className,
|
|
56
|
+
align = 'inline-start',
|
|
57
|
+
...props
|
|
58
|
+
}: React.ComponentProps<'div'> & VariantProps<typeof inputGroupAddonVariants>) {
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
role="group"
|
|
62
|
+
data-slot="input-group-addon"
|
|
63
|
+
data-align={align}
|
|
64
|
+
className={cn(inputGroupAddonVariants({ align }), className)}
|
|
65
|
+
onClick={(e) => {
|
|
66
|
+
if ((e.target as HTMLElement).closest('button')) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
e.currentTarget.parentElement?.querySelector('input')?.focus();
|
|
70
|
+
}}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const inputGroupButtonVariants = cva('flex items-center gap-2 text-body-13 shadow-none', {
|
|
77
|
+
variants: {
|
|
78
|
+
size: {
|
|
79
|
+
xs: "h-control-xs gap-1 rounded-control px-2 [&>svg:not([class*='size-'])]:size-icon-xs",
|
|
80
|
+
sm: '',
|
|
81
|
+
'icon-xs': 'size-control-xs rounded-inner p-0 has-[>svg]:p-0',
|
|
82
|
+
'icon-sm': 'size-control-sm p-0 has-[>svg]:p-0',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
defaultVariants: {
|
|
86
|
+
size: 'xs',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
function InputGroupButton({
|
|
91
|
+
className,
|
|
92
|
+
type = 'button',
|
|
93
|
+
variant = 'ghost',
|
|
94
|
+
size = 'xs',
|
|
95
|
+
...props
|
|
96
|
+
}: Omit<React.ComponentProps<typeof Button>, 'size' | 'type'> &
|
|
97
|
+
VariantProps<typeof inputGroupButtonVariants> & {
|
|
98
|
+
type?: 'button' | 'submit' | 'reset';
|
|
99
|
+
}) {
|
|
100
|
+
return (
|
|
101
|
+
<Button
|
|
102
|
+
type={type}
|
|
103
|
+
data-size={size}
|
|
104
|
+
variant={variant}
|
|
105
|
+
className={cn(inputGroupButtonVariants({ size }), className)}
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function InputGroupText({ className, ...props }: React.ComponentProps<'span'>) {
|
|
112
|
+
return (
|
|
113
|
+
<span
|
|
114
|
+
className={cn(
|
|
115
|
+
"flex items-center gap-2 text-body-13 text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-icon",
|
|
116
|
+
className,
|
|
117
|
+
)}
|
|
118
|
+
{...props}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function InputGroupInput({ className, ...props }: React.ComponentProps<typeof Input>) {
|
|
124
|
+
return (
|
|
125
|
+
<Input
|
|
126
|
+
data-slot="input-group-control"
|
|
127
|
+
className={cn(
|
|
128
|
+
'flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 focus-visible:outline-none! disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent group-data-[size=sm]/input-group:h-control-sm group-data-[size=lg]/input-group:h-control-lg',
|
|
129
|
+
className,
|
|
130
|
+
)}
|
|
131
|
+
{...props}
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function InputGroupTextarea({ className, ...props }: React.ComponentProps<'textarea'>) {
|
|
137
|
+
return (
|
|
138
|
+
<Textarea
|
|
139
|
+
data-slot="input-group-control"
|
|
140
|
+
className={cn(
|
|
141
|
+
'flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent',
|
|
142
|
+
className,
|
|
143
|
+
)}
|
|
144
|
+
{...props}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Alturas 32, 40 e 48 e respiro 12 em todas (D-175): o pequeno alinha com o botão
|
|
150
|
+
// de 32 em filtros e tabelas. Com `showCount` e `maxLength`, mostra "45/120" no fim do campo
|
|
151
|
+
// quando o texto passa de 80% do limite; aí o `className` vai para a caixa de fora.
|
|
152
|
+
function Input({
|
|
153
|
+
className,
|
|
154
|
+
type,
|
|
155
|
+
size = 'default',
|
|
156
|
+
showCount = false,
|
|
157
|
+
onChange,
|
|
158
|
+
...props
|
|
159
|
+
}: Omit<React.ComponentProps<'input'>, 'size'> & {
|
|
160
|
+
size?: 'sm' | 'default' | 'lg';
|
|
161
|
+
/** Contador de letras, "45/120", a partir de 80% do `maxLength`. Precisa do `maxLength`. */
|
|
162
|
+
showCount?: boolean;
|
|
163
|
+
}) {
|
|
164
|
+
const count = useCharCount({
|
|
165
|
+
enabled: showCount,
|
|
166
|
+
maxLength: props.maxLength,
|
|
167
|
+
value: props.value,
|
|
168
|
+
defaultValue: props.defaultValue,
|
|
169
|
+
onChange,
|
|
170
|
+
});
|
|
171
|
+
const input = (
|
|
172
|
+
<InputPrimitive
|
|
173
|
+
type={type}
|
|
174
|
+
data-slot="input"
|
|
175
|
+
data-size={size}
|
|
176
|
+
className={cn(
|
|
177
|
+
'h-control w-full min-w-0 rounded-control data-[size=lg]:h-control-lg data-[size=sm]:h-control-sm border border-input bg-surface-control px-2.5 py-1 text-body-13 transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-body-13-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring-strong focus-visible:focus-ring-field disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-ring-invalid dark:disabled:bg-input/80 dark:aria-invalid:border-border-error',
|
|
178
|
+
count.on ? count.room : className,
|
|
179
|
+
)}
|
|
180
|
+
onChange={count.onChange}
|
|
181
|
+
{...props}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
if (!count.on) return input;
|
|
185
|
+
return (
|
|
186
|
+
<div data-slot="input-count" className={cn('relative w-full min-w-0', className)}>
|
|
187
|
+
{input}
|
|
188
|
+
{count.visible && (
|
|
189
|
+
<CharCount
|
|
190
|
+
length={count.length}
|
|
191
|
+
max={props.maxLength as number}
|
|
192
|
+
className="inset-y-0 flex items-center"
|
|
193
|
+
/>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Campo de senha com o botão de mostrar/esconder. Alturas 32, 40 e 48, como o Input.
|
|
200
|
+
export function PasswordInput({
|
|
201
|
+
size = 'default',
|
|
202
|
+
...props
|
|
203
|
+
}: Omit<React.ComponentProps<typeof InputGroupInput>, 'type'>) {
|
|
204
|
+
const [visible, setVisible] = React.useState(false);
|
|
205
|
+
return (
|
|
206
|
+
<InputGroup size={size ?? 'default'}>
|
|
207
|
+
<InputGroupInput type={visible ? 'text' : 'password'} {...props} />
|
|
208
|
+
<InputGroupAddon align="inline-end">
|
|
209
|
+
<InputGroupButton
|
|
210
|
+
size="icon-xs"
|
|
211
|
+
aria-label={visible ? 'Esconder senha' : 'Mostrar senha'}
|
|
212
|
+
onClick={() => setVisible((v) => !v)}
|
|
213
|
+
>
|
|
214
|
+
{visible ? <EyeOffIcon /> : <EyeIcon />}
|
|
215
|
+
</InputGroupButton>
|
|
216
|
+
</InputGroupAddon>
|
|
217
|
+
</InputGroup>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Busca de uma lista: lupa à esquerda e um X para limpar quando há texto. Esc também limpa. Montada
|
|
222
|
+
// no Input group, como o campo de senha e o de telefone.
|
|
223
|
+
|
|
224
|
+
function SearchInput({
|
|
225
|
+
value,
|
|
226
|
+
onValueChange,
|
|
227
|
+
placeholder = 'Buscar',
|
|
228
|
+
className,
|
|
229
|
+
onKeyDown,
|
|
230
|
+
size = 'default',
|
|
231
|
+
variant = 'default',
|
|
232
|
+
...props
|
|
233
|
+
}: Omit<React.ComponentProps<'input'>, 'value' | 'onChange' | 'size'> & {
|
|
234
|
+
value: string;
|
|
235
|
+
onValueChange: (value: string) => void;
|
|
236
|
+
/** Altura 32, 40 ou 48, como o Input. */
|
|
237
|
+
size?: 'sm' | 'default' | 'lg';
|
|
238
|
+
/**
|
|
239
|
+
* `filled`: redonda, de fundo cinza e sem borda, que aparece ao clicar, como a busca do WhatsApp.
|
|
240
|
+
* Para a busca no topo de uma lista, como a Conversation list (D-788, D-790).
|
|
241
|
+
*/
|
|
242
|
+
variant?: 'default' | 'filled';
|
|
243
|
+
}) {
|
|
244
|
+
return (
|
|
245
|
+
<InputGroup
|
|
246
|
+
size={size}
|
|
247
|
+
data-search
|
|
248
|
+
data-variant={variant}
|
|
249
|
+
// D-790: a cinza é redonda, para se diferenciar das pílulas e dos campos.
|
|
250
|
+
className={cn(
|
|
251
|
+
variant === 'filled' && 'rounded-full border-transparent bg-muted dark:bg-muted',
|
|
252
|
+
className,
|
|
253
|
+
)}
|
|
254
|
+
>
|
|
255
|
+
<InputGroupAddon>
|
|
256
|
+
<SearchIcon />
|
|
257
|
+
</InputGroupAddon>
|
|
258
|
+
<InputGroupInput
|
|
259
|
+
type="search"
|
|
260
|
+
value={value}
|
|
261
|
+
placeholder={placeholder}
|
|
262
|
+
onChange={(e) => onValueChange(e.target.value)}
|
|
263
|
+
onKeyDown={(e) => {
|
|
264
|
+
if (e.key === 'Escape' && value) {
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
onValueChange('');
|
|
267
|
+
}
|
|
268
|
+
onKeyDown?.(e);
|
|
269
|
+
}}
|
|
270
|
+
className="[&::-webkit-search-cancel-button]:appearance-none"
|
|
271
|
+
{...props}
|
|
272
|
+
/>
|
|
273
|
+
{value && (
|
|
274
|
+
<InputGroupAddon align="inline-end">
|
|
275
|
+
<InputGroupButton
|
|
276
|
+
size="icon-xs"
|
|
277
|
+
aria-label="Limpar busca"
|
|
278
|
+
onClick={() => onValueChange('')}
|
|
279
|
+
>
|
|
280
|
+
<XIcon />
|
|
281
|
+
</InputGroupButton>
|
|
282
|
+
</InputGroupAddon>
|
|
283
|
+
)}
|
|
284
|
+
</InputGroup>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Campo com máscara: a pessoa digita só os números e vê o formato, como 123.456.789-09. O app
|
|
289
|
+
// recebe e guarda só os dígitos, "12345678909". Máscaras prontas para CPF, CNPJ, CEP e telefone
|
|
290
|
+
// fixo; para outro formato, passe a máscara com 9 no lugar de cada número, como "9999 9999 9999".
|
|
291
|
+
// Celular com país é o PhoneInput.
|
|
292
|
+
|
|
293
|
+
export const MASKS = {
|
|
294
|
+
cpf: '999.999.999-99',
|
|
295
|
+
cnpj: '99.999.999/9999-99',
|
|
296
|
+
cep: '99999-999',
|
|
297
|
+
'telefone-fixo': '(99) 9999-9999',
|
|
298
|
+
} as const;
|
|
299
|
+
|
|
300
|
+
export type MaskName = keyof typeof MASKS;
|
|
301
|
+
|
|
302
|
+
function patternOf(mask: MaskName | (string & {})): string {
|
|
303
|
+
return mask in MASKS ? MASKS[mask as MaskName] : mask;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Quantos números cabem na máscara. */
|
|
307
|
+
export function maskLength(mask: MaskName | (string & {})): number {
|
|
308
|
+
return patternOf(mask)
|
|
309
|
+
.split('')
|
|
310
|
+
.filter((c) => c === '9').length;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Põe os números no formato: formatMask("12345678909", "cpf") dá "123.456.789-09". */
|
|
314
|
+
export function formatMask(value: string, mask: MaskName | (string & {})): string {
|
|
315
|
+
const pattern = patternOf(mask);
|
|
316
|
+
const digits = value.replace(/\D/g, '');
|
|
317
|
+
let out = '';
|
|
318
|
+
let i = 0;
|
|
319
|
+
for (const ch of pattern) {
|
|
320
|
+
if (i >= digits.length) break;
|
|
321
|
+
if (ch === '9') out += digits[i++];
|
|
322
|
+
else out += ch;
|
|
323
|
+
}
|
|
324
|
+
return out;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const PLACEHOLDER: Record<MaskName, string> = {
|
|
328
|
+
cpf: '000.000.000-00',
|
|
329
|
+
cnpj: '00.000.000/0000-00',
|
|
330
|
+
cep: '00000-000',
|
|
331
|
+
'telefone-fixo': '(00) 0000-0000',
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
function MaskedInput({
|
|
335
|
+
mask,
|
|
336
|
+
value,
|
|
337
|
+
onValueChange,
|
|
338
|
+
addon,
|
|
339
|
+
placeholder,
|
|
340
|
+
size,
|
|
341
|
+
...props
|
|
342
|
+
}: Omit<React.ComponentProps<typeof Input>, 'value' | 'defaultValue' | 'onChange'> & {
|
|
343
|
+
/** "cpf", "cnpj", "cep", "telefone-fixo" ou a máscara livre, com 9 no lugar de cada número. */
|
|
344
|
+
mask: MaskName | (string & {});
|
|
345
|
+
/** Só os dígitos, como "12345678909". */
|
|
346
|
+
value: string;
|
|
347
|
+
/** Recebe só os dígitos, já cortados no tamanho da máscara. */
|
|
348
|
+
onValueChange: (digits: string) => void;
|
|
349
|
+
/**
|
|
350
|
+
* Peça no fim do campo, como o Spinner enquanto busca o CEP. Passe null quando ela some por um
|
|
351
|
+
* tempo, para o campo não perder o foco.
|
|
352
|
+
*/
|
|
353
|
+
addon?: React.ReactNode;
|
|
354
|
+
}) {
|
|
355
|
+
const ref = React.useRef<HTMLInputElement>(null);
|
|
356
|
+
const max = maskLength(mask);
|
|
357
|
+
const digits = value.replace(/\D/g, '').slice(0, max);
|
|
358
|
+
const shown = formatMask(digits, mask);
|
|
359
|
+
|
|
360
|
+
function change(e: React.ChangeEvent<HTMLInputElement>) {
|
|
361
|
+
const el = e.target;
|
|
362
|
+
const caret = el.selectionStart ?? el.value.length;
|
|
363
|
+
let next = el.value.replace(/\D/g, '');
|
|
364
|
+
let before = el.value.slice(0, caret).replace(/\D/g, '').length;
|
|
365
|
+
// Apagou só um ponto ou traço: apaga o número antes dele, como a pessoa espera.
|
|
366
|
+
if (next === digits && el.value.length < shown.length && before > 0) {
|
|
367
|
+
next = next.slice(0, before - 1) + next.slice(before);
|
|
368
|
+
before -= 1;
|
|
369
|
+
}
|
|
370
|
+
next = next.slice(0, max);
|
|
371
|
+
onValueChange(next);
|
|
372
|
+
// Cursor logo depois do mesmo número em que estava, e não no fim do campo.
|
|
373
|
+
requestAnimationFrame(() => {
|
|
374
|
+
const input = ref.current;
|
|
375
|
+
if (!input || document.activeElement !== input) return;
|
|
376
|
+
const text = formatMask(next, mask);
|
|
377
|
+
let pos = 0;
|
|
378
|
+
let seen = 0;
|
|
379
|
+
while (pos < text.length && seen < before) {
|
|
380
|
+
if (/\d/.test(text[pos]!)) seen++;
|
|
381
|
+
pos++;
|
|
382
|
+
}
|
|
383
|
+
input.setSelectionRange(pos, pos);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const field = {
|
|
388
|
+
ref,
|
|
389
|
+
inputMode: 'numeric' as const,
|
|
390
|
+
placeholder: placeholder ?? (mask in PLACEHOLDER ? PLACEHOLDER[mask as MaskName] : undefined),
|
|
391
|
+
value: shown,
|
|
392
|
+
onChange: change,
|
|
393
|
+
'data-mask': mask,
|
|
394
|
+
...props,
|
|
395
|
+
};
|
|
396
|
+
if (addon === undefined) return <Input data-slot="masked-input" size={size} {...field} />;
|
|
397
|
+
return (
|
|
398
|
+
<InputGroup data-slot="masked-input" size={size ?? 'default'}>
|
|
399
|
+
<InputGroupInput {...field} />
|
|
400
|
+
{addon && <InputGroupAddon align="inline-end">{addon}</InputGroupAddon>}
|
|
401
|
+
</InputGroup>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Campo de valor em dinheiro, já formatado em reais: digita 1250 e vê "R$ 1.250,00". O valor
|
|
406
|
+
// entregue ao app é número, sem formatação.
|
|
407
|
+
|
|
408
|
+
function CurrencyInput({
|
|
409
|
+
value,
|
|
410
|
+
onValueChange,
|
|
411
|
+
currency = 'BRL',
|
|
412
|
+
min = 0,
|
|
413
|
+
max,
|
|
414
|
+
disabled,
|
|
415
|
+
id,
|
|
416
|
+
className,
|
|
417
|
+
size = 'default',
|
|
418
|
+
'aria-label': ariaLabel,
|
|
419
|
+
'aria-invalid': ariaInvalid,
|
|
420
|
+
}: {
|
|
421
|
+
value: number | null;
|
|
422
|
+
onValueChange: (value: number | null) => void;
|
|
423
|
+
currency?: string;
|
|
424
|
+
min?: number;
|
|
425
|
+
max?: number;
|
|
426
|
+
disabled?: boolean;
|
|
427
|
+
id?: string;
|
|
428
|
+
className?: string;
|
|
429
|
+
/** Altura 32, 40 ou 48, como o Input. */
|
|
430
|
+
size?: 'sm' | 'default' | 'lg';
|
|
431
|
+
'aria-label'?: string;
|
|
432
|
+
'aria-invalid'?: boolean;
|
|
433
|
+
}) {
|
|
434
|
+
return (
|
|
435
|
+
<NumberField.Root
|
|
436
|
+
value={value}
|
|
437
|
+
onValueChange={(v) => onValueChange(v)}
|
|
438
|
+
min={min}
|
|
439
|
+
max={max}
|
|
440
|
+
step={0.01}
|
|
441
|
+
disabled={disabled}
|
|
442
|
+
locale="pt-BR"
|
|
443
|
+
format={{ style: 'currency', currency }}
|
|
444
|
+
className={cn('w-full', className)}
|
|
445
|
+
>
|
|
446
|
+
<NumberField.Input
|
|
447
|
+
id={id}
|
|
448
|
+
data-slot="currency-input"
|
|
449
|
+
data-size={size}
|
|
450
|
+
aria-label={ariaLabel}
|
|
451
|
+
aria-invalid={ariaInvalid}
|
|
452
|
+
placeholder="R$ 0,00"
|
|
453
|
+
className="h-control data-[size=sm]:h-control-sm data-[size=lg]:h-control-lg w-full min-w-0 rounded-control border border-input bg-surface-control px-2.5 text-body-13 tabular-nums transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring-strong focus-visible:focus-ring-field disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-ring-invalid"
|
|
454
|
+
/>
|
|
455
|
+
</NumberField.Root>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export {
|
|
460
|
+
Input,
|
|
461
|
+
SearchInput,
|
|
462
|
+
MaskedInput,
|
|
463
|
+
CurrencyInput,
|
|
464
|
+
InputGroup,
|
|
465
|
+
InputGroupAddon,
|
|
466
|
+
InputGroupButton,
|
|
467
|
+
InputGroupText,
|
|
468
|
+
InputGroupInput,
|
|
469
|
+
InputGroupTextarea,
|
|
470
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
import Link from './link';
|
|
4
|
+
|
|
5
|
+
// Lista dentro de cartão, D-704: cada linha com o ícone numa caixinha de 32, o nome, o detalhe e,
|
|
6
|
+
// à direita, o valor, um selo ou a ação. Sem caixa em volta de cada item, regra das telas de
|
|
7
|
+
// produto: itens do mesmo tipo juntos, sem linha entre eles. Com `href` ou `onClick`, a linha toda
|
|
8
|
+
// abre o item. Serve a negócios da ficha, aparelhos, contas conectadas e arquivos.
|
|
9
|
+
|
|
10
|
+
function ItemList({ className, children }: { className?: string; children: ReactNode }) {
|
|
11
|
+
return (
|
|
12
|
+
<ul data-slot="item-list" className={cn('-mx-2 grid gap-0.5', className)}>
|
|
13
|
+
{children}
|
|
14
|
+
</ul>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function ItemRow({
|
|
19
|
+
icon,
|
|
20
|
+
media,
|
|
21
|
+
title,
|
|
22
|
+
description,
|
|
23
|
+
aside,
|
|
24
|
+
actions,
|
|
25
|
+
below,
|
|
26
|
+
href,
|
|
27
|
+
onClick,
|
|
28
|
+
className,
|
|
29
|
+
}: {
|
|
30
|
+
/** Ícone do item, na caixinha cinza de 32. */
|
|
31
|
+
icon?: ReactNode;
|
|
32
|
+
/** No lugar do ícone, uma foto, um avatar ou uma logo. */
|
|
33
|
+
media?: ReactNode;
|
|
34
|
+
title: ReactNode;
|
|
35
|
+
description?: ReactNode;
|
|
36
|
+
/** À direita: o valor, um selo ou uma data. */
|
|
37
|
+
aside?: ReactNode;
|
|
38
|
+
/** Botões à direita, depois do `aside`. Ficam acima do clique da linha. */
|
|
39
|
+
actions?: ReactNode;
|
|
40
|
+
/** Embaixo da linha, alinhado ao texto, como o aviso de uma conexão com erro. */
|
|
41
|
+
below?: ReactNode;
|
|
42
|
+
href?: string;
|
|
43
|
+
onClick?: () => void;
|
|
44
|
+
className?: string;
|
|
45
|
+
}) {
|
|
46
|
+
const opens = href || onClick;
|
|
47
|
+
return (
|
|
48
|
+
<li
|
|
49
|
+
data-slot="item-row"
|
|
50
|
+
className={cn(
|
|
51
|
+
'relative flex min-h-control-lg flex-wrap items-center gap-x-3 gap-y-1 rounded-control px-2 py-1.5',
|
|
52
|
+
opens && 'hover:bg-hover has-focus-visible:focus-ring',
|
|
53
|
+
className,
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
{media ??
|
|
57
|
+
(icon && (
|
|
58
|
+
<span className="grid size-8 shrink-0 place-items-center rounded-control bg-muted text-muted-foreground [&_svg]:size-icon-lg">
|
|
59
|
+
{icon}
|
|
60
|
+
</span>
|
|
61
|
+
))}
|
|
62
|
+
<span className="grid min-w-0 flex-1">
|
|
63
|
+
{href ? (
|
|
64
|
+
<Link
|
|
65
|
+
href={href}
|
|
66
|
+
className="truncate text-body-13-medium outline-none after:absolute after:inset-0"
|
|
67
|
+
>
|
|
68
|
+
{title}
|
|
69
|
+
</Link>
|
|
70
|
+
) : onClick ? (
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
onClick={onClick}
|
|
74
|
+
className="truncate text-left text-body-13-medium outline-none after:absolute after:inset-0"
|
|
75
|
+
>
|
|
76
|
+
{title}
|
|
77
|
+
</button>
|
|
78
|
+
) : (
|
|
79
|
+
<span className="truncate text-body-13-medium">{title}</span>
|
|
80
|
+
)}
|
|
81
|
+
{description && (
|
|
82
|
+
<span className="truncate text-body-12 text-muted-foreground">{description}</span>
|
|
83
|
+
)}
|
|
84
|
+
</span>
|
|
85
|
+
{aside && <span className="shrink-0 text-body-13 tabular-nums">{aside}</span>}
|
|
86
|
+
{actions && <span className="relative z-10 flex shrink-0 items-center gap-1">{actions}</span>}
|
|
87
|
+
{below && (
|
|
88
|
+
<span className={cn('relative z-10 basis-full', (icon || media) && 'pl-11')}>{below}</span>
|
|
89
|
+
)}
|
|
90
|
+
</li>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { ItemList, ItemRow };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cn } from '../lib/utils';
|
|
2
|
+
|
|
3
|
+
// Tecla de atalho, desenhada como uma tecla de verdade: borda e um relevo embaixo (D-150).
|
|
4
|
+
|
|
5
|
+
function Kbd({ className, ...props }: React.ComponentProps<'kbd'>) {
|
|
6
|
+
return (
|
|
7
|
+
<kbd
|
|
8
|
+
data-slot="kbd"
|
|
9
|
+
className={cn(
|
|
10
|
+
"pointer-events-none inline-flex h-6 w-fit min-w-6 items-center justify-center gap-1 rounded-item border border-b-2 bg-card px-1 in-data-[slot=button]:h-5 in-data-[slot=button]:min-w-5 in-data-[slot=button]:rounded-item in-data-[slot=button]:text-body-11-medium font-sans text-body-12-medium text-muted-foreground select-none in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 [&_svg:not([class*='size-'])]:size-3",
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function KbdGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
19
|
+
return (
|
|
20
|
+
<kbd
|
|
21
|
+
data-slot="kbd-group"
|
|
22
|
+
className={cn('inline-flex items-center gap-1', className)}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { Kbd, KbdGroup };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
|
|
4
|
+
// O rótulo ganha o id `${htmlFor}-label`, para caixa de marcar, interruptor e opção única
|
|
5
|
+
// conseguirem ser anunciados pelo nome.
|
|
6
|
+
function Label({ className, id, htmlFor, ...props }: React.ComponentProps<'label'>) {
|
|
7
|
+
return (
|
|
8
|
+
<label
|
|
9
|
+
data-slot="label"
|
|
10
|
+
id={id ?? (htmlFor ? `${htmlFor}-label` : undefined)}
|
|
11
|
+
htmlFor={htmlFor}
|
|
12
|
+
className={cn(
|
|
13
|
+
'flex items-center gap-2 text-body-13-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50 peer-data-disabled:cursor-not-allowed peer-data-disabled:opacity-50',
|
|
14
|
+
className,
|
|
15
|
+
)}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { Label };
|