@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.
Files changed (116) hide show
  1. package/README.md +13 -2
  2. package/bin/vowt-ux-ui-design.mjs +483 -0
  3. package/guia/LEIA-PRIMEIRO.md +106 -0
  4. package/guia/VERSAO +1 -0
  5. package/guia/componentes.md +104 -0
  6. package/guia/regras/atualizar.md +136 -0
  7. package/guia/regras/componentes.md +374 -0
  8. package/guia/regras/fundamentos.md +257 -0
  9. package/guia/regras/marca.md +200 -0
  10. package/guia/regras/medidas.md +114 -0
  11. package/guia/regras/regras-de-base.md +85 -0
  12. package/guia/regras/telas/acoes.md +56 -0
  13. package/guia/regras/telas/direcao-ux.md +327 -0
  14. package/guia/regras/telas/padroes.md +58 -0
  15. package/guia/regras/telas/regras.md +171 -0
  16. package/guia/regras/telas/voz.md +134 -0
  17. package/package.json +72 -4
  18. package/src/brand/icons.ts +215 -0
  19. package/src/brand/logo.tsx +288 -0
  20. package/src/components/accordion.tsx +58 -0
  21. package/src/components/ai-orb.tsx +67 -0
  22. package/src/components/alert-dialog.tsx +227 -0
  23. package/src/components/alert.tsx +128 -0
  24. package/src/components/area-chart.tsx +180 -0
  25. package/src/components/attachment.tsx +339 -0
  26. package/src/components/avatar.tsx +197 -0
  27. package/src/components/badge.tsx +242 -0
  28. package/src/components/bar-chart.tsx +138 -0
  29. package/src/components/bar-list.tsx +85 -0
  30. package/src/components/brand-icon.tsx +52 -0
  31. package/src/components/breadcrumb.tsx +96 -0
  32. package/src/components/button-group.tsx +29 -0
  33. package/src/components/button.tsx +208 -0
  34. package/src/components/calendar.tsx +238 -0
  35. package/src/components/card.tsx +136 -0
  36. package/src/components/chart.tsx +289 -0
  37. package/src/components/checkbox.tsx +42 -0
  38. package/src/components/code-block.tsx +31 -0
  39. package/src/components/collapsible.tsx +114 -0
  40. package/src/components/color-picker.tsx +93 -0
  41. package/src/components/combo-chart.tsx +139 -0
  42. package/src/components/combobox.tsx +200 -0
  43. package/src/components/command.tsx +191 -0
  44. package/src/components/date-picker.tsx +435 -0
  45. package/src/components/description-list.tsx +280 -0
  46. package/src/components/dialog.tsx +192 -0
  47. package/src/components/diff-view.tsx +109 -0
  48. package/src/components/dropdown-menu.tsx +248 -0
  49. package/src/components/emoji-picker.tsx +299 -0
  50. package/src/components/empty.tsx +197 -0
  51. package/src/components/field.tsx +226 -0
  52. package/src/components/file-upload.tsx +186 -0
  53. package/src/components/funnel-chart.tsx +224 -0
  54. package/src/components/gauge-chart.tsx +109 -0
  55. package/src/components/heatmap.tsx +105 -0
  56. package/src/components/hover-card.tsx +47 -0
  57. package/src/components/image-viewer.tsx +174 -0
  58. package/src/components/input-otp.tsx +86 -0
  59. package/src/components/input.tsx +470 -0
  60. package/src/components/item.tsx +94 -0
  61. package/src/components/kbd.tsx +28 -0
  62. package/src/components/label.tsx +21 -0
  63. package/src/components/line-chart.tsx +92 -0
  64. package/src/components/link.tsx +34 -0
  65. package/src/components/message.tsx +903 -0
  66. package/src/components/number-field.tsx +79 -0
  67. package/src/components/pagination.tsx +208 -0
  68. package/src/components/phone-input.tsx +147 -0
  69. package/src/components/pie-chart.tsx +117 -0
  70. package/src/components/popover.tsx +102 -0
  71. package/src/components/powered-by.tsx +39 -0
  72. package/src/components/progress.tsx +278 -0
  73. package/src/components/prose.tsx +42 -0
  74. package/src/components/radar-chart.tsx +66 -0
  75. package/src/components/radial-chart.tsx +73 -0
  76. package/src/components/radio-group.tsx +135 -0
  77. package/src/components/rating.tsx +192 -0
  78. package/src/components/rich-text.tsx +1651 -0
  79. package/src/components/scatter-chart.tsx +115 -0
  80. package/src/components/scroll-area.tsx +50 -0
  81. package/src/components/select.tsx +193 -0
  82. package/src/components/separator.tsx +20 -0
  83. package/src/components/sheet.tsx +142 -0
  84. package/src/components/sidebar.tsx +570 -0
  85. package/src/components/skeleton.tsx +18 -0
  86. package/src/components/slider.tsx +47 -0
  87. package/src/components/sonner.tsx +178 -0
  88. package/src/components/sparkline.tsx +68 -0
  89. package/src/components/spinner.tsx +35 -0
  90. package/src/components/status-dot.tsx +45 -0
  91. package/src/components/stepper.tsx +228 -0
  92. package/src/components/switch.tsx +35 -0
  93. package/src/components/table.tsx +267 -0
  94. package/src/components/tabs.tsx +184 -0
  95. package/src/components/tag-input.tsx +238 -0
  96. package/src/components/textarea.tsx +47 -0
  97. package/src/components/time-picker.tsx +183 -0
  98. package/src/components/timeline.tsx +75 -0
  99. package/src/components/toggle-group.tsx +93 -0
  100. package/src/components/toggle.tsx +51 -0
  101. package/src/components/tooltip.tsx +160 -0
  102. package/src/components/tree.tsx +136 -0
  103. package/src/components/voice-message.tsx +193 -0
  104. package/src/css.d.ts +2 -0
  105. package/src/hooks/use-appearance.ts +57 -0
  106. package/src/hooks/use-mobile.ts +20 -0
  107. package/src/lib/appearance.ts +16 -0
  108. package/src/lib/button-render.ts +32 -0
  109. package/src/lib/char-count.tsx +67 -0
  110. package/src/lib/date.ts +45 -0
  111. package/src/lib/file-accept.ts +59 -0
  112. package/src/lib/markdown.ts +187 -0
  113. package/src/lib/utils.ts +29 -0
  114. package/src/lib/voice.ts +68 -0
  115. package/src/styles/shadcn.css +642 -0
  116. package/src/styles/theme.css +1825 -0
