@beautinique/frontend-components 1.0.4 → 1.0.6
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/README.md +67 -25
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/toast/ToastContainer.d.cts +5 -3
- package/dist/toast/ToastContainer.d.cts.map +1 -1
- package/dist/toast/ToastContainer.d.ts +5 -3
- package/dist/toast/ToastContainer.d.ts.map +1 -1
- package/dist/toast/index.cjs +155 -184
- package/dist/toast/index.cjs.map +1 -1
- package/dist/toast/index.d.cts +2 -3
- package/dist/toast/index.d.cts.map +1 -1
- package/dist/toast/index.d.ts +2 -3
- package/dist/toast/index.d.ts.map +1 -1
- package/dist/toast/index.js +155 -179
- package/dist/toast/index.js.map +1 -1
- package/dist/toast/toaster.d.cts +62 -3
- package/dist/toast/toaster.d.cts.map +1 -1
- package/dist/toast/toaster.d.ts +62 -3
- package/dist/toast/toaster.d.ts.map +1 -1
- package/dist/toast/types.d.cts +8 -8
- package/dist/toast/types.d.cts.map +1 -1
- package/dist/toast/types.d.ts +8 -8
- package/dist/toast/types.d.ts.map +1 -1
- package/dist/toast/uploads.d.cts +21 -30
- package/dist/toast/uploads.d.cts.map +1 -1
- package/dist/toast/uploads.d.ts +21 -30
- package/dist/toast/uploads.d.ts.map +1 -1
- package/package.json +3 -5
- package/dist/toast/toast.store.d.cts +0 -4
- package/dist/toast/toast.store.d.cts.map +0 -1
- package/dist/toast/toast.store.d.ts +0 -4
- package/dist/toast/toast.store.d.ts.map +0 -1
package/dist/toast/index.js
CHANGED
|
@@ -1,56 +1,9 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
|
-
import { create } from 'zustand';
|
|
3
1
|
import { addCollection, Icon } from '@iconify/react';
|
|
4
2
|
import { memo, useState, useRef, useCallback, useEffect } from 'react';
|
|
5
3
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
4
|
|
|
7
5
|
var __defProp = Object.defineProperty;
|
|
8
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
|
|
10
|
-
// src/lib/constants.ts
|
|
11
|
-
var TOAST_TYPES = [
|
|
12
|
-
"success",
|
|
13
|
-
"error",
|
|
14
|
-
"warning",
|
|
15
|
-
"progress",
|
|
16
|
-
"uploads",
|
|
17
|
-
"loading",
|
|
18
|
-
"default",
|
|
19
|
-
"custom"
|
|
20
|
-
];
|
|
21
|
-
var TOAST_TYPE = Object.fromEntries(TOAST_TYPES.map((type) => [type, type]));
|
|
22
|
-
|
|
23
|
-
// src/toast/toast.store.ts
|
|
24
|
-
var useToastStore = create((set) => ({
|
|
25
|
-
toasts: [],
|
|
26
|
-
add: /* @__PURE__ */ __name((toast) => {
|
|
27
|
-
const id = nanoid();
|
|
28
|
-
set((state) => ({ toasts: [...state.toasts, { ...toast, id }] }));
|
|
29
|
-
return id;
|
|
30
|
-
}, "add"),
|
|
31
|
-
update: {
|
|
32
|
-
progress: /* @__PURE__ */ __name((id, progress) => {
|
|
33
|
-
set((state) => ({
|
|
34
|
-
toasts: state.toasts.map((toast) => toast.id === id ? { ...toast, progress } : toast)
|
|
35
|
-
}));
|
|
36
|
-
}, "progress"),
|
|
37
|
-
uploadItem: /* @__PURE__ */ __name((id, itemId, patch) => {
|
|
38
|
-
set((state) => ({
|
|
39
|
-
toasts: state.toasts.map(
|
|
40
|
-
(toast) => toast.id === id && toast.type === TOAST_TYPE.uploads ? {
|
|
41
|
-
...toast,
|
|
42
|
-
items: toast.items.map(
|
|
43
|
-
(item) => item.id === itemId ? { ...item, ...patch } : item
|
|
44
|
-
)
|
|
45
|
-
} : toast
|
|
46
|
-
)
|
|
47
|
-
}));
|
|
48
|
-
}, "uploadItem")
|
|
49
|
-
},
|
|
50
|
-
remove: /* @__PURE__ */ __name((id) => {
|
|
51
|
-
set((state) => ({ toasts: state.toasts.filter((t) => t.id !== id) }));
|
|
52
|
-
}, "remove")
|
|
53
|
-
}));
|
|
54
7
|
var TOAST_ICON_SETS = [
|
|
55
8
|
{
|
|
56
9
|
prefix: "solar",
|
|
@@ -112,6 +65,19 @@ var TOAST_ICON_NAMES = TOAST_ICON_SETS.flatMap(
|
|
|
112
65
|
({ prefix, icons }) => Object.keys(icons).map((name) => `${prefix}:${name}`)
|
|
113
66
|
);
|
|
114
67
|
|
|
68
|
+
// src/lib/constants.ts
|
|
69
|
+
var TOAST_TYPES = [
|
|
70
|
+
"success",
|
|
71
|
+
"error",
|
|
72
|
+
"warning",
|
|
73
|
+
"progress",
|
|
74
|
+
"uploads",
|
|
75
|
+
"loading",
|
|
76
|
+
"default",
|
|
77
|
+
"custom"
|
|
78
|
+
];
|
|
79
|
+
var TOAST_TYPE = Object.fromEntries(TOAST_TYPES.map((type) => [type, type]));
|
|
80
|
+
|
|
115
81
|
// src/lib/button.ts
|
|
116
82
|
var PATTERN_CSS = {
|
|
117
83
|
primary: "text-white bg-sky-blue-burst shadow-primary-btn hover:shadow-primary-btn-hover",
|
|
@@ -149,52 +115,6 @@ var Button = /* @__PURE__ */ __name(({
|
|
|
149
115
|
)
|
|
150
116
|
), "Button");
|
|
151
117
|
|
|
152
|
-
// src/toast/toaster.ts
|
|
153
|
-
var { add, update, remove } = useToastStore.getState();
|
|
154
|
-
var toaster = {
|
|
155
|
-
success: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.success }), "success"),
|
|
156
|
-
error: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.error }), "error"),
|
|
157
|
-
warning: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.warning }), "warning"),
|
|
158
|
-
default: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.default }), "default"),
|
|
159
|
-
loading: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.loading }), "loading"),
|
|
160
|
-
custom: /* @__PURE__ */ __name((data) => add(data), "custom"),
|
|
161
|
-
progress: {
|
|
162
|
-
start: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.progress }), "start"),
|
|
163
|
-
update: /* @__PURE__ */ __name((toastId, progress) => {
|
|
164
|
-
update.progress(toastId, progress);
|
|
165
|
-
}, "update"),
|
|
166
|
-
end: /* @__PURE__ */ __name((toastId) => {
|
|
167
|
-
remove(toastId);
|
|
168
|
-
}, "end")
|
|
169
|
-
},
|
|
170
|
-
uploads: {
|
|
171
|
-
start: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.uploads }), "start"),
|
|
172
|
-
update: /* @__PURE__ */ __name((toastId, itemId, patch) => {
|
|
173
|
-
update.uploadItem(toastId, itemId, patch);
|
|
174
|
-
}, "update")
|
|
175
|
-
},
|
|
176
|
-
remove: /* @__PURE__ */ __name((toastId) => {
|
|
177
|
-
remove(toastId);
|
|
178
|
-
}, "remove")
|
|
179
|
-
};
|
|
180
|
-
var withProgressToast = /* @__PURE__ */ __name(async ({
|
|
181
|
-
title,
|
|
182
|
-
description,
|
|
183
|
-
request
|
|
184
|
-
}) => {
|
|
185
|
-
const toastId = toaster.progress.start({ title, description, progress: 0 });
|
|
186
|
-
try {
|
|
187
|
-
const response = await request((event) => {
|
|
188
|
-
if (!event.total) return;
|
|
189
|
-
toaster.progress.update(toastId, Math.round(event.loaded * 100 / event.total));
|
|
190
|
-
});
|
|
191
|
-
toaster.progress.update(toastId, 100);
|
|
192
|
-
return response;
|
|
193
|
-
} finally {
|
|
194
|
-
toaster.progress.end(toastId);
|
|
195
|
-
}
|
|
196
|
-
}, "withProgressToast");
|
|
197
|
-
|
|
198
118
|
// src/toast/uploads.ts
|
|
199
119
|
var sum = /* @__PURE__ */ __name((numbers) => numbers.reduce((total, value) => total + value, 0), "sum");
|
|
200
120
|
var isUploadItemSettled = /* @__PURE__ */ __name(({ status }) => status === "success" || status === "error", "isUploadItemSettled");
|
|
@@ -244,92 +164,95 @@ var getUploadsSummary = /* @__PURE__ */ __name((items) => {
|
|
|
244
164
|
};
|
|
245
165
|
}, "getUploadsSummary");
|
|
246
166
|
var getFormDataFiles = /* @__PURE__ */ __name((data, key = "files") => data.getAll(key).filter((value) => value instanceof File), "getFormDataFiles");
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
description,
|
|
250
|
-
items
|
|
251
|
-
}) => {
|
|
252
|
-
if (items.length === 0) return void 0;
|
|
253
|
-
const statuses = new Map(items.map(({ id }) => [id, "pending"]));
|
|
254
|
-
const toastId = toaster.uploads.start({
|
|
167
|
+
var createUploadsHelpers = /* @__PURE__ */ __name((toaster) => {
|
|
168
|
+
const createUploadsToast = /* @__PURE__ */ __name(({
|
|
255
169
|
title,
|
|
256
170
|
description,
|
|
257
|
-
items
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
171
|
+
items
|
|
172
|
+
}) => {
|
|
173
|
+
if (items.length === 0) return void 0;
|
|
174
|
+
const statuses = new Map(items.map(({ id }) => [id, "pending"]));
|
|
175
|
+
const toastId = toaster.uploads.start({
|
|
176
|
+
title,
|
|
177
|
+
description,
|
|
178
|
+
items: items.map(({ id, label, files }) => {
|
|
179
|
+
const fileSizes = files.map(({ size }) => size);
|
|
180
|
+
return { id, label, status: "pending", loaded: 0, total: sum(fileSizes), fileSizes };
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
const patch = /* @__PURE__ */ __name((id, changes) => {
|
|
184
|
+
if (changes.status) statuses.set(id, changes.status);
|
|
185
|
+
toaster.uploads.update(toastId, id, changes);
|
|
186
|
+
}, "patch");
|
|
187
|
+
return {
|
|
188
|
+
item: /* @__PURE__ */ __name((id) => ({
|
|
189
|
+
run: /* @__PURE__ */ __name(async (request) => {
|
|
190
|
+
patch(id, { status: "uploading" });
|
|
191
|
+
try {
|
|
192
|
+
const result = await request((event) => {
|
|
193
|
+
if (!event.total) return;
|
|
194
|
+
patch(id, { loaded: event.loaded, total: event.total });
|
|
195
|
+
});
|
|
196
|
+
patch(id, { status: "success" });
|
|
197
|
+
return result;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
patch(id, { status: "error" });
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}, "run")
|
|
203
|
+
}), "item"),
|
|
204
|
+
end: /* @__PURE__ */ __name(() => {
|
|
205
|
+
for (const [id, status] of statuses) {
|
|
206
|
+
if (status === "pending" || status === "uploading") patch(id, { status: "error" });
|
|
280
207
|
}
|
|
281
|
-
}, "
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (status === "pending" || status === "uploading") patch(id, { status: "error" });
|
|
286
|
-
}
|
|
287
|
-
}, "end")
|
|
288
|
-
};
|
|
289
|
-
}, "createUploadsToast");
|
|
290
|
-
var withUploadsToast = /* @__PURE__ */ __name(async ({
|
|
291
|
-
title,
|
|
292
|
-
description,
|
|
293
|
-
files,
|
|
294
|
-
request
|
|
295
|
-
}) => {
|
|
296
|
-
const group = createUploadsToast({
|
|
208
|
+
}, "end")
|
|
209
|
+
};
|
|
210
|
+
}, "createUploadsToast");
|
|
211
|
+
const withUploadsToast = /* @__PURE__ */ __name(async ({
|
|
297
212
|
title,
|
|
298
213
|
description,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
})
|
|
314
|
-
const
|
|
214
|
+
files,
|
|
215
|
+
request
|
|
216
|
+
}) => {
|
|
217
|
+
const group = createUploadsToast({
|
|
218
|
+
title,
|
|
219
|
+
description,
|
|
220
|
+
items: files.length > 0 ? [{ id: "files", label: description ?? title, files }] : []
|
|
221
|
+
});
|
|
222
|
+
if (!group) return request(() => void 0);
|
|
223
|
+
try {
|
|
224
|
+
return await group.item("files").run(request);
|
|
225
|
+
} finally {
|
|
226
|
+
group.end();
|
|
227
|
+
}
|
|
228
|
+
}, "withUploadsToast");
|
|
229
|
+
const runUploadsInToast = /* @__PURE__ */ __name(async ({
|
|
315
230
|
title,
|
|
316
231
|
description,
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
232
|
+
uploads,
|
|
233
|
+
run
|
|
234
|
+
}) => {
|
|
235
|
+
const group = createUploadsToast({
|
|
236
|
+
title,
|
|
237
|
+
description,
|
|
238
|
+
items: uploads.filter(({ files }) => files.length > 0)
|
|
239
|
+
});
|
|
240
|
+
const settled = await Promise.allSettled(uploads.map(({ id }) => run(id, group?.item(id))));
|
|
241
|
+
group?.end();
|
|
242
|
+
const results = {};
|
|
243
|
+
settled.forEach((result, index) => {
|
|
244
|
+
if (result.status === "fulfilled") results[uploads[index].id] = result.value;
|
|
245
|
+
});
|
|
246
|
+
const failure = settled.find(
|
|
247
|
+
(result) => result.status === "rejected"
|
|
248
|
+
);
|
|
249
|
+
if (failure) {
|
|
250
|
+
throw failure.reason instanceof Error ? failure.reason : new Error("Upload failed");
|
|
251
|
+
}
|
|
252
|
+
return results;
|
|
253
|
+
}, "runUploadsInToast");
|
|
254
|
+
return { createUploadsToast, withUploadsToast, runUploadsInToast };
|
|
255
|
+
}, "createUploadsHelpers");
|
|
333
256
|
registerToastIcons();
|
|
334
257
|
var CircularProgress = /* @__PURE__ */ __name(({ progress, ...props }) => {
|
|
335
258
|
const radius = 10;
|
|
@@ -476,9 +399,9 @@ var ToasterItem = /* @__PURE__ */ __name((props) => {
|
|
|
476
399
|
buttonProps,
|
|
477
400
|
isClosable = true,
|
|
478
401
|
autoClose = true,
|
|
479
|
-
closeTimer = 5e3
|
|
402
|
+
closeTimer = 5e3,
|
|
403
|
+
onRemove
|
|
480
404
|
} = props;
|
|
481
|
-
const remove2 = useToastStore((s) => s.remove);
|
|
482
405
|
const [visible, setVisible] = useState(false);
|
|
483
406
|
const [mounted, setMounted] = useState(true);
|
|
484
407
|
const timeoutRef = useRef(null);
|
|
@@ -500,9 +423,9 @@ var ToasterItem = /* @__PURE__ */ __name((props) => {
|
|
|
500
423
|
setVisible(false);
|
|
501
424
|
timeoutRef.current = setTimeout(() => {
|
|
502
425
|
setMounted(false);
|
|
503
|
-
|
|
426
|
+
onRemove?.(props.id);
|
|
504
427
|
}, 300);
|
|
505
|
-
}, [
|
|
428
|
+
}, [onRemove, props.id]);
|
|
506
429
|
useEffect(() => {
|
|
507
430
|
const enterTimer = setTimeout(() => {
|
|
508
431
|
setVisible(true);
|
|
@@ -588,12 +511,65 @@ var ToasterItem = /* @__PURE__ */ __name((props) => {
|
|
|
588
511
|
);
|
|
589
512
|
}, "ToasterItem");
|
|
590
513
|
var Toaster = memo(ToasterItem);
|
|
591
|
-
var ToastContainer = /* @__PURE__ */ __name(() => {
|
|
514
|
+
var ToastContainer = /* @__PURE__ */ __name(({ store: useToastStore }) => {
|
|
592
515
|
const toasts = useToastStore((s) => s.toasts);
|
|
516
|
+
const remove = useToastStore((s) => s.remove);
|
|
593
517
|
if (toasts.length === 0) return null;
|
|
594
|
-
return /* @__PURE__ */ jsx("div", { className: "base:max-w-sm fixed right-2 bottom-2 z-999 flex w-full max-w-xs flex-col gap-2 sm:max-w-md md:right-4 md:bottom-4 md:max-w-lg lg:right-8 lg:bottom-8 lg:max-w-xl", children: toasts.map((toast) => /* @__PURE__ */ jsx(Toaster, { ...toast, id: toast.id }, toast.id)) });
|
|
518
|
+
return /* @__PURE__ */ jsx("div", { className: "base:max-w-sm fixed right-2 bottom-2 z-999 flex w-full max-w-xs flex-col gap-2 sm:max-w-md md:right-4 md:bottom-4 md:max-w-lg lg:right-8 lg:bottom-8 lg:max-w-xl", children: toasts.map((toast) => /* @__PURE__ */ jsx(Toaster, { ...toast, id: toast.id, onRemove: remove }, toast.id)) });
|
|
595
519
|
}, "ToastContainer");
|
|
596
520
|
|
|
597
|
-
|
|
521
|
+
// src/toast/toaster.ts
|
|
522
|
+
var createToasterApi = /* @__PURE__ */ __name((store) => {
|
|
523
|
+
const { add, update, remove } = store.getState();
|
|
524
|
+
return {
|
|
525
|
+
success: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.success }), "success"),
|
|
526
|
+
error: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.error }), "error"),
|
|
527
|
+
warning: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.warning }), "warning"),
|
|
528
|
+
default: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.default }), "default"),
|
|
529
|
+
loading: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.loading }), "loading"),
|
|
530
|
+
custom: /* @__PURE__ */ __name((data) => add(data), "custom"),
|
|
531
|
+
progress: {
|
|
532
|
+
start: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.progress }), "start"),
|
|
533
|
+
update: /* @__PURE__ */ __name((toastId, progress) => {
|
|
534
|
+
update.progress(toastId, progress);
|
|
535
|
+
}, "update"),
|
|
536
|
+
end: /* @__PURE__ */ __name((toastId) => {
|
|
537
|
+
remove(toastId);
|
|
538
|
+
}, "end")
|
|
539
|
+
},
|
|
540
|
+
uploads: {
|
|
541
|
+
start: /* @__PURE__ */ __name((data) => add({ ...data, type: TOAST_TYPE.uploads }), "start"),
|
|
542
|
+
update: /* @__PURE__ */ __name((toastId, itemId, patch) => {
|
|
543
|
+
update.uploadItem(toastId, itemId, patch);
|
|
544
|
+
}, "update")
|
|
545
|
+
},
|
|
546
|
+
remove: /* @__PURE__ */ __name((toastId) => {
|
|
547
|
+
remove(toastId);
|
|
548
|
+
}, "remove")
|
|
549
|
+
};
|
|
550
|
+
}, "createToasterApi");
|
|
551
|
+
var createToaster = /* @__PURE__ */ __name((store) => {
|
|
552
|
+
const toaster = createToasterApi(store);
|
|
553
|
+
const withProgressToast = /* @__PURE__ */ __name(async ({
|
|
554
|
+
title,
|
|
555
|
+
description,
|
|
556
|
+
request
|
|
557
|
+
}) => {
|
|
558
|
+
const toastId = toaster.progress.start({ title, description, progress: 0 });
|
|
559
|
+
try {
|
|
560
|
+
const response = await request((event) => {
|
|
561
|
+
if (!event.total) return;
|
|
562
|
+
toaster.progress.update(toastId, Math.round(event.loaded * 100 / event.total));
|
|
563
|
+
});
|
|
564
|
+
toaster.progress.update(toastId, 100);
|
|
565
|
+
return response;
|
|
566
|
+
} finally {
|
|
567
|
+
toaster.progress.end(toastId);
|
|
568
|
+
}
|
|
569
|
+
}, "withProgressToast");
|
|
570
|
+
return { toaster, withProgressToast, ...createUploadsHelpers(toaster) };
|
|
571
|
+
}, "createToaster");
|
|
572
|
+
|
|
573
|
+
export { TOAST_ICON_NAMES, ToastContainer, Toaster, createToaster, getFormDataFiles, getUploadItemFilesDone, getUploadItemPercent, getUploadsSummary, isUploadItemSettled };
|
|
598
574
|
//# sourceMappingURL=index.js.map
|
|
599
575
|
//# sourceMappingURL=index.js.map
|