@behavioral-agentic-design-system/core 0.8.4 → 0.9.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/package.json +17 -1
- package/scripts/build-fonts.cjs +26 -3
- package/scripts/build-tokens.cjs +68 -6
- package/src/api/brand-fonts.ts +20 -10
- package/src/api/layers/file.ts +39 -4
- package/src/app/preview/components/page.tsx +718 -1
- package/src/app/shell.tsx +61 -15
- package/src/components/brand-mark.tsx +1 -1
- package/src/components/docs-tab.tsx +497 -0
- package/src/components/home-tab.tsx +341 -2043
- package/src/components/layers-tab.tsx +3 -91
- package/src/components/markdown-preview.tsx +226 -0
- package/src/components/motion/chart-reveal.tsx +164 -0
- package/src/components/motion/reveal.tsx +156 -0
- package/src/components/ui/accordion.tsx +117 -0
- package/src/components/ui/alert-dialog.tsx +162 -0
- package/src/components/ui/carousel.tsx +357 -0
- package/src/components/ui/context-menu.tsx +258 -0
- package/src/components/ui/file-upload.tsx +278 -0
- package/src/components/ui/index.ts +10 -0
- package/src/components/ui/navigation-menu.tsx +154 -0
- package/src/components/ui/number-input.tsx +229 -0
- package/src/components/ui/pagination.tsx +143 -0
- package/src/components/ui/pin-input.tsx +257 -0
- package/src/components/ui/sheet.tsx +10 -4
- package/src/components/ui/spinner.tsx +70 -0
- package/src/components/ui/stepper.tsx +272 -0
- package/src/data/docs-index.ts +163 -0
- package/src/hooks/use-reduced-motion.ts +13 -0
- package/src/styles.css +56 -6
- package/src/tokens.json +5 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
|
5
|
+
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../lib/utils"
|
|
8
|
+
import { usePortalThemeClass } from "../../hooks/use-portal-theme-class"
|
|
9
|
+
|
|
10
|
+
function ContextMenu({
|
|
11
|
+
...props
|
|
12
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Root>) {
|
|
13
|
+
return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function ContextMenuTrigger({
|
|
17
|
+
...props
|
|
18
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Trigger>) {
|
|
19
|
+
return (
|
|
20
|
+
<ContextMenuPrimitive.Trigger
|
|
21
|
+
data-slot="context-menu-trigger"
|
|
22
|
+
{...props}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function ContextMenuGroup({
|
|
28
|
+
...props
|
|
29
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Group>) {
|
|
30
|
+
return (
|
|
31
|
+
<ContextMenuPrimitive.Group data-slot="context-menu-group" {...props} />
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ContextMenuPortal({
|
|
36
|
+
...props
|
|
37
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Portal>) {
|
|
38
|
+
return (
|
|
39
|
+
<ContextMenuPrimitive.Portal data-slot="context-menu-portal" {...props} />
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ContextMenuSub({
|
|
44
|
+
...props
|
|
45
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Sub>) {
|
|
46
|
+
return <ContextMenuPrimitive.Sub data-slot="context-menu-sub" {...props} />
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function ContextMenuRadioGroup({
|
|
50
|
+
...props
|
|
51
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioGroup>) {
|
|
52
|
+
return (
|
|
53
|
+
<ContextMenuPrimitive.RadioGroup
|
|
54
|
+
data-slot="context-menu-radio-group"
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function ContextMenuSubTrigger({
|
|
61
|
+
className,
|
|
62
|
+
inset,
|
|
63
|
+
children,
|
|
64
|
+
...props
|
|
65
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.SubTrigger> & {
|
|
66
|
+
inset?: boolean
|
|
67
|
+
}) {
|
|
68
|
+
return (
|
|
69
|
+
<ContextMenuPrimitive.SubTrigger
|
|
70
|
+
data-slot="context-menu-sub-trigger"
|
|
71
|
+
data-inset={inset}
|
|
72
|
+
className={cn(
|
|
73
|
+
"flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
|
74
|
+
className
|
|
75
|
+
)}
|
|
76
|
+
{...props}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
<ChevronRightIcon className="ml-auto size-4" />
|
|
80
|
+
</ContextMenuPrimitive.SubTrigger>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function ContextMenuSubContent({
|
|
85
|
+
className,
|
|
86
|
+
...props
|
|
87
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
|
|
88
|
+
return (
|
|
89
|
+
<ContextMenuPrimitive.SubContent
|
|
90
|
+
data-slot="context-menu-sub-content"
|
|
91
|
+
className={cn(
|
|
92
|
+
"z-50 min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
93
|
+
className
|
|
94
|
+
)}
|
|
95
|
+
{...props}
|
|
96
|
+
/>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function ContextMenuContent({
|
|
101
|
+
className,
|
|
102
|
+
...props
|
|
103
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Content>) {
|
|
104
|
+
const portalThemeClass = usePortalThemeClass()
|
|
105
|
+
return (
|
|
106
|
+
<ContextMenuPrimitive.Portal>
|
|
107
|
+
<ContextMenuPrimitive.Content
|
|
108
|
+
data-slot="context-menu-content"
|
|
109
|
+
className={cn(
|
|
110
|
+
"z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
111
|
+
portalThemeClass,
|
|
112
|
+
className
|
|
113
|
+
)}
|
|
114
|
+
{...props}
|
|
115
|
+
/>
|
|
116
|
+
</ContextMenuPrimitive.Portal>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function ContextMenuItem({
|
|
121
|
+
className,
|
|
122
|
+
inset,
|
|
123
|
+
variant = "default",
|
|
124
|
+
...props
|
|
125
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
|
|
126
|
+
inset?: boolean
|
|
127
|
+
variant?: "default" | "destructive"
|
|
128
|
+
}) {
|
|
129
|
+
return (
|
|
130
|
+
<ContextMenuPrimitive.Item
|
|
131
|
+
data-slot="context-menu-item"
|
|
132
|
+
data-inset={inset}
|
|
133
|
+
data-variant={variant}
|
|
134
|
+
className={cn(
|
|
135
|
+
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",
|
|
136
|
+
className
|
|
137
|
+
)}
|
|
138
|
+
{...props}
|
|
139
|
+
/>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function ContextMenuCheckboxItem({
|
|
144
|
+
className,
|
|
145
|
+
children,
|
|
146
|
+
checked,
|
|
147
|
+
...props
|
|
148
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.CheckboxItem>) {
|
|
149
|
+
return (
|
|
150
|
+
<ContextMenuPrimitive.CheckboxItem
|
|
151
|
+
data-slot="context-menu-checkbox-item"
|
|
152
|
+
className={cn(
|
|
153
|
+
"relative flex cursor-default select-none items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
154
|
+
className
|
|
155
|
+
)}
|
|
156
|
+
checked={checked}
|
|
157
|
+
{...props}
|
|
158
|
+
>
|
|
159
|
+
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
160
|
+
<ContextMenuPrimitive.ItemIndicator>
|
|
161
|
+
<CheckIcon className="size-4" />
|
|
162
|
+
</ContextMenuPrimitive.ItemIndicator>
|
|
163
|
+
</span>
|
|
164
|
+
{children}
|
|
165
|
+
</ContextMenuPrimitive.CheckboxItem>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function ContextMenuRadioItem({
|
|
170
|
+
className,
|
|
171
|
+
children,
|
|
172
|
+
...props
|
|
173
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioItem>) {
|
|
174
|
+
return (
|
|
175
|
+
<ContextMenuPrimitive.RadioItem
|
|
176
|
+
data-slot="context-menu-radio-item"
|
|
177
|
+
className={cn(
|
|
178
|
+
"relative flex cursor-default select-none items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
179
|
+
className
|
|
180
|
+
)}
|
|
181
|
+
{...props}
|
|
182
|
+
>
|
|
183
|
+
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
184
|
+
<ContextMenuPrimitive.ItemIndicator>
|
|
185
|
+
<CircleIcon className="size-2 fill-current" />
|
|
186
|
+
</ContextMenuPrimitive.ItemIndicator>
|
|
187
|
+
</span>
|
|
188
|
+
{children}
|
|
189
|
+
</ContextMenuPrimitive.RadioItem>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function ContextMenuLabel({
|
|
194
|
+
className,
|
|
195
|
+
inset,
|
|
196
|
+
...props
|
|
197
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Label> & {
|
|
198
|
+
inset?: boolean
|
|
199
|
+
}) {
|
|
200
|
+
return (
|
|
201
|
+
<ContextMenuPrimitive.Label
|
|
202
|
+
data-slot="context-menu-label"
|
|
203
|
+
data-inset={inset}
|
|
204
|
+
className={cn(
|
|
205
|
+
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
|
206
|
+
className
|
|
207
|
+
)}
|
|
208
|
+
{...props}
|
|
209
|
+
/>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function ContextMenuSeparator({
|
|
214
|
+
className,
|
|
215
|
+
...props
|
|
216
|
+
}: React.ComponentProps<typeof ContextMenuPrimitive.Separator>) {
|
|
217
|
+
return (
|
|
218
|
+
<ContextMenuPrimitive.Separator
|
|
219
|
+
data-slot="context-menu-separator"
|
|
220
|
+
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
|
221
|
+
{...props}
|
|
222
|
+
/>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function ContextMenuShortcut({
|
|
227
|
+
className,
|
|
228
|
+
...props
|
|
229
|
+
}: React.ComponentProps<"span">) {
|
|
230
|
+
return (
|
|
231
|
+
<span
|
|
232
|
+
data-slot="context-menu-shortcut"
|
|
233
|
+
className={cn(
|
|
234
|
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
|
235
|
+
className
|
|
236
|
+
)}
|
|
237
|
+
{...props}
|
|
238
|
+
/>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export {
|
|
243
|
+
ContextMenu,
|
|
244
|
+
ContextMenuTrigger,
|
|
245
|
+
ContextMenuGroup,
|
|
246
|
+
ContextMenuPortal,
|
|
247
|
+
ContextMenuSub,
|
|
248
|
+
ContextMenuRadioGroup,
|
|
249
|
+
ContextMenuSubTrigger,
|
|
250
|
+
ContextMenuSubContent,
|
|
251
|
+
ContextMenuContent,
|
|
252
|
+
ContextMenuItem,
|
|
253
|
+
ContextMenuCheckboxItem,
|
|
254
|
+
ContextMenuRadioItem,
|
|
255
|
+
ContextMenuLabel,
|
|
256
|
+
ContextMenuSeparator,
|
|
257
|
+
ContextMenuShortcut,
|
|
258
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
import { Upload, X, File as FileIcon } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../lib/utils";
|
|
8
|
+
|
|
9
|
+
// ─── Variants ─────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
const fileUploadZoneVariants = cva(
|
|
12
|
+
[
|
|
13
|
+
"relative flex cursor-pointer flex-col items-center justify-center",
|
|
14
|
+
"rounded-md border-2 border-dashed border-input",
|
|
15
|
+
"text-center transition-colors",
|
|
16
|
+
"focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
|
|
17
|
+
"hover:border-ring/60 hover:bg-accent/20",
|
|
18
|
+
"data-[state=dragging]:border-ring data-[state=dragging]:bg-accent/30",
|
|
19
|
+
"data-[state=rejected]:border-destructive data-[state=rejected]:bg-destructive/5",
|
|
20
|
+
"aria-disabled:pointer-events-none aria-disabled:opacity-50",
|
|
21
|
+
],
|
|
22
|
+
{
|
|
23
|
+
variants: {
|
|
24
|
+
size: {
|
|
25
|
+
sm: "gap-1.5 p-4",
|
|
26
|
+
default: "gap-2 p-8",
|
|
27
|
+
lg: "gap-3 p-12",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: { size: "default" },
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
export interface FileUploadProps extends VariantProps<typeof fileUploadZoneVariants> {
|
|
37
|
+
/** Controlled file list */
|
|
38
|
+
value?: File[];
|
|
39
|
+
/** Fires when the file list changes */
|
|
40
|
+
onChange?: (files: File[]) => void;
|
|
41
|
+
/** Accepted file types — same format as <input type="file" accept="…"> */
|
|
42
|
+
accept?: string;
|
|
43
|
+
/** Allow selecting more than one file */
|
|
44
|
+
multiple?: boolean;
|
|
45
|
+
/** Maximum file size in bytes. Files larger than this are silently rejected. */
|
|
46
|
+
maxSize?: number;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
className?: string;
|
|
49
|
+
/** Accessible name for the hidden file input */
|
|
50
|
+
"aria-label"?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
function formatBytes(bytes: number): string {
|
|
56
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
57
|
+
if (bytes < 1_048_576) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
58
|
+
return `${(bytes / 1_048_576).toFixed(1)} MB`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isFileAccepted(file: File, accept: string): boolean {
|
|
62
|
+
const types = accept.split(",").map((t) => t.trim());
|
|
63
|
+
return types.some((type) => {
|
|
64
|
+
if (type.startsWith(".")) return file.name.toLowerCase().endsWith(type.toLowerCase());
|
|
65
|
+
if (type.endsWith("/*")) return file.type.startsWith(type.slice(0, -1));
|
|
66
|
+
return file.type === type;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ─── FileUpload ───────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
function FileUpload({
|
|
73
|
+
value,
|
|
74
|
+
onChange,
|
|
75
|
+
accept,
|
|
76
|
+
multiple = false,
|
|
77
|
+
maxSize,
|
|
78
|
+
disabled = false,
|
|
79
|
+
size,
|
|
80
|
+
className,
|
|
81
|
+
"aria-label": ariaLabel = "File upload",
|
|
82
|
+
}: FileUploadProps) {
|
|
83
|
+
const inputId = React.useId();
|
|
84
|
+
const isControlled = value !== undefined;
|
|
85
|
+
|
|
86
|
+
const [localFiles, setLocalFiles] = React.useState<File[]>([]);
|
|
87
|
+
const files = isControlled ? value : localFiles;
|
|
88
|
+
|
|
89
|
+
const [dragState, setDragState] = React.useState<"idle" | "dragging" | "rejected">("idle");
|
|
90
|
+
const dragCounterRef = React.useRef(0);
|
|
91
|
+
const rejectTimerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
92
|
+
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
return () => clearTimeout(rejectTimerRef.current);
|
|
95
|
+
}, []);
|
|
96
|
+
|
|
97
|
+
// ── file intake ────────────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
const handleFiles = React.useCallback(
|
|
100
|
+
(incoming: FileList | File[]) => {
|
|
101
|
+
const arr = Array.from(incoming);
|
|
102
|
+
const valid = arr.filter((f) => {
|
|
103
|
+
if (accept && !isFileAccepted(f, accept)) return false;
|
|
104
|
+
if (maxSize !== undefined && f.size > maxSize) return false;
|
|
105
|
+
return true;
|
|
106
|
+
});
|
|
107
|
+
if (valid.length < arr.length) {
|
|
108
|
+
clearTimeout(rejectTimerRef.current);
|
|
109
|
+
setDragState("rejected");
|
|
110
|
+
rejectTimerRef.current = setTimeout(() => setDragState("idle"), 2000);
|
|
111
|
+
}
|
|
112
|
+
if (valid.length === 0) return;
|
|
113
|
+
const next = multiple ? [...files, ...valid] : valid.slice(0, 1);
|
|
114
|
+
if (!isControlled) setLocalFiles(next);
|
|
115
|
+
onChange?.(next);
|
|
116
|
+
},
|
|
117
|
+
[accept, maxSize, multiple, files, isControlled, onChange]
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// ── drag events ────────────────────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
const handleDragEnter = (e: React.DragEvent) => {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
dragCounterRef.current += 1;
|
|
125
|
+
if (dragCounterRef.current === 1) setDragState("dragging");
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const handleDragOver = (e: React.DragEvent) => {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleDragLeave = (e: React.DragEvent) => {
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
dragCounterRef.current -= 1;
|
|
135
|
+
if (dragCounterRef.current === 0) setDragState("idle");
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const handleDrop = (e: React.DragEvent) => {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
dragCounterRef.current = 0;
|
|
141
|
+
setDragState("idle");
|
|
142
|
+
handleFiles(e.dataTransfer.files);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// ── input change ───────────────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
148
|
+
if (e.target.files) handleFiles(e.target.files);
|
|
149
|
+
e.target.value = ""; // allow re-selecting the same file
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// ── remove ─────────────────────────────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
const removeFile = (index: number) => {
|
|
155
|
+
const next = files.filter((_, i) => i !== index);
|
|
156
|
+
if (!isControlled) setLocalFiles(next);
|
|
157
|
+
onChange?.(next);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const zoneLabel =
|
|
161
|
+
dragState === "dragging"
|
|
162
|
+
? "Drop files here"
|
|
163
|
+
: dragState === "rejected"
|
|
164
|
+
? "File type or size not accepted"
|
|
165
|
+
: "Drag & drop or click to browse";
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div data-slot="file-upload" className={cn("space-y-3", className)}>
|
|
169
|
+
{/* ── drop zone ── */}
|
|
170
|
+
<label
|
|
171
|
+
data-slot="file-upload-zone"
|
|
172
|
+
data-state={dragState}
|
|
173
|
+
htmlFor={inputId}
|
|
174
|
+
aria-disabled={disabled ? "true" : undefined}
|
|
175
|
+
className={cn(fileUploadZoneVariants({ size }))}
|
|
176
|
+
onDragEnter={disabled ? undefined : handleDragEnter}
|
|
177
|
+
onDragOver={disabled ? undefined : handleDragOver}
|
|
178
|
+
onDragLeave={disabled ? undefined : handleDragLeave}
|
|
179
|
+
onDrop={disabled ? undefined : handleDrop}
|
|
180
|
+
style={{
|
|
181
|
+
transitionDuration: "var(--duration-fast)",
|
|
182
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
{/* hidden input — keyboard reachable via sr-only */}
|
|
186
|
+
<input
|
|
187
|
+
id={inputId}
|
|
188
|
+
type="file"
|
|
189
|
+
accept={accept}
|
|
190
|
+
multiple={multiple}
|
|
191
|
+
disabled={disabled}
|
|
192
|
+
aria-label={ariaLabel}
|
|
193
|
+
onChange={handleInputChange}
|
|
194
|
+
className="sr-only"
|
|
195
|
+
/>
|
|
196
|
+
|
|
197
|
+
<Upload
|
|
198
|
+
strokeWidth={1.5}
|
|
199
|
+
className={cn(
|
|
200
|
+
"transition-colors",
|
|
201
|
+
size === "sm" ? "size-5" : size === "lg" ? "size-8" : "size-6",
|
|
202
|
+
dragState === "rejected" ? "text-destructive" : "text-muted-foreground"
|
|
203
|
+
)}
|
|
204
|
+
style={{
|
|
205
|
+
transitionDuration: "var(--duration-fast)",
|
|
206
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
|
|
210
|
+
<div className="space-y-0.5">
|
|
211
|
+
<p
|
|
212
|
+
className={cn(
|
|
213
|
+
"font-medium",
|
|
214
|
+
size === "sm" ? "text-xs" : "text-sm",
|
|
215
|
+
dragState === "rejected" ? "text-destructive" : "text-foreground"
|
|
216
|
+
)}
|
|
217
|
+
>
|
|
218
|
+
{zoneLabel}
|
|
219
|
+
</p>
|
|
220
|
+
{(accept || maxSize) && dragState !== "rejected" && (
|
|
221
|
+
<p className="text-xs text-muted-foreground">
|
|
222
|
+
{[
|
|
223
|
+
accept && `Accepted: ${accept}`,
|
|
224
|
+
maxSize !== undefined && `Max: ${formatBytes(maxSize)}`,
|
|
225
|
+
]
|
|
226
|
+
.filter(Boolean)
|
|
227
|
+
.join(" · ")}
|
|
228
|
+
</p>
|
|
229
|
+
)}
|
|
230
|
+
</div>
|
|
231
|
+
</label>
|
|
232
|
+
|
|
233
|
+
{/* ── file list ── */}
|
|
234
|
+
{files.length > 0 && (
|
|
235
|
+
<ul data-slot="file-upload-list" className="space-y-2">
|
|
236
|
+
{files.map((file, index) => (
|
|
237
|
+
<li
|
|
238
|
+
key={`${file.name}-${index}`}
|
|
239
|
+
data-slot="file-upload-item"
|
|
240
|
+
className="flex items-center gap-3 overflow-hidden rounded-md border border-input px-3 py-2"
|
|
241
|
+
>
|
|
242
|
+
<FileIcon
|
|
243
|
+
strokeWidth={1.5}
|
|
244
|
+
className="size-4 shrink-0 text-muted-foreground"
|
|
245
|
+
/>
|
|
246
|
+
<div className="min-w-0 flex-1">
|
|
247
|
+
<p className="truncate text-sm font-medium text-foreground">{file.name}</p>
|
|
248
|
+
<p className="text-xs text-muted-foreground">{formatBytes(file.size)}</p>
|
|
249
|
+
</div>
|
|
250
|
+
<button
|
|
251
|
+
type="button"
|
|
252
|
+
data-slot="file-upload-remove"
|
|
253
|
+
aria-label={`Remove ${file.name}`}
|
|
254
|
+
onClick={() => removeFile(index)}
|
|
255
|
+
disabled={disabled}
|
|
256
|
+
className={cn(
|
|
257
|
+
"ml-auto shrink-0 rounded text-muted-foreground",
|
|
258
|
+
"outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
259
|
+
"hover:text-foreground",
|
|
260
|
+
"transition-colors",
|
|
261
|
+
"disabled:pointer-events-none disabled:opacity-50"
|
|
262
|
+
)}
|
|
263
|
+
style={{
|
|
264
|
+
transitionDuration: "var(--duration-fast)",
|
|
265
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
266
|
+
}}
|
|
267
|
+
>
|
|
268
|
+
<X strokeWidth={1.5} className="size-4" />
|
|
269
|
+
</button>
|
|
270
|
+
</li>
|
|
271
|
+
))}
|
|
272
|
+
</ul>
|
|
273
|
+
)}
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export { FileUpload, fileUploadZoneVariants };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// Local convenience barrel for preview routes and example components.
|
|
2
2
|
// NOT exported from package.json — published consumers must use per-component
|
|
3
3
|
// import paths so optional peer deps stay optional.
|
|
4
|
+
export * from "./accordion";
|
|
4
5
|
export * from "./alert";
|
|
6
|
+
export * from "./carousel";
|
|
7
|
+
export * from "./alert-dialog";
|
|
5
8
|
export * from "./avatar";
|
|
6
9
|
export * from "./badge";
|
|
7
10
|
export * from "./breadcrumb";
|
|
@@ -12,10 +15,15 @@ export * from "./chart";
|
|
|
12
15
|
export * from "./checkbox";
|
|
13
16
|
export * from "./collapsible";
|
|
14
17
|
export * from "./command";
|
|
18
|
+
export * from "./context-menu";
|
|
15
19
|
export * from "./dialog";
|
|
16
20
|
export * from "./dropdown-menu";
|
|
21
|
+
export * from "./file-upload";
|
|
17
22
|
export * from "./input";
|
|
18
23
|
export * from "./label";
|
|
24
|
+
export * from "./navigation-menu";
|
|
25
|
+
export * from "./number-input";
|
|
26
|
+
export * from "./pagination";
|
|
19
27
|
export * from "./popover";
|
|
20
28
|
export * from "./progress";
|
|
21
29
|
export * from "./radio-group";
|
|
@@ -29,6 +37,8 @@ export * from "./sidebar";
|
|
|
29
37
|
export * from "./skeleton";
|
|
30
38
|
export * from "./slider";
|
|
31
39
|
export * from "./sonner";
|
|
40
|
+
export * from "./spinner";
|
|
41
|
+
export * from "./stepper";
|
|
32
42
|
export * from "./switch";
|
|
33
43
|
export * from "./table";
|
|
34
44
|
export * from "./tabs";
|