@rafal.lemieszewski/tide-ui 0.88.2 → 0.90.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.
- package/dist/cjs/components/fundamental/button-group.cjs +1 -1
- package/dist/cjs/components/fundamental/chart.cjs +1 -1
- package/dist/cjs/components/fundamental/file-upload.cjs +1 -1
- package/dist/es/components/fundamental/button-group.js +49 -45
- package/dist/es/components/fundamental/chart.js +3 -2
- package/dist/es/components/fundamental/file-upload.js +180 -154
- package/dist/es/style.css +1 -1
- package/dist/types/components/fundamental/button-group.d.ts +3 -3
- package/dist/types/components/fundamental/file-upload.d.ts +13 -3
- package/dist/types/components/index.d.ts +2 -2
- package/package.json +2 -1
|
@@ -1,61 +1,71 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
1
|
+
import { jsx as i, jsxs as F, Fragment as Z } from "react/jsx-runtime";
|
|
2
|
+
import * as d from "react";
|
|
3
3
|
import { cn as v } from "../../lib/utils.js";
|
|
4
|
-
import { cva as
|
|
5
|
-
import { Button as
|
|
6
|
-
import { Progress as
|
|
7
|
-
import { Icon as
|
|
8
|
-
import { X as
|
|
9
|
-
import { Badge as
|
|
10
|
-
const
|
|
4
|
+
import { cva as _ } from "class-variance-authority";
|
|
5
|
+
import { Button as z } from "./button.js";
|
|
6
|
+
import { Progress as ee } from "./progress.js";
|
|
7
|
+
import { Icon as M } from "./icon.js";
|
|
8
|
+
import { X as re } from "lucide-react";
|
|
9
|
+
import { Badge as te } from "./badge.js";
|
|
10
|
+
const j = d.createContext(
|
|
11
11
|
null
|
|
12
|
-
),
|
|
13
|
-
const r =
|
|
12
|
+
), I = () => {
|
|
13
|
+
const r = d.useContext(j);
|
|
14
14
|
if (!r)
|
|
15
15
|
throw new Error("useFileUpload must be used within a FileUpload component");
|
|
16
16
|
return r;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
|
+
function oe(r) {
|
|
19
|
+
return r instanceof File;
|
|
20
|
+
}
|
|
21
|
+
const L = /* @__PURE__ */ d.forwardRef(
|
|
18
22
|
({
|
|
19
23
|
className: r,
|
|
20
24
|
files: e,
|
|
21
25
|
onFilesChange: o,
|
|
22
26
|
maxFiles: t = 10,
|
|
23
|
-
maxSize:
|
|
27
|
+
maxSize: a = 10 * 1024 * 1024,
|
|
24
28
|
// 10MB
|
|
25
|
-
accept:
|
|
26
|
-
disabled:
|
|
27
|
-
multiple:
|
|
28
|
-
onUpload:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
accept: n,
|
|
30
|
+
disabled: p = !1,
|
|
31
|
+
multiple: m = !0,
|
|
32
|
+
onUpload: c,
|
|
33
|
+
onDelete: u,
|
|
34
|
+
uploadMode: h = "auto",
|
|
35
|
+
children: w,
|
|
36
|
+
...N
|
|
37
|
+
}, U) => {
|
|
38
|
+
const b = d.useMemo(
|
|
33
39
|
() => ({
|
|
34
40
|
files: e,
|
|
35
41
|
onFilesChange: o,
|
|
36
42
|
maxFiles: t,
|
|
37
|
-
maxSize:
|
|
38
|
-
accept:
|
|
39
|
-
disabled:
|
|
40
|
-
multiple:
|
|
41
|
-
onUpload:
|
|
43
|
+
maxSize: a,
|
|
44
|
+
accept: n,
|
|
45
|
+
disabled: p,
|
|
46
|
+
multiple: m,
|
|
47
|
+
onUpload: c,
|
|
48
|
+
onDelete: u,
|
|
49
|
+
uploadMode: h
|
|
42
50
|
}),
|
|
43
51
|
[
|
|
44
52
|
e,
|
|
45
53
|
o,
|
|
46
54
|
t,
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
a,
|
|
56
|
+
n,
|
|
57
|
+
p,
|
|
49
58
|
m,
|
|
50
59
|
c,
|
|
51
|
-
|
|
60
|
+
u,
|
|
61
|
+
h
|
|
52
62
|
]
|
|
53
63
|
);
|
|
54
|
-
return /* @__PURE__ */
|
|
64
|
+
return /* @__PURE__ */ i(j.Provider, { value: b, children: /* @__PURE__ */ i("div", { ref: U, className: v("space-y-4", r), ...N, children: w }) });
|
|
55
65
|
}
|
|
56
66
|
);
|
|
57
|
-
|
|
58
|
-
const
|
|
67
|
+
L.displayName = "FileUploadRoot";
|
|
68
|
+
const ae = _(
|
|
59
69
|
"relative flex flex-col items-center justify-center rounded-[var(--border-radius-l)] border-2 border-dashed p-6 text-center transition-colors duration-200",
|
|
60
70
|
{
|
|
61
71
|
variants: {
|
|
@@ -73,92 +83,97 @@ const ee = Q(
|
|
|
73
83
|
disabled: !1
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
|
-
),
|
|
86
|
+
), A = /* @__PURE__ */ d.forwardRef(({ className: r, children: e, ...o }, t) => {
|
|
77
87
|
const {
|
|
78
|
-
files:
|
|
79
|
-
onFilesChange:
|
|
80
|
-
maxFiles:
|
|
81
|
-
maxSize:
|
|
82
|
-
accept:
|
|
88
|
+
files: a,
|
|
89
|
+
onFilesChange: n,
|
|
90
|
+
maxFiles: p,
|
|
91
|
+
maxSize: m,
|
|
92
|
+
accept: c,
|
|
83
93
|
disabled: u,
|
|
84
|
-
multiple:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
multiple: h,
|
|
95
|
+
onUpload: w,
|
|
96
|
+
uploadMode: N
|
|
97
|
+
} = I(), [U, b] = d.useState(!1), R = d.useRef(null), G = (s) => {
|
|
98
|
+
if (m && s.size > m)
|
|
99
|
+
return `File size must be less than ${S(m)}`;
|
|
100
|
+
if (c && c.length > 0) {
|
|
101
|
+
const l = s.type, y = `.${s.name.split(".").pop()?.toLowerCase()}`;
|
|
102
|
+
if (!c.some((f) => {
|
|
91
103
|
if (f.startsWith("."))
|
|
92
|
-
return f.toLowerCase() ===
|
|
104
|
+
return f.toLowerCase() === y;
|
|
93
105
|
if (f.includes("*")) {
|
|
94
|
-
const
|
|
95
|
-
return
|
|
106
|
+
const x = f.split("/")[0];
|
|
107
|
+
return l.startsWith(x);
|
|
96
108
|
}
|
|
97
|
-
return
|
|
109
|
+
return l === f;
|
|
98
110
|
}))
|
|
99
|
-
return `File type not supported. Accepted types: ${
|
|
111
|
+
return `File type not supported. Accepted types: ${c.join(", ")}`;
|
|
100
112
|
}
|
|
101
113
|
return null;
|
|
102
|
-
},
|
|
103
|
-
const
|
|
104
|
-
Array.from(
|
|
105
|
-
if (
|
|
106
|
-
const
|
|
114
|
+
}, C = async (s) => {
|
|
115
|
+
const l = [], y = a.length;
|
|
116
|
+
if (Array.from(s).forEach((g, f) => {
|
|
117
|
+
if (p && y + l.length >= p) return;
|
|
118
|
+
const x = G(g), k = {
|
|
107
119
|
id: `${Date.now()}-${f}`,
|
|
108
|
-
file:
|
|
109
|
-
status:
|
|
110
|
-
error:
|
|
120
|
+
file: g,
|
|
121
|
+
status: x ? "error" : "pending",
|
|
122
|
+
error: x || void 0,
|
|
111
123
|
progress: 0
|
|
112
124
|
};
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
(
|
|
125
|
+
if (g.type.startsWith("image/")) {
|
|
126
|
+
const P = new FileReader();
|
|
127
|
+
P.onload = (Q) => {
|
|
128
|
+
const Y = a.map(
|
|
129
|
+
(D) => D.id === k.id ? { ...D, preview: Q.target?.result } : D
|
|
118
130
|
);
|
|
119
|
-
|
|
120
|
-
},
|
|
131
|
+
n(Y);
|
|
132
|
+
}, P.readAsDataURL(g);
|
|
121
133
|
}
|
|
122
|
-
|
|
123
|
-
}),
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
l.push(k);
|
|
135
|
+
}), l.length > 0 && (n([...a, ...l]), N === "auto" && w)) {
|
|
136
|
+
const g = l.filter((f) => f.status !== "error");
|
|
137
|
+
g.length > 0 && await w(g);
|
|
138
|
+
}
|
|
139
|
+
}, K = (s) => {
|
|
140
|
+
s.preventDefault(), s.stopPropagation(), u || b(!0);
|
|
141
|
+
}, X = (s) => {
|
|
142
|
+
s.preventDefault(), s.stopPropagation(), b(!1);
|
|
143
|
+
}, q = (s) => {
|
|
144
|
+
if (s.preventDefault(), s.stopPropagation(), b(!1), u) return;
|
|
145
|
+
const l = s.dataTransfer.files;
|
|
146
|
+
l.length > 0 && C(l);
|
|
147
|
+
}, H = () => {
|
|
148
|
+
u || R.current?.click();
|
|
149
|
+
}, J = (s) => {
|
|
150
|
+
const l = s.target.files;
|
|
151
|
+
l && C(l), s.target.value = "";
|
|
137
152
|
};
|
|
138
|
-
return /* @__PURE__ */
|
|
153
|
+
return /* @__PURE__ */ F(
|
|
139
154
|
"div",
|
|
140
155
|
{
|
|
141
156
|
ref: t,
|
|
142
|
-
className: v(
|
|
143
|
-
onDragOver:
|
|
144
|
-
onDragLeave:
|
|
145
|
-
onDrop:
|
|
146
|
-
onClick:
|
|
157
|
+
className: v(ae({ isDragActive: U, disabled: u }), r),
|
|
158
|
+
onDragOver: K,
|
|
159
|
+
onDragLeave: X,
|
|
160
|
+
onDrop: q,
|
|
161
|
+
onClick: H,
|
|
147
162
|
role: "button",
|
|
148
163
|
tabIndex: u ? -1 : 0,
|
|
149
164
|
"aria-label": "Upload files",
|
|
150
165
|
...o,
|
|
151
166
|
children: [
|
|
152
|
-
/* @__PURE__ */
|
|
167
|
+
/* @__PURE__ */ i(
|
|
153
168
|
"input",
|
|
154
169
|
{
|
|
155
|
-
ref:
|
|
170
|
+
ref: R,
|
|
156
171
|
type: "file",
|
|
157
|
-
multiple:
|
|
158
|
-
accept:
|
|
172
|
+
multiple: h,
|
|
173
|
+
accept: c?.join(","),
|
|
159
174
|
disabled: u,
|
|
160
175
|
className: "hidden",
|
|
161
|
-
onChange:
|
|
176
|
+
onChange: J
|
|
162
177
|
}
|
|
163
178
|
),
|
|
164
179
|
e
|
|
@@ -166,21 +181,26 @@ const ee = Q(
|
|
|
166
181
|
}
|
|
167
182
|
);
|
|
168
183
|
});
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
const { disabled:
|
|
172
|
-
return /* @__PURE__ */
|
|
184
|
+
A.displayName = "FileUploadDropzone";
|
|
185
|
+
const B = /* @__PURE__ */ d.forwardRef(({ children: r, onClick: e, ...o }, t) => {
|
|
186
|
+
const { disabled: a, files: n, onUpload: p } = I();
|
|
187
|
+
return /* @__PURE__ */ i(z, { ref: t, disabled: a, onClick: async (c) => {
|
|
188
|
+
if (e?.(c), p) {
|
|
189
|
+
const u = n.filter((h) => h.status === "pending");
|
|
190
|
+
u.length > 0 && await p(u);
|
|
191
|
+
}
|
|
192
|
+
}, ...o, children: r });
|
|
173
193
|
});
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
({ className: r, children: e, ...o }, t) => /* @__PURE__ */
|
|
194
|
+
B.displayName = "FileUploadTrigger";
|
|
195
|
+
const W = /* @__PURE__ */ d.forwardRef(
|
|
196
|
+
({ className: r, children: e, ...o }, t) => /* @__PURE__ */ i("div", { ref: t, className: v("space-y-2", r), ...o, children: e })
|
|
177
197
|
);
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
({ className: r, file: e, children: o, ...t },
|
|
198
|
+
W.displayName = "FileUploadList";
|
|
199
|
+
const $ = /* @__PURE__ */ d.forwardRef(
|
|
200
|
+
({ className: r, file: e, children: o, ...t }, a) => /* @__PURE__ */ i(
|
|
181
201
|
"div",
|
|
182
202
|
{
|
|
183
|
-
ref:
|
|
203
|
+
ref: a,
|
|
184
204
|
className: v(
|
|
185
205
|
"flex items-center gap-3 rounded-[var(--border-radius-l)] border p-3",
|
|
186
206
|
"border-[var(--color-border-primary)]",
|
|
@@ -193,10 +213,10 @@ const B = /* @__PURE__ */ n.forwardRef(
|
|
|
193
213
|
}
|
|
194
214
|
)
|
|
195
215
|
);
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
return /* @__PURE__ */
|
|
216
|
+
$.displayName = "FileUploadItem";
|
|
217
|
+
const V = /* @__PURE__ */ d.forwardRef(({ className: r, file: e, ...o }, t) => {
|
|
218
|
+
const a = (n) => n.startsWith("image/") ? "image" : n.startsWith("video/") ? "video" : n.startsWith("audio/") ? "volume-2" : n.includes("pdf") || n.includes("text/") || n.includes("application/json") ? "file-text" : "file";
|
|
219
|
+
return /* @__PURE__ */ i(
|
|
200
220
|
"div",
|
|
201
221
|
{
|
|
202
222
|
ref: t,
|
|
@@ -205,86 +225,92 @@ const W = /* @__PURE__ */ n.forwardRef(({ className: r, file: e, ...o }, t) => {
|
|
|
205
225
|
r
|
|
206
226
|
),
|
|
207
227
|
...o,
|
|
208
|
-
children: e.preview ? /* @__PURE__ */
|
|
228
|
+
children: e.preview && oe(e.file) ? /* @__PURE__ */ i(
|
|
209
229
|
"img",
|
|
210
230
|
{
|
|
211
231
|
src: e.preview,
|
|
212
232
|
alt: e.file.name,
|
|
213
233
|
className: "h-full w-full rounded object-cover"
|
|
214
234
|
}
|
|
215
|
-
) : /* @__PURE__ */
|
|
216
|
-
|
|
235
|
+
) : /* @__PURE__ */ i(
|
|
236
|
+
M,
|
|
217
237
|
{
|
|
218
|
-
name:
|
|
238
|
+
name: a(e.file.type ?? ""),
|
|
219
239
|
className: "h-5 w-5 text-[var(--color-text-secondary)]"
|
|
220
240
|
}
|
|
221
241
|
)
|
|
222
242
|
}
|
|
223
243
|
);
|
|
224
244
|
});
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
/* @__PURE__ */
|
|
228
|
-
/* @__PURE__ */
|
|
229
|
-
/* @__PURE__ */
|
|
245
|
+
V.displayName = "FileUploadItemPreview";
|
|
246
|
+
const T = /* @__PURE__ */ d.forwardRef(({ className: r, file: e, children: o, ...t }, a) => /* @__PURE__ */ i("div", { ref: a, className: v("flex-1 space-y-1", r), ...t, children: o ?? /* @__PURE__ */ F(Z, { children: [
|
|
247
|
+
/* @__PURE__ */ F("div", { className: "flex items-center gap-2", children: [
|
|
248
|
+
/* @__PURE__ */ i("p", { className: "text-body-sm truncate font-medium", children: e.file.name }),
|
|
249
|
+
/* @__PURE__ */ i(te, { children: e.status })
|
|
230
250
|
] }),
|
|
231
|
-
/* @__PURE__ */
|
|
232
|
-
e.error && /* @__PURE__ */
|
|
233
|
-
] }));
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
/* @__PURE__ */
|
|
237
|
-
/* @__PURE__ */
|
|
251
|
+
/* @__PURE__ */ i("p", { className: "text-caption-sm text-[var(--color-text-secondary)]", children: S(e.file.size) }),
|
|
252
|
+
e.error && /* @__PURE__ */ i("p", { className: "text-caption-sm text-[var(--color-text-error-bold)]", children: e.error })
|
|
253
|
+
] }) }));
|
|
254
|
+
T.displayName = "FileUploadItemMetadata";
|
|
255
|
+
const E = /* @__PURE__ */ d.forwardRef(({ className: r, file: e, variant: o = "linear", ...t }, a) => e.status !== "uploading" || e.progress === void 0 ? null : /* @__PURE__ */ F("div", { ref: a, className: v("w-full", r), ...t, children: [
|
|
256
|
+
/* @__PURE__ */ i(ee, { value: e.progress, className: "h-2" }),
|
|
257
|
+
/* @__PURE__ */ F("p", { className: "text-caption-sm mt-1 text-[var(--color-text-secondary)]", children: [
|
|
238
258
|
Math.round(e.progress),
|
|
239
259
|
"%"
|
|
240
260
|
] })
|
|
241
261
|
] }));
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
const { files: t, onFilesChange:
|
|
245
|
-
return /* @__PURE__ */
|
|
246
|
-
|
|
262
|
+
E.displayName = "FileUploadItemProgress";
|
|
263
|
+
const O = /* @__PURE__ */ d.forwardRef(({ file: r, ...e }, o) => {
|
|
264
|
+
const { files: t, onFilesChange: a, onDelete: n } = I();
|
|
265
|
+
return /* @__PURE__ */ i(
|
|
266
|
+
z,
|
|
247
267
|
{
|
|
248
268
|
ref: o,
|
|
249
269
|
variant: "ghost",
|
|
250
270
|
size: "s",
|
|
251
|
-
onClick: () => {
|
|
271
|
+
onClick: async () => {
|
|
272
|
+
if (n)
|
|
273
|
+
try {
|
|
274
|
+
await n(r);
|
|
275
|
+
} catch {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
252
278
|
const m = t.filter((c) => c.id !== r.id);
|
|
253
|
-
|
|
279
|
+
a(m);
|
|
254
280
|
},
|
|
255
281
|
"aria-label": `Remove ${r.file.name}`,
|
|
256
282
|
...e,
|
|
257
|
-
children: /* @__PURE__ */
|
|
283
|
+
children: /* @__PURE__ */ i(M, { name: re, className: "h-4 w-4" })
|
|
258
284
|
}
|
|
259
285
|
);
|
|
260
286
|
});
|
|
261
|
-
|
|
262
|
-
const
|
|
287
|
+
O.displayName = "FileUploadItemDelete";
|
|
288
|
+
const S = (r) => {
|
|
263
289
|
if (r === 0) return "0 Bytes";
|
|
264
290
|
const e = 1024, o = ["Bytes", "KB", "MB", "GB"], t = Math.floor(Math.log(r) / Math.log(e));
|
|
265
291
|
return parseFloat((r / Math.pow(e, t)).toFixed(2)) + " " + o[t];
|
|
266
|
-
},
|
|
267
|
-
Root:
|
|
268
|
-
Dropzone:
|
|
269
|
-
Trigger:
|
|
270
|
-
List:
|
|
271
|
-
Item:
|
|
272
|
-
ItemPreview:
|
|
273
|
-
ItemMetadata:
|
|
274
|
-
ItemProgress:
|
|
275
|
-
ItemDelete:
|
|
292
|
+
}, me = {
|
|
293
|
+
Root: L,
|
|
294
|
+
Dropzone: A,
|
|
295
|
+
Trigger: B,
|
|
296
|
+
List: W,
|
|
297
|
+
Item: $,
|
|
298
|
+
ItemPreview: V,
|
|
299
|
+
ItemMetadata: T,
|
|
300
|
+
ItemProgress: E,
|
|
301
|
+
ItemDelete: O
|
|
276
302
|
};
|
|
277
303
|
export {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
304
|
+
me as FileUpload,
|
|
305
|
+
A as FileUploadDropzone,
|
|
306
|
+
$ as FileUploadItem,
|
|
307
|
+
O as FileUploadItemDelete,
|
|
308
|
+
T as FileUploadItemMetadata,
|
|
309
|
+
V as FileUploadItemPreview,
|
|
310
|
+
E as FileUploadItemProgress,
|
|
311
|
+
W as FileUploadList,
|
|
312
|
+
L as FileUploadRoot,
|
|
313
|
+
B as FileUploadTrigger,
|
|
314
|
+
S as formatFileSize,
|
|
315
|
+
I as useFileUpload
|
|
290
316
|
};
|