@@ -0,0 +1,139 @@
1
+ 'use client';
2
+
3
+ import { Bar, CartesianGrid, ComposedChart, Line, ReferenceLine, XAxis, YAxis } from 'recharts';
4
+ import {
5
+ AXIS,
6
+ type ChartDatum,
7
+ type ChartSeries,
8
+ ChartContainer,
9
+ ChartLegend,
10
+ ChartTooltip,
11
+ formatNumber,
12
+ seriesConfig,
13
+ CHART_ANIMATION,
14
+ } from './chart';
15
+ import { cn } from '../lib/utils';
16
+
17
+ // Barras com linha no mesmo gráfico (D-156), como as vendas de cada dia e a média da semana, ou o
18
+ // realizado e a meta. As duas medidas dividem o MESMO eixo: nunca dois eixos com escalas
19
+ // diferentes, que enganam a leitura. Medidas de unidades diferentes vão em dois gráficos.
20
+ // Exceção, D-635: com `lineFormat`, a linha ganha o próprio eixo, à direita, para medidas de
21
+ // unidades diferentes que se leem juntas, como a receita em R$ e o número de clientes. Cada eixo
22
+ // mostra a sua unidade, e o balão formata cada série do seu jeito.
23
+ //
24
+ // Escala honesta, D-827: a meta entra por `goal`, como linha de referência, e não como série. A
25
+ // escala segue as barras, que usam a altura do gráfico. A linha só estica o eixo quando fica até
26
+ // 25% acima da maior barra; mais longe que isso, ela sai do desenho e a legenda avisa, em vez de
27
+ // achatar as barras.
28
+
29
+ /** Chave da meta na legenda, fora das séries de dados. */
30
+ const GOAL_KEY = '__goal';
31
+ /** Até quanto acima da maior barra a meta ainda entra no desenho. */
32
+ const GOAL_REACH = 1.25;
33
+
34
+ function ComboChart({
35
+ data,
36
+ index,
37
+ bars,
38
+ lines,
39
+ goal,
40
+ yAxis = true,
41
+ format = formatNumber,
42
+ lineFormat,
43
+ className,
44
+ }: {
45
+ data: ChartDatum[];
46
+ index: string;
47
+ /** Séries em barra, como as vendas de cada dia. */
48
+ bars: ChartSeries[];
49
+ /** Séries em linha, na mesma unidade, como a média ou a meta. */
50
+ lines: ChartSeries[];
51
+ /**
52
+ * Meta, na unidade das barras: linha tracejada de referência, que não achata as barras, D-827.
53
+ * No rótulo, o nome com o valor, como "Meta da semana, R$ 15.000,00".
54
+ */
55
+ goal?: { value: number; label: string };
56
+ yAxis?: boolean;
57
+ format?: (value: unknown) => string;
58
+ /** Unidade das linhas, quando é outra: elas vão para um eixo à direita, D-635. */
59
+ lineFormat?: (value: unknown) => string;
60
+ className?: string;
61
+ }) {
62
+ // O maior valor do eixo das barras, para saber se a meta cabe sem achatar o desenho.
63
+ const leftKeys = [...bars, ...(lineFormat ? [] : lines)].map((s) => s.key);
64
+ const top = Math.max(0, ...data.flatMap((d) => leftKeys.map((k) => Number(d[k]) || 0)));
65
+ const goalFits = !!goal && goal.value <= top * GOAL_REACH;
66
+ const config = seriesConfig([...bars, ...lines]);
67
+ if (goal)
68
+ config[GOAL_KEY] = {
69
+ label: goalFits ? goal.label : `${goal.label}, acima do gráfico`,
70
+ color: 'var(--muted-foreground)',
71
+ };
72
+ return (
73
+ <ChartContainer config={config} className={cn('aspect-auto h-64', className)}>
74
+ {(hidden) => (
75
+ <ComposedChart data={data} margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
76
+ <CartesianGrid vertical={false} />
77
+ <XAxis dataKey={index} {...AXIS} minTickGap={8} />
78
+ {yAxis && (
79
+ <YAxis yAxisId="left" {...AXIS} width="auto" tickFormatter={(v) => format(v)} />
80
+ )}
81
+ {lineFormat && yAxis && (
82
+ <YAxis
83
+ yAxisId="right"
84
+ orientation="right"
85
+ {...AXIS}
86
+ width="auto"
87
+ tickFormatter={(v) => lineFormat(v)}
88
+ />
89
+ )}
90
+ {!yAxis && <YAxis yAxisId="left" hide />}
91
+ {lineFormat && !yAxis && <YAxis yAxisId="right" hide />}
92
+ <ChartTooltip
93
+ formatValue={(v, key) =>
94
+ lineFormat && lines.some((s) => s.key === key) ? lineFormat(v) : format(v)
95
+ }
96
+ />
97
+ <ChartLegend />
98
+ {goal && goalFits && !hidden.has(GOAL_KEY) && (
99
+ <ReferenceLine
100
+ yAxisId="left"
101
+ y={goal.value}
102
+ ifOverflow="extendDomain"
103
+ stroke="var(--muted-foreground)"
104
+ strokeDasharray="4 4"
105
+ />
106
+ )}
107
+ {bars.map((s) => (
108
+ <Bar
109
+ key={s.key}
110
+ yAxisId="left"
111
+ dataKey={s.key}
112
+ hide={hidden.has(s.key)}
113
+ fill={`var(--color-${s.key})`}
114
+ radius={[4, 4, 0, 0]}
115
+ maxBarSize={40}
116
+ />
117
+ ))}
118
+ {lines.map((s) => (
119
+ <Line
120
+ key={s.key}
121
+ {...CHART_ANIMATION}
122
+ yAxisId={lineFormat ? 'right' : 'left'}
123
+ dataKey={s.key}
124
+ hide={hidden.has(s.key)}
125
+ type="monotone"
126
+ stroke={`var(--color-${s.key})`}
127
+ strokeWidth={2}
128
+ strokeDasharray={s.dashed ? '4 4' : undefined}
129
+ dot={false}
130
+ activeDot={{ r: 4, strokeWidth: 2, stroke: 'var(--card)' }}
131
+ />
132
+ ))}
133
+ </ComposedChart>
134
+ )}
135
+ </ChartContainer>
136
+ );
137
+ }
138
+
139
+ export { ComboChart };
@@ -0,0 +1,200 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { Combobox as ComboboxPrimitive } from '@base-ui/react/combobox';
5
+ import { CheckIcon, ChevronsUpDownIcon, XIcon } from 'lucide-react';
6
+ import { cn } from '../lib/utils';
7
+
8
+ // Escolha de uma opção numa lista longa, com busca: digitar filtra a lista. Para poucas opções, use
9
+ // o Select; para escolher várias, o Multi-select.
10
+
11
+ export type ComboboxOption = { value: string; label: string };
12
+
13
+ /** Classes do campo, iguais às do Input. */
14
+ export const comboboxFieldClass =
15
+ 'w-full min-w-0 rounded-control border border-input bg-surface-control text-body-13 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';
16
+
17
+ /** Classes da lista aberta e dos itens, iguais às do Select. */
18
+ export const comboboxPopupClass =
19
+ 'isolate z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-hidden rounded-menu bg-popover text-popover-foreground shadow-menu ring-1 ring-border duration-(--duration-fast) data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95';
20
+ export const comboboxItemClass =
21
+ 'relative flex w-full cursor-default items-center min-h-control-sm gap-2 rounded-item py-1.5 pr-8 pl-3 text-body-13 outline-hidden select-none data-highlighted:bg-hover data-disabled:pointer-events-none data-disabled:opacity-50';
22
+
23
+ function Combobox({
24
+ options,
25
+ value,
26
+ onValueChange,
27
+ placeholder = 'Buscar',
28
+ emptyText = 'Nada encontrado.',
29
+ disabled,
30
+ id,
31
+ size = 'default',
32
+ className,
33
+ 'aria-label': ariaLabel,
34
+ 'aria-invalid': ariaInvalid,
35
+ }: {
36
+ options: ComboboxOption[];
37
+ value: string | null;
38
+ onValueChange: (value: string | null) => void;
39
+ placeholder?: string;
40
+ emptyText?: string;
41
+ disabled?: boolean;
42
+ id?: string;
43
+ /** Altura 32, 40 ou 48, como o Input. */
44
+ size?: 'sm' | 'default' | 'lg';
45
+ className?: string;
46
+ 'aria-label'?: string;
47
+ 'aria-invalid'?: boolean;
48
+ }) {
49
+ const selected = options.find((o) => o.value === value) ?? null;
50
+ return (
51
+ <ComboboxPrimitive.Root
52
+ items={options}
53
+ value={selected}
54
+ onValueChange={(o: ComboboxOption | null) => onValueChange(o?.value ?? null)}
55
+ disabled={disabled}
56
+ >
57
+ <div data-slot="combobox" data-size={size} className={cn('relative w-full', className)}>
58
+ <ComboboxPrimitive.Input
59
+ id={id}
60
+ placeholder={placeholder}
61
+ aria-label={ariaLabel}
62
+ aria-invalid={ariaInvalid}
63
+ className={cn(
64
+ comboboxFieldClass,
65
+ 'pr-10 pl-3',
66
+ size === 'sm' ? 'h-control-sm' : size === 'lg' ? 'h-control-lg' : 'h-control',
67
+ )}
68
+ />
69
+ <ComboboxPrimitive.Trigger
70
+ aria-label="Abrir opções"
71
+ className={cn(
72
+ 'absolute top-1/2 right-1.5 flex size-control-xs -translate-y-1/2 items-center justify-center rounded-control text-muted-foreground outline-none hover:bg-hover focus-visible:focus-ring-field',
73
+ size === 'sm' && 'right-1 size-6',
74
+ )}
75
+ >
76
+ <ChevronsUpDownIcon className="size-icon-xs" />
77
+ </ComboboxPrimitive.Trigger>
78
+ </div>
79
+ <ComboboxPrimitive.Portal>
80
+ <ComboboxPrimitive.Positioner sideOffset={6} className="isolate z-50">
81
+ <ComboboxPrimitive.Popup data-slot="combobox-content" className={comboboxPopupClass}>
82
+ <ComboboxPrimitive.Empty className="text-body-13 text-muted-foreground empty:hidden px-2.5 py-6 text-center">
83
+ {emptyText}
84
+ </ComboboxPrimitive.Empty>
85
+ <ComboboxPrimitive.List className="max-h-72 overflow-y-auto p-1 empty:hidden">
86
+ {(o: ComboboxOption) => (
87
+ <ComboboxPrimitive.Item key={o.value} value={o} className={comboboxItemClass}>
88
+ <span className="min-w-0 flex-1 truncate">{o.label}</span>
89
+ <ComboboxPrimitive.ItemIndicator className="absolute right-3 flex size-4 items-center justify-center">
90
+ <CheckIcon className="size-icon-lg" />
91
+ </ComboboxPrimitive.ItemIndicator>
92
+ </ComboboxPrimitive.Item>
93
+ )}
94
+ </ComboboxPrimitive.List>
95
+ </ComboboxPrimitive.Popup>
96
+ </ComboboxPrimitive.Positioner>
97
+ </ComboboxPrimitive.Portal>
98
+ </ComboboxPrimitive.Root>
99
+ );
100
+ }
101
+
102
+ // Escolha de várias opções numa lista, com busca. Cada escolhida vira uma etiqueta dentro do campo,
103
+ // com um X para tirar. Exemplo: categorias de um produto.
104
+
105
+ function MultiSelect({
106
+ options,
107
+ value,
108
+ onValueChange,
109
+ placeholder = 'Buscar',
110
+ emptyText = 'Nada encontrado.',
111
+ disabled,
112
+ id,
113
+ className,
114
+ 'aria-label': ariaLabel,
115
+ }: {
116
+ options: ComboboxOption[];
117
+ value: string[];
118
+ onValueChange: (value: string[]) => void;
119
+ placeholder?: string;
120
+ emptyText?: string;
121
+ disabled?: boolean;
122
+ id?: string;
123
+ className?: string;
124
+ 'aria-label'?: string;
125
+ }) {
126
+ const anchor = React.useRef<HTMLDivElement>(null);
127
+ const selected = options.filter((o) => value.includes(o.value));
128
+ return (
129
+ <ComboboxPrimitive.Root
130
+ multiple
131
+ items={options}
132
+ value={selected}
133
+ onValueChange={(next: ComboboxOption[]) => onValueChange(next.map((o) => o.value))}
134
+ disabled={disabled}
135
+ >
136
+ <ComboboxPrimitive.Chips
137
+ ref={anchor}
138
+ data-slot="multi-select"
139
+ className={cn(
140
+ comboboxFieldClass,
141
+ 'flex min-h-control flex-wrap items-center gap-1.5 px-2 py-1 focus-within:border-ring-strong focus-within:focus-ring-field',
142
+ className,
143
+ )}
144
+ >
145
+ <ComboboxPrimitive.Value>
146
+ {(items: ComboboxOption[]) => (
147
+ <>
148
+ {items.map((o) => (
149
+ <ComboboxPrimitive.Chip
150
+ key={o.value}
151
+ className="inline-flex h-control-xs items-center gap-1 rounded-full bg-muted pr-1 pl-2.5 text-body-13-medium outline-none data-highlighted:bg-selected"
152
+ >
153
+ {o.label}
154
+ <ComboboxPrimitive.ChipRemove
155
+ aria-label={`Remover ${o.label}`}
156
+ className="relative flex size-5 items-center justify-center rounded-full text-muted-foreground after:absolute after:-inset-1 hover:bg-card hover:text-foreground"
157
+ >
158
+ <XIcon className="size-icon-xs" />
159
+ </ComboboxPrimitive.ChipRemove>
160
+ </ComboboxPrimitive.Chip>
161
+ ))}
162
+ <ComboboxPrimitive.Input
163
+ id={id}
164
+ aria-label={ariaLabel}
165
+ placeholder={items.length ? '' : placeholder}
166
+ // Com etiquetas, o campo de busca só precisa do espaço do cursor: assim não desce
167
+ // sozinho para uma segunda linha vazia.
168
+ className={cn(
169
+ 'h-control-xs flex-1 bg-transparent px-1.5 text-body-13 outline-none placeholder:text-muted-foreground',
170
+ items.length ? 'min-w-12' : 'min-w-24',
171
+ )}
172
+ />
173
+ </>
174
+ )}
175
+ </ComboboxPrimitive.Value>
176
+ </ComboboxPrimitive.Chips>
177
+ <ComboboxPrimitive.Portal>
178
+ <ComboboxPrimitive.Positioner anchor={anchor} sideOffset={6} className="isolate z-50">
179
+ <ComboboxPrimitive.Popup data-slot="multi-select-content" className={comboboxPopupClass}>
180
+ <ComboboxPrimitive.Empty className="text-body-13 text-muted-foreground empty:hidden px-2.5 py-6 text-center">
181
+ {emptyText}
182
+ </ComboboxPrimitive.Empty>
183
+ <ComboboxPrimitive.List className="max-h-72 overflow-y-auto p-1.5 empty:hidden">
184
+ {(o: ComboboxOption) => (
185
+ <ComboboxPrimitive.Item key={o.value} value={o} className={comboboxItemClass}>
186
+ <span className="min-w-0 flex-1 truncate">{o.label}</span>
187
+ <ComboboxPrimitive.ItemIndicator className="absolute right-2.5 flex size-4 items-center justify-center">
188
+ <CheckIcon className="size-icon-lg" />
189
+ </ComboboxPrimitive.ItemIndicator>
190
+ </ComboboxPrimitive.Item>
191
+ )}
192
+ </ComboboxPrimitive.List>
193
+ </ComboboxPrimitive.Popup>
194
+ </ComboboxPrimitive.Positioner>
195
+ </ComboboxPrimitive.Portal>
196
+ </ComboboxPrimitive.Root>
197
+ );
198
+ }
199
+
200
+ export { Combobox, MultiSelect };
@@ -0,0 +1,191 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { Autocomplete } from '@base-ui/react/autocomplete';
5
+ import {
6
+ ArrowDownIcon,
7
+ ArrowRightIcon,
8
+ ArrowUpIcon,
9
+ CornerDownLeftIcon,
10
+ SearchIcon,
11
+ } from 'lucide-react';
12
+ import { cn } from '../lib/utils';
13
+
14
+ import { Dialog, DialogContent, DialogTitle } from './dialog';
15
+ import { Kbd } from './kbd';
16
+ import { Skeleton } from './skeleton';
17
+
18
+ // Busca rápida do painel, aberta com Ctrl K (Cmd K no Mac): ir para uma página ou fazer uma ação
19
+ // sem usar o mouse. Cada produto passa os seus grupos de itens. Com `onQueryChange`, quem filtra é o
20
+ // app, que devolve os resultados já agrupados, como Contatos, Empresas e Negócios.
21
+
22
+ export type CommandItem = {
23
+ /** Identificador único do item. */
24
+ value: string;
25
+ /** Texto mostrado e usado na busca. */
26
+ label: string;
27
+ /** Linha de baixo, como o telefone do contato ou o CNPJ da empresa. */
28
+ description?: string;
29
+ /** Ícone ou foto à esquerda, como o Avatar do contato. */
30
+ icon?: React.ReactNode;
31
+ /** Atalho mostrado à direita, como "G P". Só informativo. */
32
+ shortcut?: string;
33
+ onSelect: () => void;
34
+ };
35
+ export type CommandGroup = { value: string; items: CommandItem[] };
36
+
37
+ function CommandMenu({
38
+ open,
39
+ onOpenChange,
40
+ groups,
41
+ placeholder = 'Buscar ou ir para…',
42
+ emptyText = 'Nada encontrado.',
43
+ shortcut = true,
44
+ onQueryChange,
45
+ loading = false,
46
+ hint,
47
+ }: {
48
+ open: boolean;
49
+ onOpenChange: (open: boolean) => void;
50
+ groups: CommandGroup[];
51
+ placeholder?: string;
52
+ /** Texto de quando nada aparece; como função, recebe o que foi digitado. */
53
+ emptyText?: React.ReactNode | ((query: string) => React.ReactNode);
54
+ /** Abre e fecha com Ctrl K. */
55
+ shortcut?: boolean;
56
+ /** O app filtra: recebe o texto e devolve em `groups` só o que encontrou. */
57
+ onQueryChange?: (query: string) => void;
58
+ /** Mostra linhas de espera enquanto o app procura. */
59
+ loading?: boolean;
60
+ /** Dica antes de digitar, como o que dá para procurar. */
61
+ hint?: React.ReactNode;
62
+ }) {
63
+ const input = React.useRef<HTMLInputElement>(null);
64
+ const [query, setQuery] = React.useState('');
65
+ // Cada abertura começa sem texto.
66
+ React.useEffect(() => {
67
+ if (!open) {
68
+ setQuery('');
69
+ onQueryChange?.('');
70
+ }
71
+ }, [open]);
72
+ React.useEffect(() => {
73
+ if (!shortcut) return;
74
+ const onKey = (e: KeyboardEvent) => {
75
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
76
+ e.preventDefault();
77
+ onOpenChange(!open);
78
+ }
79
+ };
80
+ window.addEventListener('keydown', onKey);
81
+ return () => window.removeEventListener('keydown', onKey);
82
+ }, [shortcut, open, onOpenChange]);
83
+
84
+ return (
85
+ <Dialog open={open} onOpenChange={onOpenChange}>
86
+ <DialogContent
87
+ showCloseButton={false}
88
+ initialFocus={input}
89
+ className="top-[20%] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-lg"
90
+ >
91
+ <DialogTitle className="sr-only">Busca rápida</DialogTitle>
92
+ <Autocomplete.Root
93
+ inline
94
+ open
95
+ items={groups}
96
+ autoHighlight="always"
97
+ mode={onQueryChange ? 'none' : 'list'}
98
+ value={query}
99
+ onValueChange={(q) => {
100
+ setQuery(q);
101
+ onQueryChange?.(q);
102
+ }}
103
+ >
104
+ <div className="flex items-center gap-2.5 border-b px-4">
105
+ <SearchIcon className="size-icon-lg shrink-0 text-muted-foreground" />
106
+ <Autocomplete.Input
107
+ ref={input}
108
+ data-slot="command-menu-input"
109
+ placeholder={placeholder}
110
+ className="h-12 min-w-0 flex-1 bg-transparent text-body-13 outline-none placeholder:text-muted-foreground"
111
+ />
112
+ <Kbd>Esc</Kbd>
113
+ </div>
114
+ {hint && !query && (
115
+ <div className="border-b px-4 py-3 text-body-12 text-muted-foreground">{hint}</div>
116
+ )}
117
+ {loading ? (
118
+ <div className="grid gap-2 p-4" aria-label="Procurando">
119
+ {[0, 1, 2].map((i) => (
120
+ <Skeleton key={i} className="h-control-sm" />
121
+ ))}
122
+ </div>
123
+ ) : (
124
+ <Autocomplete.Empty className="text-body-13 text-muted-foreground empty:hidden px-4 py-8 text-center">
125
+ {typeof emptyText === 'function' ? emptyText(query) : emptyText}
126
+ </Autocomplete.Empty>
127
+ )}
128
+ <Autocomplete.List
129
+ data-slot="command-menu-list"
130
+ className="max-h-80 overflow-y-auto p-2 empty:hidden"
131
+ >
132
+ {(group: CommandGroup) => (
133
+ <Autocomplete.Group key={group.value} items={group.items} className="not-first:mt-1">
134
+ <Autocomplete.GroupLabel className="px-2.5 pt-2 pb-1 text-body-12-medium text-muted-foreground">
135
+ {group.value}
136
+ </Autocomplete.GroupLabel>
137
+ <Autocomplete.Collection>
138
+ {(item: CommandItem) => (
139
+ <Autocomplete.Item
140
+ key={item.value}
141
+ value={item}
142
+ onClick={() => {
143
+ item.onSelect();
144
+ onOpenChange(false);
145
+ }}
146
+ className={cn(
147
+ 'group/item flex min-h-control-sm cursor-default items-center gap-2 rounded-item px-2.5 py-1.5 text-body-13 outline-none select-none data-highlighted:bg-hover',
148
+ '[&_svg]:size-icon-lg [&_svg]:shrink-0 [&_svg]:text-muted-foreground',
149
+ )}
150
+ >
151
+ {item.icon}
152
+ <span className="grid min-w-0 flex-1">
153
+ <span className="truncate">{item.label}</span>
154
+ {item.description && (
155
+ <span className="truncate text-body-12 text-muted-foreground">
156
+ {item.description}
157
+ </span>
158
+ )}
159
+ </span>
160
+ {item.shortcut && <Kbd>{item.shortcut}</Kbd>}
161
+ <ArrowRightIcon className="opacity-0 group-data-highlighted/item:opacity-100" />
162
+ </Autocomplete.Item>
163
+ )}
164
+ </Autocomplete.Collection>
165
+ </Autocomplete.Group>
166
+ )}
167
+ </Autocomplete.List>
168
+ </Autocomplete.Root>
169
+ <div className="text-body-12 text-muted-foreground flex items-center gap-4 border-t px-4 py-2.5 [&_svg]:size-icon-xs">
170
+ <span className="flex items-center gap-1.5">
171
+ <Kbd>
172
+ <ArrowUpIcon />
173
+ </Kbd>
174
+ <Kbd>
175
+ <ArrowDownIcon />
176
+ </Kbd>
177
+ para navegar
178
+ </span>
179
+ <span className="flex items-center gap-1.5">
180
+ <Kbd>
181
+ <CornerDownLeftIcon />
182
+ </Kbd>
183
+ para abrir
184
+ </span>
185
+ </div>
186
+ </DialogContent>
187
+ </Dialog>
188
+ );
189
+ }
190
+
191
+ export { CommandMenu };