xertica-ui 1.0.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.
Files changed (141) hide show
  1. package/App.tsx +182 -0
  2. package/README.md +330 -0
  3. package/assets/xertica-logo.svg +38 -0
  4. package/assets/xertica-x-logo.svg +21 -0
  5. package/bin/cli.ts +193 -0
  6. package/components/AssistenteXertica.tsx +2003 -0
  7. package/components/AudioPlayer.tsx +203 -0
  8. package/components/CodeBlock.tsx +242 -0
  9. package/components/DocumentEditor.tsx +504 -0
  10. package/components/ForgotPasswordPage.tsx +170 -0
  11. package/components/FormattedDocument.tsx +87 -0
  12. package/components/HomeContent.tsx +123 -0
  13. package/components/HomePage.tsx +70 -0
  14. package/components/LanguageSelector.tsx +54 -0
  15. package/components/LoginPage.tsx +199 -0
  16. package/components/MarkdownMessage.tsx +62 -0
  17. package/components/ModernChatInput.tsx +502 -0
  18. package/components/PodcastPlayer.tsx +409 -0
  19. package/components/ResetPasswordPage.tsx +234 -0
  20. package/components/Sidebar.tsx +489 -0
  21. package/components/TemplateContent.tsx +629 -0
  22. package/components/TemplatePage.tsx +70 -0
  23. package/components/ThemeToggle.tsx +65 -0
  24. package/components/VerifyEmailPage.tsx +187 -0
  25. package/components/XerticaLogo.tsx +69 -0
  26. package/components/XerticaOrbe.tsx +1339 -0
  27. package/components/XerticaXLogo.tsx +53 -0
  28. package/components/examples/DrawingMapExample.tsx +530 -0
  29. package/components/examples/FilterableMapExample.tsx +380 -0
  30. package/components/examples/LocationPickerExample.tsx +330 -0
  31. package/components/examples/MapExamples.tsx +280 -0
  32. package/components/examples/MapShowcase.tsx +446 -0
  33. package/components/examples/RouteMapExamples.tsx +329 -0
  34. package/components/examples/SimpleFilterableMap.tsx +192 -0
  35. package/components/examples/index.ts +52 -0
  36. package/components/figma/ImageWithFallback.tsx +27 -0
  37. package/components/index.ts +44 -0
  38. package/components/media/AudioPlayer.tsx +278 -0
  39. package/components/media/FloatingMediaWrapper.tsx +166 -0
  40. package/components/media/VideoPlayer.tsx +285 -0
  41. package/components/ui/accordion.tsx +66 -0
  42. package/components/ui/alert-dialog.tsx +159 -0
  43. package/components/ui/alert.tsx +91 -0
  44. package/components/ui/aspect-ratio.tsx +11 -0
  45. package/components/ui/avatar.tsx +65 -0
  46. package/components/ui/badge.tsx +55 -0
  47. package/components/ui/breadcrumb.tsx +109 -0
  48. package/components/ui/button.tsx +78 -0
  49. package/components/ui/calendar.tsx +235 -0
  50. package/components/ui/card.tsx +92 -0
  51. package/components/ui/carousel.tsx +241 -0
  52. package/components/ui/chart.tsx +353 -0
  53. package/components/ui/checkbox.tsx +32 -0
  54. package/components/ui/collapsible.tsx +33 -0
  55. package/components/ui/command.tsx +177 -0
  56. package/components/ui/context-menu.tsx +252 -0
  57. package/components/ui/dialog.tsx +138 -0
  58. package/components/ui/drawer.tsx +134 -0
  59. package/components/ui/dropdown-menu.tsx +257 -0
  60. package/components/ui/empty.tsx +90 -0
  61. package/components/ui/file-upload.tsx +152 -0
  62. package/components/ui/form.tsx +195 -0
  63. package/components/ui/google-maps-loader.tsx +379 -0
  64. package/components/ui/hover-card.tsx +44 -0
  65. package/components/ui/index.ts +242 -0
  66. package/components/ui/input-otp.tsx +77 -0
  67. package/components/ui/input.tsx +38 -0
  68. package/components/ui/label.tsx +24 -0
  69. package/components/ui/map-config.ts +12 -0
  70. package/components/ui/map-layers.tsx +129 -0
  71. package/components/ui/map.exports.ts +31 -0
  72. package/components/ui/map.tsx +412 -0
  73. package/components/ui/menubar.tsx +276 -0
  74. package/components/ui/navigation-menu.tsx +162 -0
  75. package/components/ui/notification-badge.tsx +61 -0
  76. package/components/ui/page-header.tsx +229 -0
  77. package/components/ui/pagination.tsx +127 -0
  78. package/components/ui/popover.tsx +48 -0
  79. package/components/ui/progress.tsx +31 -0
  80. package/components/ui/radio-group.tsx +56 -0
  81. package/components/ui/rating.tsx +102 -0
  82. package/components/ui/resizable.tsx +405 -0
  83. package/components/ui/route-map.tsx +246 -0
  84. package/components/ui/scroll-area.tsx +58 -0
  85. package/components/ui/search.tsx +70 -0
  86. package/components/ui/select.tsx +176 -0
  87. package/components/ui/separator.tsx +28 -0
  88. package/components/ui/sheet.tsx +138 -0
  89. package/components/ui/sidebar.tsx +726 -0
  90. package/components/ui/simple-map.tsx +92 -0
  91. package/components/ui/skeleton.tsx +13 -0
  92. package/components/ui/slider.tsx +58 -0
  93. package/components/ui/sonner.tsx +77 -0
  94. package/components/ui/stats-card.tsx +84 -0
  95. package/components/ui/stepper.tsx +126 -0
  96. package/components/ui/switch.tsx +34 -0
  97. package/components/ui/table.tsx +116 -0
  98. package/components/ui/tabs.tsx +66 -0
  99. package/components/ui/textarea.tsx +26 -0
  100. package/components/ui/timeline.tsx +140 -0
  101. package/components/ui/toggle-group.tsx +71 -0
  102. package/components/ui/toggle.tsx +46 -0
  103. package/components/ui/tooltip.tsx +61 -0
  104. package/components/ui/tree-view.tsx +123 -0
  105. package/components/ui/use-mobile.ts +24 -0
  106. package/components/ui/utils.ts +6 -0
  107. package/components/ui/xertica-assistant.tsx +1420 -0
  108. package/contexts/ApiKeyContext.tsx +123 -0
  109. package/contexts/AssistenteContext.tsx +118 -0
  110. package/contexts/BrandColorsContext.tsx +551 -0
  111. package/contexts/LanguageContext.tsx +36 -0
  112. package/contexts/ThemeContext.tsx +85 -0
  113. package/dist/cli.js +20922 -0
  114. package/eslint.config.js +41 -0
  115. package/guidelines/Guidelines.md +61 -0
  116. package/hooks/useTheme.ts +4 -0
  117. package/imports/Podcast.tsx +389 -0
  118. package/imports/XerticaAi.tsx +46 -0
  119. package/imports/XerticaX.tsx +20 -0
  120. package/imports/svg-aueiaqngck.ts +11 -0
  121. package/imports/svg-v9krss1ozd.ts +16 -0
  122. package/imports/svg-vhrdofe3qe.ts +5 -0
  123. package/index.css +4448 -0
  124. package/index.html +14 -0
  125. package/main.tsx +10 -0
  126. package/package.json +119 -0
  127. package/postcss.config.js +6 -0
  128. package/routes.tsx +33 -0
  129. package/styles/globals.css +15 -0
  130. package/styles/xertica/app-overrides/chat.css +61 -0
  131. package/styles/xertica/app-overrides/scrollbar.css +33 -0
  132. package/styles/xertica/base.css +70 -0
  133. package/styles/xertica/integrations/google-maps.css +76 -0
  134. package/styles/xertica/integrations/sonner.css +73 -0
  135. package/styles/xertica/theme-map.css +88 -0
  136. package/styles/xertica/tokens.css +190 -0
  137. package/tsconfig.json +31 -0
  138. package/tsconfig.node.json +10 -0
  139. package/utils/gemini.ts +140 -0
  140. package/vite-env.d.ts +12 -0
  141. package/vite.config.ts +36 -0
