@fldr/ui 0.3.5 → 0.3.7
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/THEMING.md +1 -1
- package/ai/component-registry.json +962 -43
- package/ai/component-registry.md +1 -1
- package/dist/.build-complete +1 -1
- package/dist/blocks-source/activity-feed/activity-feed.test.tsx +75 -0
- package/dist/blocks-source/activity-feed/activity-feed.tsx +256 -0
- package/dist/blocks-source/app-shell/app-shell.test.tsx +74 -0
- package/dist/blocks-source/app-shell/app-shell.tsx +123 -0
- package/dist/blocks-source/auth-card/auth-card.test.tsx +64 -0
- package/dist/blocks-source/auth-card/auth-card.tsx +234 -0
- package/dist/blocks-source/dashboard-page/dashboard-page.tsx +167 -0
- package/dist/blocks-source/error-page/error-page.test.tsx +60 -0
- package/dist/blocks-source/error-page/error-page.tsx +97 -0
- package/dist/blocks-source/file-table/file-item.tsx +164 -0
- package/dist/blocks-source/file-table/file-table.test.tsx +82 -0
- package/dist/blocks-source/file-table/file-table.tsx +292 -0
- package/dist/blocks-source/folder-grid/folder-grid.test.tsx +54 -0
- package/dist/blocks-source/folder-grid/folder-grid.tsx +170 -0
- package/dist/blocks-source/login-page/login-page.tsx +47 -0
- package/dist/blocks-source/onboarding-checklist/onboarding-checklist.test.tsx +50 -0
- package/dist/blocks-source/onboarding-checklist/onboarding-checklist.tsx +180 -0
- package/dist/blocks-source/settings-section/settings-section.test.tsx +43 -0
- package/dist/blocks-source/settings-section/settings-section.tsx +165 -0
- package/dist/blocks-source/share-dialog/share-dialog.test.tsx +69 -0
- package/dist/blocks-source/share-dialog/share-dialog.tsx +307 -0
- package/dist/blocks-source/stat-grid/stat-grid.test.tsx +52 -0
- package/dist/blocks-source/stat-grid/stat-grid.tsx +153 -0
- package/dist/blocks-source/upload-dropzone/upload-dropzone.test.tsx +82 -0
- package/dist/blocks-source/upload-dropzone/upload-dropzone.tsx +264 -0
- package/dist/blocks.d.ts +780 -0
- package/dist/blocks.js +1664 -0
- package/dist/chunks/delete-resource-cmlptb61ih8s84r3.js +151 -0
- package/dist/chunks/{tabs-o59bv7348nh2gppm.js → tabs-cja62qojznpj99et.js} +2 -0
- package/dist/components/tabs.js +1 -1
- package/dist/delete-resource-DY-GFy2s.d.ts +48 -0
- package/dist/index.d.ts +4 -50
- package/dist/index.js +2 -147
- package/dist/primitives.d.ts +1 -1
- package/dist/styles/kumo-standalone.css +1 -1
- package/dist/styles/theme-fldr.css +12 -0
- package/dist/theming.d.ts +29 -2
- package/dist/theming.js +19 -4
- package/package.json +5 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { useId, useRef, useState, type DragEvent } from "react";
|
|
2
|
+
import {
|
|
3
|
+
ArrowClockwiseIcon,
|
|
4
|
+
CheckCircleIcon,
|
|
5
|
+
FileIcon,
|
|
6
|
+
UploadSimpleIcon,
|
|
7
|
+
WarningCircleIcon,
|
|
8
|
+
XIcon,
|
|
9
|
+
} from "@phosphor-icons/react";
|
|
10
|
+
import { Button } from "../../components/button";
|
|
11
|
+
import { cn } from "../../utils/cn";
|
|
12
|
+
import { formatFileSize } from "../file-table/file-item";
|
|
13
|
+
|
|
14
|
+
export type UploadStatus = "uploading" | "done" | "error";
|
|
15
|
+
|
|
16
|
+
export interface UploadItem {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
/** Size in bytes. */
|
|
20
|
+
size: number;
|
|
21
|
+
/** Progress from 0 to 100. */
|
|
22
|
+
progress: number;
|
|
23
|
+
status: UploadStatus;
|
|
24
|
+
/** Error message shown when `status` is `"error"`. */
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type UploadRejectReason = "size" | "type";
|
|
29
|
+
|
|
30
|
+
export interface UploadRejection {
|
|
31
|
+
file: File;
|
|
32
|
+
reason: UploadRejectReason;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface UploadDropzoneLabels {
|
|
36
|
+
title: string;
|
|
37
|
+
hint: string;
|
|
38
|
+
browse: string;
|
|
39
|
+
done: string;
|
|
40
|
+
failed: string;
|
|
41
|
+
retry: string;
|
|
42
|
+
remove: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface UploadDropzoneProps {
|
|
46
|
+
/** Current uploads, owned by the consumer. */
|
|
47
|
+
uploads?: UploadItem[];
|
|
48
|
+
/** Called with accepted files from a drop or the file picker. */
|
|
49
|
+
onFiles: (files: File[]) => void;
|
|
50
|
+
/** Called with files rejected for size or type. */
|
|
51
|
+
onReject?: (rejections: UploadRejection[]) => void;
|
|
52
|
+
onRetry?: (id: string) => void;
|
|
53
|
+
onRemove?: (id: string) => void;
|
|
54
|
+
/** Same format as the input `accept` attribute, e.g. `".pdf,image/*"`. */
|
|
55
|
+
accept?: string;
|
|
56
|
+
/** @default true */
|
|
57
|
+
multiple?: boolean;
|
|
58
|
+
/** Maximum file size in bytes. */
|
|
59
|
+
maxSize?: number;
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
labels?: Partial<UploadDropzoneLabels>;
|
|
62
|
+
className?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const DEFAULT_LABELS: UploadDropzoneLabels = {
|
|
66
|
+
title: "Drop files here",
|
|
67
|
+
hint: "Receipts, documents and images",
|
|
68
|
+
browse: "Browse files",
|
|
69
|
+
done: "Uploaded",
|
|
70
|
+
failed: "Upload failed",
|
|
71
|
+
retry: "Retry",
|
|
72
|
+
remove: "Remove",
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function matchesAccept(file: File, accept?: string): boolean {
|
|
76
|
+
if (!accept) return true;
|
|
77
|
+
const name = file.name.toLowerCase();
|
|
78
|
+
const type = file.type.toLowerCase();
|
|
79
|
+
return accept.split(",").some((raw) => {
|
|
80
|
+
const rule = raw.trim().toLowerCase();
|
|
81
|
+
if (!rule) return false;
|
|
82
|
+
if (rule.startsWith(".")) return name.endsWith(rule);
|
|
83
|
+
if (rule.endsWith("/*")) return type.startsWith(rule.slice(0, -1));
|
|
84
|
+
return type === rule;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Drag-and-drop upload area with a file list. Performs no network requests:
|
|
90
|
+
* the consumer owns upload state and reacts to the callbacks.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```tsx
|
|
94
|
+
* <UploadDropzone
|
|
95
|
+
* accept=".pdf,image/*"
|
|
96
|
+
* maxSize={10 * 1024 * 1024}
|
|
97
|
+
* uploads={uploads}
|
|
98
|
+
* onFiles={startUploads}
|
|
99
|
+
* onReject={(r) => toast(`${r.length} file(s) skipped`)}
|
|
100
|
+
* onRetry={retryUpload}
|
|
101
|
+
* onRemove={removeUpload}
|
|
102
|
+
* />
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function UploadDropzone({
|
|
106
|
+
uploads = [],
|
|
107
|
+
onFiles,
|
|
108
|
+
onReject,
|
|
109
|
+
onRetry,
|
|
110
|
+
onRemove,
|
|
111
|
+
accept,
|
|
112
|
+
multiple = true,
|
|
113
|
+
maxSize,
|
|
114
|
+
disabled = false,
|
|
115
|
+
labels,
|
|
116
|
+
className,
|
|
117
|
+
}: UploadDropzoneProps) {
|
|
118
|
+
const l = { ...DEFAULT_LABELS, ...labels };
|
|
119
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
120
|
+
const hintId = useId();
|
|
121
|
+
const [dragging, setDragging] = useState(false);
|
|
122
|
+
|
|
123
|
+
const handleFiles = (list: FileList | null) => {
|
|
124
|
+
if (!list || disabled) return;
|
|
125
|
+
const files = multiple ? Array.from(list) : Array.from(list).slice(0, 1);
|
|
126
|
+
const accepted: File[] = [];
|
|
127
|
+
const rejected: UploadRejection[] = [];
|
|
128
|
+
for (const file of files) {
|
|
129
|
+
if (!matchesAccept(file, accept)) rejected.push({ file, reason: "type" });
|
|
130
|
+
else if (maxSize !== undefined && file.size > maxSize)
|
|
131
|
+
rejected.push({ file, reason: "size" });
|
|
132
|
+
else accepted.push(file);
|
|
133
|
+
}
|
|
134
|
+
if (accepted.length) onFiles(accepted);
|
|
135
|
+
if (rejected.length) onReject?.(rejected);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const onDragOver = (e: DragEvent<HTMLDivElement>) => {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
if (!disabled) setDragging(true);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const onDragLeave = (e: DragEvent<HTMLDivElement>) => {
|
|
144
|
+
if (!e.currentTarget.contains(e.relatedTarget as Node | null))
|
|
145
|
+
setDragging(false);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const onDrop = (e: DragEvent<HTMLDivElement>) => {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
setDragging(false);
|
|
151
|
+
handleFiles(e.dataTransfer.files);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<div className={cn("flex flex-col gap-2", className)}>
|
|
156
|
+
<div
|
|
157
|
+
data-dragging={dragging || undefined}
|
|
158
|
+
onDragOver={onDragOver}
|
|
159
|
+
onDragLeave={onDragLeave}
|
|
160
|
+
onDrop={onDrop}
|
|
161
|
+
className={cn(
|
|
162
|
+
"flex flex-col items-center gap-1.5 rounded-lg border border-dashed border-kumo-line bg-kumo-elevated px-4 py-5 text-center",
|
|
163
|
+
dragging && "border-kumo-brand bg-kumo-tint",
|
|
164
|
+
disabled && "opacity-50",
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
<UploadSimpleIcon size={24} className="text-kumo-subtle" />
|
|
168
|
+
<div className="text-sm font-medium text-kumo-default">{l.title}</div>
|
|
169
|
+
<div id={hintId} className="text-xs text-kumo-subtle">
|
|
170
|
+
{l.hint}
|
|
171
|
+
{maxSize !== undefined && ` · ${formatFileSize(maxSize)} max`}
|
|
172
|
+
</div>
|
|
173
|
+
<Button
|
|
174
|
+
size="sm"
|
|
175
|
+
className="mt-1"
|
|
176
|
+
disabled={disabled}
|
|
177
|
+
aria-describedby={hintId}
|
|
178
|
+
onClick={() => inputRef.current?.click()}
|
|
179
|
+
>
|
|
180
|
+
{l.browse}
|
|
181
|
+
</Button>
|
|
182
|
+
<input
|
|
183
|
+
ref={inputRef}
|
|
184
|
+
type="file"
|
|
185
|
+
hidden
|
|
186
|
+
tabIndex={-1}
|
|
187
|
+
accept={accept}
|
|
188
|
+
multiple={multiple}
|
|
189
|
+
disabled={disabled}
|
|
190
|
+
data-testid="upload-dropzone-input"
|
|
191
|
+
onChange={(e) => {
|
|
192
|
+
handleFiles(e.currentTarget.files);
|
|
193
|
+
e.currentTarget.value = "";
|
|
194
|
+
}}
|
|
195
|
+
/>
|
|
196
|
+
</div>
|
|
197
|
+
|
|
198
|
+
{uploads.length > 0 && (
|
|
199
|
+
<ul className="m-0 flex list-none flex-col divide-y divide-kumo-hairline p-0">
|
|
200
|
+
{uploads.map((u) => (
|
|
201
|
+
<li key={u.id} className="flex items-center gap-3 px-1 py-1.5">
|
|
202
|
+
<FileIcon size={18} className="shrink-0 text-kumo-subtle" />
|
|
203
|
+
<div className="flex min-w-0 grow flex-col gap-1">
|
|
204
|
+
<div className="flex items-baseline justify-between gap-2 text-sm">
|
|
205
|
+
<span className="truncate text-kumo-default">{u.name}</span>
|
|
206
|
+
<span className="shrink-0 text-xs text-kumo-subtle tabular-nums">
|
|
207
|
+
{formatFileSize(u.size)}
|
|
208
|
+
</span>
|
|
209
|
+
</div>
|
|
210
|
+
{u.status === "uploading" && (
|
|
211
|
+
<div
|
|
212
|
+
role="progressbar"
|
|
213
|
+
aria-label={u.name}
|
|
214
|
+
aria-valuemin={0}
|
|
215
|
+
aria-valuemax={100}
|
|
216
|
+
aria-valuenow={Math.round(u.progress)}
|
|
217
|
+
className="h-1 overflow-hidden rounded-full bg-kumo-recessed"
|
|
218
|
+
>
|
|
219
|
+
<div
|
|
220
|
+
className="h-full bg-kumo-brand"
|
|
221
|
+
style={{
|
|
222
|
+
width: `${Math.min(100, Math.max(0, u.progress))}%`,
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
)}
|
|
227
|
+
{u.status === "done" && (
|
|
228
|
+
<span className="flex items-center gap-1 text-xs text-kumo-success">
|
|
229
|
+
<CheckCircleIcon size={14} /> {l.done}
|
|
230
|
+
</span>
|
|
231
|
+
)}
|
|
232
|
+
{u.status === "error" && (
|
|
233
|
+
<span className="flex items-center gap-1 text-xs text-kumo-danger">
|
|
234
|
+
<WarningCircleIcon size={14} /> {u.error ?? l.failed}
|
|
235
|
+
</span>
|
|
236
|
+
)}
|
|
237
|
+
</div>
|
|
238
|
+
{u.status === "error" && onRetry && (
|
|
239
|
+
<Button
|
|
240
|
+
size="sm"
|
|
241
|
+
variant="ghost"
|
|
242
|
+
shape="square"
|
|
243
|
+
icon={ArrowClockwiseIcon}
|
|
244
|
+
aria-label={`${l.retry} ${u.name}`}
|
|
245
|
+
onClick={() => onRetry(u.id)}
|
|
246
|
+
/>
|
|
247
|
+
)}
|
|
248
|
+
{onRemove && (
|
|
249
|
+
<Button
|
|
250
|
+
size="sm"
|
|
251
|
+
variant="ghost"
|
|
252
|
+
shape="square"
|
|
253
|
+
icon={XIcon}
|
|
254
|
+
aria-label={`${l.remove} ${u.name}`}
|
|
255
|
+
onClick={() => onRemove(u.id)}
|
|
256
|
+
/>
|
|
257
|
+
)}
|
|
258
|
+
</li>
|
|
259
|
+
))}
|
|
260
|
+
</ul>
|
|
261
|
+
)}
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
}
|