kitzo 2.0.4 → 2.0.5
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 +1 -1
- package/dist/react.esm.js +26 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm i kitzo
|
|
|
25
25
|
or
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
|
-
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.
|
|
28
|
+
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.5/dist/kitzo.umd.min.js"></script>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
> Attach this script tag in the html head tag and you are good to go.
|
package/dist/react.esm.js
CHANGED
|
@@ -319,6 +319,7 @@ function LoadingSvg() {
|
|
|
319
319
|
})));
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
const GAP = 10;
|
|
322
323
|
function Toast({
|
|
323
324
|
toast,
|
|
324
325
|
setToasts,
|
|
@@ -328,32 +329,35 @@ function Toast({
|
|
|
328
329
|
useLayoutEffect(() => {
|
|
329
330
|
if (!ref.current) return;
|
|
330
331
|
const h = ref.current.getBoundingClientRect().height;
|
|
331
|
-
setToasts(prev =>
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
332
|
+
setToasts(prev => {
|
|
333
|
+
const idx = prev.findIndex(t => t.options.id === toast.id);
|
|
334
|
+
if (idx === -1) return prev;
|
|
335
|
+
const newToasts = [...prev];
|
|
336
|
+
newToasts[idx] = {
|
|
337
|
+
...newToasts[idx],
|
|
338
|
+
height: h
|
|
339
|
+
};
|
|
340
|
+
let offset = 0;
|
|
341
|
+
for (let i = 0; i < newToasts.length; i++) {
|
|
342
|
+
newToasts[i] = {
|
|
343
|
+
...newToasts[i],
|
|
344
|
+
offset
|
|
345
|
+
};
|
|
346
|
+
offset += newToasts[i].height + GAP;
|
|
343
347
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
+
return newToasts;
|
|
349
|
+
});
|
|
350
|
+
}, [setToasts, toast.id]);
|
|
351
|
+
const transformY = position.includes('bottom') ? `translateY(-${toast.offset || 0}px)` : `translateY(${toast.offset || 0}px)`;
|
|
348
352
|
return /*#__PURE__*/React.createElement("div", {
|
|
349
353
|
ref: ref,
|
|
350
354
|
className: "toast",
|
|
351
355
|
style: {
|
|
352
|
-
transform:
|
|
356
|
+
transform: transformY,
|
|
353
357
|
...getToastPosition(position)
|
|
354
358
|
}
|
|
355
359
|
}, /*#__PURE__*/React.createElement("div", {
|
|
356
|
-
className: `toast-content ${toast.leaving ? 'exit' : ''}`
|
|
360
|
+
className: `toast-content${position.includes('bottom') ? '-bottom' : ''} ${toast.leaving ? 'exit' : ''}`
|
|
357
361
|
}, toast.type === 'loading' && /*#__PURE__*/React.createElement(LoadingSvg, null), toast.type === 'success' && /*#__PURE__*/React.createElement(SuccessSvg, null), toast.type === 'error' && /*#__PURE__*/React.createElement(ErrorSvg, null), /*#__PURE__*/React.createElement("span", null, toast.text)));
|
|
358
362
|
}
|
|
359
363
|
function getToastPosition(position) {
|
|
@@ -386,10 +390,10 @@ function ToastContainer(props) {
|
|
|
386
390
|
} = props;
|
|
387
391
|
const [toasts, setToasts] = useState([]);
|
|
388
392
|
useEffect(() => {
|
|
389
|
-
const timeouts = new Set();
|
|
390
393
|
const unsub = subscribe(toast => {
|
|
391
394
|
const duration = toast.options.duration;
|
|
392
395
|
const id = toast.options.id;
|
|
396
|
+
console.log(id);
|
|
393
397
|
setToasts(prev => {
|
|
394
398
|
const exists = prev.some(t => t.options.id === id);
|
|
395
399
|
if (exists) {
|
|
@@ -406,24 +410,18 @@ function ToastContainer(props) {
|
|
|
406
410
|
}, ...prev];
|
|
407
411
|
});
|
|
408
412
|
if (toast.type !== 'loading') {
|
|
409
|
-
|
|
413
|
+
setTimeout(() => {
|
|
410
414
|
setToasts(prev => prev.map(t => t.options.id === id ? {
|
|
411
415
|
...t,
|
|
412
416
|
leaving: true
|
|
413
417
|
} : t));
|
|
414
418
|
}, Math.max(0, duration - 300));
|
|
415
|
-
|
|
419
|
+
setTimeout(() => {
|
|
416
420
|
setToasts(prev => prev.filter(t => t.options.id !== id));
|
|
417
421
|
}, duration);
|
|
418
|
-
timeouts.add(exit);
|
|
419
|
-
timeouts.add(remove);
|
|
420
422
|
}
|
|
421
423
|
});
|
|
422
|
-
return () =>
|
|
423
|
-
unsub();
|
|
424
|
-
timeouts.forEach(clearTimeout);
|
|
425
|
-
timeouts.clear();
|
|
426
|
-
};
|
|
424
|
+
return () => unsub();
|
|
427
425
|
}, []);
|
|
428
426
|
return /*#__PURE__*/React.createElement("div", {
|
|
429
427
|
style: {
|