@@ -0,0 +1,257 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
5
+ import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";
6
+
7
+ import { cn } from "./utils";
8
+
9
+ function DropdownMenu({
10
+ ...props
11
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
12
+ return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
13
+ }
14
+
15
+ function DropdownMenuPortal({
16
+ ...props
17
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
18
+ return (
19
+ <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
20
+ );
21
+ }
22
+
23
+ function DropdownMenuTrigger({
24
+ ...props
25
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
26
+ return (
27
+ <DropdownMenuPrimitive.Trigger
28
+ data-slot="dropdown-menu-trigger"
29
+ {...props}
30
+ />
31
+ );
32
+ }
33
+
34
+ function DropdownMenuContent({
35
+ className,
36
+ sideOffset = 4,
37
+ ...props
38
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
39
+ return (
40
+ <DropdownMenuPrimitive.Portal>
41
+ <DropdownMenuPrimitive.Content
42
+ data-slot="dropdown-menu-content"
43
+ sideOffset={sideOffset}
44
+ className={cn(
45
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
46
+ className,
47
+ )}
48
+ {...props}
49
+ />
50
+ </DropdownMenuPrimitive.Portal>
51
+ );
52
+ }
53
+
54
+ function DropdownMenuGroup({
55
+ ...props
56
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
57
+ return (
58
+ <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
59
+ );
60
+ }
61
+
62
+ function DropdownMenuItem({
63
+ className,
64
+ inset,
65
+ variant = "default",
66
+ ...props
67
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
68
+ inset?: boolean;
69
+ variant?: "default" | "destructive";
70
+ }) {
71
+ return (
72
+ <DropdownMenuPrimitive.Item
73
+ data-slot="dropdown-menu-item"
74
+ data-inset={inset}
75
+ data-variant={variant}
76
+ className={cn(
77
+ "focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
78
+ className,
79
+ )}
80
+ {...props}
81
+ />
82
+ );
83
+ }
84
+
85
+ function DropdownMenuCheckboxItem({
86
+ className,
87
+ children,
88
+ checked,
89
+ ...props
90
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
91
+ return (
92
+ <DropdownMenuPrimitive.CheckboxItem
93
+ data-slot="dropdown-menu-checkbox-item"
94
+ className={cn(
95
+ "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
96
+ className,
97
+ )}
98
+ checked={checked}
99
+ {...props}
100
+ >
101
+ <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
102
+ <DropdownMenuPrimitive.ItemIndicator>
103
+ <CheckIcon className="size-4" />
104
+ </DropdownMenuPrimitive.ItemIndicator>
105
+ </span>
106
+ {children}
107
+ </DropdownMenuPrimitive.CheckboxItem>
108
+ );
109
+ }
110
+
111
+ function DropdownMenuRadioGroup({
112
+ ...props
113
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
114
+ return (
115
+ <DropdownMenuPrimitive.RadioGroup
116
+ data-slot="dropdown-menu-radio-group"
117
+ {...props}
118
+ />
119
+ );
120
+ }
121
+
122
+ function DropdownMenuRadioItem({
123
+ className,
124
+ children,
125
+ ...props
126
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
127
+ return (
128
+ <DropdownMenuPrimitive.RadioItem
129
+ data-slot="dropdown-menu-radio-item"
130
+ className={cn(
131
+ "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
132
+ className,
133
+ )}
134
+ {...props}
135
+ >
136
+ <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
137
+ <DropdownMenuPrimitive.ItemIndicator>
138
+ <CircleIcon className="size-2 fill-current" />
139
+ </DropdownMenuPrimitive.ItemIndicator>
140
+ </span>
141
+ {children}
142
+ </DropdownMenuPrimitive.RadioItem>
143
+ );
144
+ }
145
+
146
+ function DropdownMenuLabel({
147
+ className,
148
+ inset,
149
+ ...props
150
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
151
+ inset?: boolean;
152
+ }) {
153
+ return (
154
+ <DropdownMenuPrimitive.Label
155
+ data-slot="dropdown-menu-label"
156
+ data-inset={inset}
157
+ className={cn(
158
+ "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
159
+ className,
160
+ )}
161
+ {...props}
162
+ />
163
+ );
164
+ }
165
+
166
+ function DropdownMenuSeparator({
167
+ className,
168
+ ...props
169
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
170
+ return (
171
+ <DropdownMenuPrimitive.Separator
172
+ data-slot="dropdown-menu-separator"
173
+ className={cn("bg-border -mx-1 my-1 h-px", className)}
174
+ {...props}
175
+ />
176
+ );
177
+ }
178
+
179
+ function DropdownMenuShortcut({
180
+ className,
181
+ ...props
182
+ }: React.ComponentProps<"span">) {
183
+ return (
184
+ <span
185
+ data-slot="dropdown-menu-shortcut"
186
+ className={cn(
187
+ "text-muted-foreground ml-auto text-xs tracking-widest",
188
+ className,
189
+ )}
190
+ {...props}
191
+ />
192
+ );
193
+ }
194
+
195
+ function DropdownMenuSub({
196
+ ...props
197
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
198
+ return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
199
+ }
200
+
201
+ function DropdownMenuSubTrigger({
202
+ className,
203
+ inset,
204
+ children,
205
+ ...props
206
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
207
+ inset?: boolean;
208
+ }) {
209
+ return (
210
+ <DropdownMenuPrimitive.SubTrigger
211
+ data-slot="dropdown-menu-sub-trigger"
212
+ data-inset={inset}
213
+ className={cn(
214
+ "focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
215
+ className,
216
+ )}
217
+ {...props}
218
+ >
219
+ {children}
220
+ <ChevronRightIcon className="ml-auto size-4" />
221
+ </DropdownMenuPrimitive.SubTrigger>
222
+ );
223
+ }
224
+
225
+ function DropdownMenuSubContent({
226
+ className,
227
+ ...props
228
+ }: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
229
+ return (
230
+ <DropdownMenuPrimitive.SubContent
231
+ data-slot="dropdown-menu-sub-content"
232
+ className={cn(
233
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
234
+ className,
235
+ )}
236
+ {...props}
237
+ />
238
+ );
239
+ }
240
+
241
+ export {
242
+ DropdownMenu,
243
+ DropdownMenuPortal,
244
+ DropdownMenuTrigger,
245
+ DropdownMenuContent,
246
+ DropdownMenuGroup,
247
+ DropdownMenuLabel,
248
+ DropdownMenuItem,
249
+ DropdownMenuCheckboxItem,
250
+ DropdownMenuRadioGroup,
251
+ DropdownMenuRadioItem,
252
+ DropdownMenuSeparator,
253
+ DropdownMenuShortcut,
254
+ DropdownMenuSub,
255
+ DropdownMenuSubTrigger,
256
+ DropdownMenuSubContent,
257
+ };
@@ -0,0 +1,90 @@
1
+ import * as React from "react";
2
+ import { cn } from "./utils";
3
+
4
+ const Empty = React.forwardRef<
5
+ HTMLDivElement,
6
+ React.HTMLAttributes<HTMLDivElement>
7
+ >(({ className, ...props }, ref) => (
8
+ <div
9
+ ref={ref}
10
+ className={cn(
11
+ "flex min-h-[400px] flex-col items-center justify-center rounded-[var(--radius-card)] border border-dashed border-border p-8 text-center animate-in fade-in-50",
12
+ className
13
+ )}
14
+ {...props}
15
+ />
16
+ ));
17
+ Empty.displayName = "Empty";
18
+
19
+ const EmptyIcon = React.forwardRef<
20
+ HTMLDivElement,
21
+ React.HTMLAttributes<HTMLDivElement>
22
+ >(({ className, ...props }, ref) => (
23
+ <div
24
+ ref={ref}
25
+ className={cn(
26
+ "mx-auto flex h-20 w-20 items-center justify-center rounded-full bg-muted",
27
+ className
28
+ )}
29
+ {...props}
30
+ />
31
+ ));
32
+ EmptyIcon.displayName = "EmptyIcon";
33
+
34
+ const EmptyImage = React.forwardRef<
35
+ HTMLImageElement,
36
+ React.ImgHTMLAttributes<HTMLImageElement>
37
+ >(({ className, alt, ...props }, ref) => (
38
+ <img
39
+ ref={ref}
40
+ alt={alt}
41
+ className={cn("mx-auto mb-4 h-48 w-48 object-contain opacity-50", className)}
42
+ {...props}
43
+ />
44
+ ));
45
+ EmptyImage.displayName = "EmptyImage";
46
+
47
+ const EmptyTitle = React.forwardRef<
48
+ HTMLHeadingElement,
49
+ React.HTMLAttributes<HTMLHeadingElement>
50
+ >(({ className, ...props }, ref) => (
51
+ <h3
52
+ ref={ref}
53
+ className={cn("mt-4 font-semibold text-foreground", className)}
54
+ {...props}
55
+ />
56
+ ));
57
+ EmptyTitle.displayName = "EmptyTitle";
58
+
59
+ const EmptyDescription = React.forwardRef<
60
+ HTMLParagraphElement,
61
+ React.HTMLAttributes<HTMLParagraphElement>
62
+ >(({ className, ...props }, ref) => (
63
+ <p
64
+ ref={ref}
65
+ className={cn("mt-2 text-sm text-muted-foreground max-w-sm mx-auto", className)}
66
+ {...props}
67
+ />
68
+ ));
69
+ EmptyDescription.displayName = "EmptyDescription";
70
+
71
+ const EmptyAction = React.forwardRef<
72
+ HTMLDivElement,
73
+ React.HTMLAttributes<HTMLDivElement>
74
+ >(({ className, ...props }, ref) => (
75
+ <div
76
+ ref={ref}
77
+ className={cn("mt-6 flex flex-col gap-2 sm:flex-row sm:gap-4", className)}
78
+ {...props}
79
+ />
80
+ ));
81
+ EmptyAction.displayName = "EmptyAction";
82
+
83
+ export {
84
+ Empty,
85
+ EmptyIcon,
86
+ EmptyImage,
87
+ EmptyTitle,
88
+ EmptyDescription,
89
+ EmptyAction,
90
+ };
@@ -0,0 +1,152 @@
1
+ import * as React from "react";
2
+ import { Upload, X, FileIcon } from "lucide-react";
3
+ import { cn } from "./utils";
4
+ import { Button } from "./button";
5
+
6
+ interface FileUploadProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
7
+ onFilesChange?: (files: File[]) => void;
8
+ maxFiles?: number;
9
+ maxSize?: number; // in bytes
10
+ showPreview?: boolean;
11
+ }
12
+
13
+ const FileUpload = React.forwardRef<HTMLDivElement, FileUploadProps>(
14
+ ({
15
+ className,
16
+ onFilesChange,
17
+ maxFiles = 1,
18
+ maxSize = 5 * 1024 * 1024, // 5MB default
19
+ showPreview = true,
20
+ accept,
21
+ disabled,
22
+ ...props
23
+ }, ref) => {
24
+ const [files, setFiles] = React.useState<File[]>([]);
25
+ const [dragActive, setDragActive] = React.useState(false);
26
+ const inputRef = React.useRef<HTMLInputElement>(null);
27
+
28
+ const handleFiles = (newFiles: FileList | null) => {
29
+ if (!newFiles) return;
30
+
31
+ const filesArray = Array.from(newFiles);
32
+ const validFiles = filesArray.filter(file => file.size <= maxSize);
33
+
34
+ const updatedFiles = maxFiles === 1
35
+ ? validFiles.slice(0, 1)
36
+ : [...files, ...validFiles].slice(0, maxFiles);
37
+
38
+ setFiles(updatedFiles);
39
+ onFilesChange?.(updatedFiles);
40
+ };
41
+
42
+ const handleDrag = (e: React.DragEvent) => {
43
+ e.preventDefault();
44
+ e.stopPropagation();
45
+
46
+ if (e.type === "dragenter" || e.type === "dragover") {
47
+ setDragActive(true);
48
+ } else if (e.type === "dragleave") {
49
+ setDragActive(false);
50
+ }
51
+ };
52
+
53
+ const handleDrop = (e: React.DragEvent) => {
54
+ e.preventDefault();
55
+ e.stopPropagation();
56
+ setDragActive(false);
57
+
58
+ if (disabled) return;
59
+ handleFiles(e.dataTransfer.files);
60
+ };
61
+
62
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
63
+ e.preventDefault();
64
+ if (disabled) return;
65
+ handleFiles(e.target.files);
66
+ };
67
+
68
+ const removeFile = (index: number) => {
69
+ const updatedFiles = files.filter((_, i) => i !== index);
70
+ setFiles(updatedFiles);
71
+ onFilesChange?.(updatedFiles);
72
+ };
73
+
74
+ const openFileDialog = () => {
75
+ if (!disabled) {
76
+ inputRef.current?.click();
77
+ }
78
+ };
79
+
80
+ return (
81
+ <div ref={ref} className={cn("w-full", className)}>
82
+ <div
83
+ onDragEnter={handleDrag}
84
+ onDragLeave={handleDrag}
85
+ onDragOver={handleDrag}
86
+ onDrop={handleDrop}
87
+ onClick={openFileDialog}
88
+ className={cn(
89
+ "relative flex cursor-pointer flex-col items-center justify-center rounded-[var(--radius)] border-2 border-dashed border-border bg-background p-8 transition-colors hover:bg-muted/50",
90
+ dragActive && "border-primary bg-primary/5",
91
+ disabled && "cursor-not-allowed opacity-50"
92
+ )}
93
+ >
94
+ <Upload className="mb-4 h-10 w-10 text-muted-foreground" />
95
+ <p className="mb-2 text-foreground">
96
+ <span className="text-primary">Clique para fazer upload</span> ou arraste arquivos
97
+ </p>
98
+ <p className="text-muted-foreground">
99
+ {maxFiles > 1 ? `Até ${maxFiles} arquivos` : "1 arquivo"} • Máx {(maxSize / 1024 / 1024).toFixed(0)}MB
100
+ </p>
101
+ <input
102
+ {...props}
103
+ ref={inputRef}
104
+ type="file"
105
+ className="hidden"
106
+ onChange={handleChange}
107
+ multiple={maxFiles > 1}
108
+ accept={accept}
109
+ disabled={disabled}
110
+ />
111
+ </div>
112
+
113
+ {showPreview && files.length > 0 && (
114
+ <div className="mt-4 space-y-2">
115
+ {files.map((file, index) => (
116
+ <div
117
+ key={index}
118
+ className="flex items-center justify-between rounded-[var(--radius)] border border-border bg-card p-3"
119
+ >
120
+ <div className="flex items-center gap-3">
121
+ <FileIcon className="h-5 w-5 text-muted-foreground" />
122
+ <div>
123
+ <p className="text-foreground">{file.name}</p>
124
+ <p className="text-muted-foreground">
125
+ {(file.size / 1024).toFixed(2)} KB
126
+ </p>
127
+ </div>
128
+ </div>
129
+ <Button
130
+ type="button"
131
+ variant="ghost"
132
+ size="sm"
133
+ onClick={(e) => {
134
+ e.stopPropagation();
135
+ removeFile(index);
136
+ }}
137
+ disabled={disabled}
138
+ >
139
+ <X className="h-4 w-4" />
140
+ </Button>
141
+ </div>
142
+ ))}
143
+ </div>
144
+ )}
145
+ </div>
146
+ );
147
+ }
148
+ );
149
+ FileUpload.displayName = "FileUpload";
150
+
151
+ export { FileUpload };
152
+ export type { FileUploadProps };
@@ -0,0 +1,195 @@
1
+ import * as React from "react";
2
+ import * as LabelPrimitive from "@radix-ui/react-label";
3
+ import { Slot } from "@radix-ui/react-slot";
4
+ import {
5
+ Controller,
6
+ FormProvider,
7
+ useFormContext,
8
+ useFormState,
9
+ type ControllerProps,
10
+ type FieldPath,
11
+ type FieldValues,
12
+ } from "react-hook-form";
13
+
14
+ import { cn } from "./utils";
15
+ import { Label } from "./label";
16
+
17
+ const Form = FormProvider;
18
+
19
+ type FormFieldContextValue<
20
+ TFieldValues extends FieldValues = FieldValues,
21
+ TName extends
22
+ FieldPath<TFieldValues> = FieldPath<TFieldValues>,
23
+ > = {
24
+ name: TName;
25
+ };
26
+
27
+ const FormFieldContext =
28
+ React.createContext<FormFieldContextValue>(
29
+ {} as FormFieldContextValue,
30
+ );
31
+
32
+ const FormField = <
33
+ TFieldValues extends FieldValues = FieldValues,
34
+ TName extends
35
+ FieldPath<TFieldValues> = FieldPath<TFieldValues>,
36
+ >({
37
+ ...props
38
+ }: ControllerProps<TFieldValues, TName>) => {
39
+ return (
40
+ <FormFieldContext.Provider value={{ name: props.name }}>
41
+ <Controller {...props} />
42
+ </FormFieldContext.Provider>
43
+ );
44
+ };
45
+
46
+ const useFormField = () => {
47
+ const fieldContext = React.useContext(FormFieldContext);
48
+ const itemContext = React.useContext(FormItemContext);
49
+ const { getFieldState } = useFormContext();
50
+ const formState = useFormState({ name: fieldContext.name });
51
+ const fieldState = getFieldState(
52
+ fieldContext.name,
53
+ formState,
54
+ );
55
+
56
+ if (!fieldContext) {
57
+ throw new Error(
58
+ "useFormField should be used within <FormField>",
59
+ );
60
+ }
61
+
62
+ const { id } = itemContext;
63
+
64
+ return {
65
+ id,
66
+ name: fieldContext.name,
67
+ formItemId: `${id}-form-item`,
68
+ formDescriptionId: `${id}-form-item-description`,
69
+ formMessageId: `${id}-form-item-message`,
70
+ ...fieldState,
71
+ };
72
+ };
73
+
74
+ type FormItemContextValue = {
75
+ id: string;
76
+ };
77
+
78
+ const FormItemContext =
79
+ React.createContext<FormItemContextValue>(
80
+ {} as FormItemContextValue,
81
+ );
82
+
83
+ function FormItem({
84
+ className,
85
+ ...props
86
+ }: React.ComponentProps<"div">) {
87
+ const id = React.useId();
88
+
89
+ return (
90
+ <FormItemContext.Provider value={{ id }}>
91
+ <div
92
+ data-slot="form-item"
93
+ className={cn("grid gap-2", className)}
94
+ {...props}
95
+ />
96
+ </FormItemContext.Provider>
97
+ );
98
+ }
99
+
100
+ function FormLabel({
101
+ className,
102
+ ...props
103
+ }: React.ComponentProps<typeof LabelPrimitive.Root>) {
104
+ const { error, formItemId } = useFormField();
105
+
106
+ return (
107
+ <Label
108
+ data-slot="form-label"
109
+ data-error={!!error}
110
+ className={cn(
111
+ "data-[error=true]:text-destructive",
112
+ className,
113
+ )}
114
+ htmlFor={formItemId}
115
+ {...props}
116
+ />
117
+ );
118
+ }
119
+
120
+ function FormControl({
121
+ ...props
122
+ }: React.ComponentProps<typeof Slot>) {
123
+ const {
124
+ error,
125
+ formItemId,
126
+ formDescriptionId,
127
+ formMessageId,
128
+ } = useFormField();
129
+
130
+ return (
131
+ <Slot
132
+ data-slot="form-control"
133
+ id={formItemId}
134
+ aria-describedby={
135
+ !error
136
+ ? `${formDescriptionId}`
137
+ : `${formDescriptionId} ${formMessageId}`
138
+ }
139
+ aria-invalid={!!error}
140
+ {...props}
141
+ />
142
+ );
143
+ }
144
+
145
+ function FormDescription({
146
+ className,
147
+ ...props
148
+ }: React.ComponentProps<"p">) {
149
+ const { formDescriptionId } = useFormField();
150
+
151
+ return (
152
+ <p
153
+ data-slot="form-description"
154
+ id={formDescriptionId}
155
+ className={cn("text-muted-foreground text-sm", className)}
156
+ {...props}
157
+ />
158
+ );
159
+ }
160
+
161
+ function FormMessage({
162
+ className,
163
+ ...props
164
+ }: React.ComponentProps<"p">) {
165
+ const { error, formMessageId } = useFormField();
166
+ const body = error
167
+ ? String(error?.message ?? "")
168
+ : props.children;
169
+
170
+ if (!body) {
171
+ return null;
172
+ }
173
+
174
+ return (
175
+ <p
176
+ data-slot="form-message"
177
+ id={formMessageId}
178
+ className={cn("text-destructive text-sm", className)}
179
+ {...props}
180
+ >
181
+ {body}
182
+ </p>
183
+ );
184
+ }
185
+
186
+ export {
187
+ useFormField,
188
+ Form,
189
+ FormItem,
190
+ FormLabel,
191
+ FormControl,
192
+ FormDescription,
193
+ FormMessage,
194
+ FormField,
195
+ };