kitzo 2.0.6 → 2.0.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/dist/react.esm.js +35 -19
- package/package.json +1 -1
package/dist/react.esm.js
CHANGED
|
@@ -328,26 +328,23 @@ function Toast({
|
|
|
328
328
|
const ref = useRef(null);
|
|
329
329
|
useLayoutEffect(() => {
|
|
330
330
|
if (!ref.current) return;
|
|
331
|
-
const
|
|
331
|
+
const height = ref.current.getBoundingClientRect().height;
|
|
332
332
|
setToasts(prev => {
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
333
|
+
const index = prev.findIndex(t => t.options.id === toast.options.id);
|
|
334
|
+
if (index === -1) return prev;
|
|
335
335
|
const newToasts = [...prev];
|
|
336
|
-
newToasts[
|
|
337
|
-
...newToasts[
|
|
338
|
-
height
|
|
336
|
+
newToasts[index] = {
|
|
337
|
+
...newToasts[index],
|
|
338
|
+
height
|
|
339
339
|
};
|
|
340
340
|
let offset = 0;
|
|
341
|
-
for (let
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
offset
|
|
345
|
-
};
|
|
346
|
-
offset += newToasts[i].height + GAP;
|
|
341
|
+
for (let t of newToasts) {
|
|
342
|
+
t.offset = offset;
|
|
343
|
+
offset += (t.height || 0) + GAP;
|
|
347
344
|
}
|
|
348
345
|
return newToasts;
|
|
349
346
|
});
|
|
350
|
-
}, [setToasts, toast.id]);
|
|
347
|
+
}, [setToasts, toast.options.id]);
|
|
351
348
|
const transformY = position.includes('bottom') ? `translateY(-${toast.offset || 0}px)` : `translateY(${toast.offset || 0}px)`;
|
|
352
349
|
return /*#__PURE__*/React.createElement("div", {
|
|
353
350
|
ref: ref,
|
|
@@ -389,10 +386,12 @@ function ToastContainer(props) {
|
|
|
389
386
|
position
|
|
390
387
|
} = props;
|
|
391
388
|
const [toasts, setToasts] = useState([]);
|
|
389
|
+
const timeouts = useRef(new Set());
|
|
392
390
|
useEffect(() => {
|
|
393
391
|
const unsub = subscribe(toast => {
|
|
394
392
|
const duration = toast.options.duration;
|
|
395
393
|
const id = toast.options.id;
|
|
394
|
+
console.log(toast);
|
|
396
395
|
setToasts(prev => {
|
|
397
396
|
const exists = prev.some(t => t.options.id === id);
|
|
398
397
|
if (exists) {
|
|
@@ -409,19 +408,36 @@ function ToastContainer(props) {
|
|
|
409
408
|
}, ...prev];
|
|
410
409
|
});
|
|
411
410
|
if (toast.type !== 'loading') {
|
|
412
|
-
setTimeout(() => {
|
|
411
|
+
const exit = setTimeout(() => {
|
|
413
412
|
setToasts(prev => prev.map(t => t.options.id === id ? {
|
|
414
413
|
...t,
|
|
415
414
|
leaving: true
|
|
416
415
|
} : t));
|
|
417
416
|
}, Math.max(0, duration - 300));
|
|
418
|
-
setTimeout(() => {
|
|
417
|
+
const remove = setTimeout(() => {
|
|
419
418
|
setToasts(prev => prev.filter(t => t.options.id !== id));
|
|
420
419
|
}, duration);
|
|
420
|
+
timeouts.current.add(exit);
|
|
421
|
+
timeouts.current.add(remove);
|
|
421
422
|
}
|
|
422
423
|
});
|
|
423
|
-
return () =>
|
|
424
|
+
return () => {
|
|
425
|
+
unsub();
|
|
426
|
+
timeouts.current.forEach(clearTimeout);
|
|
427
|
+
timeouts.current.clear();
|
|
428
|
+
};
|
|
424
429
|
}, []);
|
|
430
|
+
useEffect(() => {
|
|
431
|
+
let offset = 0;
|
|
432
|
+
setToasts(prev => prev.map(t => {
|
|
433
|
+
const newToast = {
|
|
434
|
+
...t,
|
|
435
|
+
offset
|
|
436
|
+
};
|
|
437
|
+
offset += (t.height || 0) + 10;
|
|
438
|
+
return newToast;
|
|
439
|
+
}));
|
|
440
|
+
}, [toasts.map(t => t.height).join(',')]);
|
|
425
441
|
return /*#__PURE__*/React.createElement("div", {
|
|
426
442
|
style: {
|
|
427
443
|
position: 'fixed',
|
|
@@ -431,9 +447,9 @@ function ToastContainer(props) {
|
|
|
431
447
|
fontFamily: 'inherit',
|
|
432
448
|
padding: '1rem'
|
|
433
449
|
}
|
|
434
|
-
}, toasts.map(
|
|
435
|
-
key:
|
|
436
|
-
toast:
|
|
450
|
+
}, toasts.map(toast => /*#__PURE__*/React.createElement(Toast, {
|
|
451
|
+
key: toast.options.id,
|
|
452
|
+
toast: toast,
|
|
437
453
|
setToasts: setToasts,
|
|
438
454
|
position: position
|
|
439
455
|
})));
|