@rafal.lemieszewski/tide-ui 0.89.0 → 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 +166 -153
- 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 +2 -0
- package/dist/types/components/index.d.ts +1 -1
- package/package.json +2 -1
|
@@ -1,68 +1,71 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import { cn as
|
|
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
|
|
1
|
+
import { jsx as i, jsxs as F, Fragment as Z } from "react/jsx-runtime";
|
|
2
|
+
import * as d from "react";
|
|
3
|
+
import { cn as v } from "../../lib/utils.js";
|
|
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
|
|
18
|
+
function oe(r) {
|
|
19
19
|
return r instanceof File;
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const L = /* @__PURE__ */ d.forwardRef(
|
|
22
22
|
({
|
|
23
23
|
className: r,
|
|
24
24
|
files: e,
|
|
25
25
|
onFilesChange: o,
|
|
26
26
|
maxFiles: t = 10,
|
|
27
|
-
maxSize:
|
|
27
|
+
maxSize: a = 10 * 1024 * 1024,
|
|
28
28
|
// 10MB
|
|
29
|
-
accept:
|
|
30
|
-
disabled:
|
|
31
|
-
multiple:
|
|
29
|
+
accept: n,
|
|
30
|
+
disabled: p = !1,
|
|
31
|
+
multiple: m = !0,
|
|
32
32
|
onUpload: c,
|
|
33
33
|
onDelete: u,
|
|
34
|
+
uploadMode: h = "auto",
|
|
34
35
|
children: w,
|
|
35
36
|
...N
|
|
36
|
-
},
|
|
37
|
-
const
|
|
37
|
+
}, U) => {
|
|
38
|
+
const b = d.useMemo(
|
|
38
39
|
() => ({
|
|
39
40
|
files: e,
|
|
40
41
|
onFilesChange: o,
|
|
41
42
|
maxFiles: t,
|
|
42
|
-
maxSize:
|
|
43
|
-
accept:
|
|
44
|
-
disabled:
|
|
45
|
-
multiple:
|
|
43
|
+
maxSize: a,
|
|
44
|
+
accept: n,
|
|
45
|
+
disabled: p,
|
|
46
|
+
multiple: m,
|
|
46
47
|
onUpload: c,
|
|
47
|
-
onDelete: u
|
|
48
|
+
onDelete: u,
|
|
49
|
+
uploadMode: h
|
|
48
50
|
}),
|
|
49
51
|
[
|
|
50
52
|
e,
|
|
51
53
|
o,
|
|
52
54
|
t,
|
|
55
|
+
a,
|
|
53
56
|
n,
|
|
54
|
-
l,
|
|
55
|
-
v,
|
|
56
57
|
p,
|
|
58
|
+
m,
|
|
57
59
|
c,
|
|
58
|
-
u
|
|
60
|
+
u,
|
|
61
|
+
h
|
|
59
62
|
]
|
|
60
63
|
);
|
|
61
|
-
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 }) });
|
|
62
65
|
}
|
|
63
66
|
);
|
|
64
|
-
|
|
65
|
-
const
|
|
67
|
+
L.displayName = "FileUploadRoot";
|
|
68
|
+
const ae = _(
|
|
66
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",
|
|
67
70
|
{
|
|
68
71
|
variants: {
|
|
@@ -80,92 +83,97 @@ const te = Y(
|
|
|
80
83
|
disabled: !1
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
|
-
),
|
|
86
|
+
), A = /* @__PURE__ */ d.forwardRef(({ className: r, children: e, ...o }, t) => {
|
|
84
87
|
const {
|
|
85
|
-
files:
|
|
86
|
-
onFilesChange:
|
|
87
|
-
maxFiles:
|
|
88
|
-
maxSize:
|
|
88
|
+
files: a,
|
|
89
|
+
onFilesChange: n,
|
|
90
|
+
maxFiles: p,
|
|
91
|
+
maxSize: m,
|
|
89
92
|
accept: c,
|
|
90
93
|
disabled: u,
|
|
91
|
-
multiple:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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)}`;
|
|
95
100
|
if (c && c.length > 0) {
|
|
96
|
-
const
|
|
97
|
-
if (!c.some((
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
100
|
-
if (
|
|
101
|
-
const x =
|
|
102
|
-
return
|
|
101
|
+
const l = s.type, y = `.${s.name.split(".").pop()?.toLowerCase()}`;
|
|
102
|
+
if (!c.some((f) => {
|
|
103
|
+
if (f.startsWith("."))
|
|
104
|
+
return f.toLowerCase() === y;
|
|
105
|
+
if (f.includes("*")) {
|
|
106
|
+
const x = f.split("/")[0];
|
|
107
|
+
return l.startsWith(x);
|
|
103
108
|
}
|
|
104
|
-
return
|
|
109
|
+
return l === f;
|
|
105
110
|
}))
|
|
106
111
|
return `File type not supported. Accepted types: ${c.join(", ")}`;
|
|
107
112
|
}
|
|
108
113
|
return null;
|
|
109
|
-
},
|
|
110
|
-
const
|
|
111
|
-
Array.from(
|
|
112
|
-
if (
|
|
113
|
-
const x =
|
|
114
|
-
id: `${Date.now()}-${
|
|
115
|
-
file:
|
|
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 = {
|
|
119
|
+
id: `${Date.now()}-${f}`,
|
|
120
|
+
file: g,
|
|
116
121
|
status: x ? "error" : "pending",
|
|
117
122
|
error: x || void 0,
|
|
118
123
|
progress: 0
|
|
119
124
|
};
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
(
|
|
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
|
|
125
130
|
);
|
|
126
|
-
|
|
127
|
-
},
|
|
131
|
+
n(Y);
|
|
132
|
+
}, P.readAsDataURL(g);
|
|
128
133
|
}
|
|
129
|
-
|
|
130
|
-
}),
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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 = "";
|
|
144
152
|
};
|
|
145
|
-
return /* @__PURE__ */
|
|
153
|
+
return /* @__PURE__ */ F(
|
|
146
154
|
"div",
|
|
147
155
|
{
|
|
148
156
|
ref: t,
|
|
149
|
-
className:
|
|
150
|
-
onDragOver:
|
|
151
|
-
onDragLeave:
|
|
152
|
-
onDrop:
|
|
153
|
-
onClick:
|
|
157
|
+
className: v(ae({ isDragActive: U, disabled: u }), r),
|
|
158
|
+
onDragOver: K,
|
|
159
|
+
onDragLeave: X,
|
|
160
|
+
onDrop: q,
|
|
161
|
+
onClick: H,
|
|
154
162
|
role: "button",
|
|
155
163
|
tabIndex: u ? -1 : 0,
|
|
156
164
|
"aria-label": "Upload files",
|
|
157
165
|
...o,
|
|
158
166
|
children: [
|
|
159
|
-
/* @__PURE__ */
|
|
167
|
+
/* @__PURE__ */ i(
|
|
160
168
|
"input",
|
|
161
169
|
{
|
|
162
|
-
ref:
|
|
170
|
+
ref: R,
|
|
163
171
|
type: "file",
|
|
164
|
-
multiple:
|
|
172
|
+
multiple: h,
|
|
165
173
|
accept: c?.join(","),
|
|
166
174
|
disabled: u,
|
|
167
175
|
className: "hidden",
|
|
168
|
-
onChange:
|
|
176
|
+
onChange: J
|
|
169
177
|
}
|
|
170
178
|
),
|
|
171
179
|
e
|
|
@@ -173,22 +181,27 @@ const te = Y(
|
|
|
173
181
|
}
|
|
174
182
|
);
|
|
175
183
|
});
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
const { disabled:
|
|
179
|
-
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 });
|
|
180
193
|
});
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
({ 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 })
|
|
184
197
|
);
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
({ 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(
|
|
188
201
|
"div",
|
|
189
202
|
{
|
|
190
|
-
ref:
|
|
191
|
-
className:
|
|
203
|
+
ref: a,
|
|
204
|
+
className: v(
|
|
192
205
|
"flex items-center gap-3 rounded-[var(--border-radius-l)] border p-3",
|
|
193
206
|
"border-[var(--color-border-primary)]",
|
|
194
207
|
e.status === "error" && "border-[var(--color-border-error-bold)] bg-[var(--color-background-error-subtle)]",
|
|
@@ -200,104 +213,104 @@ const B = /* @__PURE__ */ i.forwardRef(
|
|
|
200
213
|
}
|
|
201
214
|
)
|
|
202
215
|
);
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
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(
|
|
207
220
|
"div",
|
|
208
221
|
{
|
|
209
222
|
ref: t,
|
|
210
|
-
className:
|
|
223
|
+
className: v(
|
|
211
224
|
"flex h-10 w-10 items-center justify-center rounded",
|
|
212
225
|
r
|
|
213
226
|
),
|
|
214
227
|
...o,
|
|
215
|
-
children: e.preview &&
|
|
228
|
+
children: e.preview && oe(e.file) ? /* @__PURE__ */ i(
|
|
216
229
|
"img",
|
|
217
230
|
{
|
|
218
231
|
src: e.preview,
|
|
219
232
|
alt: e.file.name,
|
|
220
233
|
className: "h-full w-full rounded object-cover"
|
|
221
234
|
}
|
|
222
|
-
) : /* @__PURE__ */
|
|
223
|
-
|
|
235
|
+
) : /* @__PURE__ */ i(
|
|
236
|
+
M,
|
|
224
237
|
{
|
|
225
|
-
name:
|
|
238
|
+
name: a(e.file.type ?? ""),
|
|
226
239
|
className: "h-5 w-5 text-[var(--color-text-secondary)]"
|
|
227
240
|
}
|
|
228
241
|
)
|
|
229
242
|
}
|
|
230
243
|
);
|
|
231
244
|
});
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
/* @__PURE__ */
|
|
235
|
-
/* @__PURE__ */
|
|
236
|
-
/* @__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 })
|
|
237
250
|
] }),
|
|
238
|
-
/* @__PURE__ */
|
|
239
|
-
e.error && /* @__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 })
|
|
240
253
|
] }) }));
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
/* @__PURE__ */
|
|
244
|
-
/* @__PURE__ */
|
|
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: [
|
|
245
258
|
Math.round(e.progress),
|
|
246
259
|
"%"
|
|
247
260
|
] })
|
|
248
261
|
] }));
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
const { files: t, onFilesChange:
|
|
252
|
-
return /* @__PURE__ */
|
|
253
|
-
|
|
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,
|
|
254
267
|
{
|
|
255
268
|
ref: o,
|
|
256
269
|
variant: "ghost",
|
|
257
270
|
size: "s",
|
|
258
271
|
onClick: async () => {
|
|
259
|
-
if (
|
|
272
|
+
if (n)
|
|
260
273
|
try {
|
|
261
|
-
await
|
|
274
|
+
await n(r);
|
|
262
275
|
} catch {
|
|
263
276
|
return;
|
|
264
277
|
}
|
|
265
|
-
const
|
|
266
|
-
|
|
278
|
+
const m = t.filter((c) => c.id !== r.id);
|
|
279
|
+
a(m);
|
|
267
280
|
},
|
|
268
281
|
"aria-label": `Remove ${r.file.name}`,
|
|
269
282
|
...e,
|
|
270
|
-
children: /* @__PURE__ */
|
|
283
|
+
children: /* @__PURE__ */ i(M, { name: re, className: "h-4 w-4" })
|
|
271
284
|
}
|
|
272
285
|
);
|
|
273
286
|
});
|
|
274
|
-
|
|
275
|
-
const
|
|
287
|
+
O.displayName = "FileUploadItemDelete";
|
|
288
|
+
const S = (r) => {
|
|
276
289
|
if (r === 0) return "0 Bytes";
|
|
277
290
|
const e = 1024, o = ["Bytes", "KB", "MB", "GB"], t = Math.floor(Math.log(r) / Math.log(e));
|
|
278
291
|
return parseFloat((r / Math.pow(e, t)).toFixed(2)) + " " + o[t];
|
|
279
|
-
},
|
|
280
|
-
Root:
|
|
281
|
-
Dropzone:
|
|
282
|
-
Trigger:
|
|
283
|
-
List:
|
|
284
|
-
Item:
|
|
285
|
-
ItemPreview:
|
|
286
|
-
ItemMetadata:
|
|
287
|
-
ItemProgress:
|
|
288
|
-
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
|
|
289
302
|
};
|
|
290
303
|
export {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
|
303
316
|
};
|