kitzo 2.0.4 → 2.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 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.4/dist/kitzo.umd.min.js"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.6/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 => prev.map(t => t.options.id === toast.id ? t : {
332
- ...t,
333
- offset: t.offset + h + 10
334
- }));
335
- }, [setToasts, toast.id]);
336
- if (position.includes('bottom')) {
337
- return /*#__PURE__*/React.createElement("div", {
338
- ref: ref,
339
- className: "toast",
340
- style: {
341
- transform: `translateY(-${toast.offset}px)`,
342
- ...getToastPosition(position)
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
- }, /*#__PURE__*/React.createElement("div", {
345
- className: `toast-content-bottom ${toast.leaving ? 'exit' : ''}`
346
- }, 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)));
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: `translateY(${toast.offset}px)`,
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,7 +390,6 @@ 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;
@@ -406,24 +409,18 @@ function ToastContainer(props) {
406
409
  }, ...prev];
407
410
  });
408
411
  if (toast.type !== 'loading') {
409
- const exit = setTimeout(() => {
412
+ setTimeout(() => {
410
413
  setToasts(prev => prev.map(t => t.options.id === id ? {
411
414
  ...t,
412
415
  leaving: true
413
416
  } : t));
414
417
  }, Math.max(0, duration - 300));
415
- const remove = setTimeout(() => {
418
+ setTimeout(() => {
416
419
  setToasts(prev => prev.filter(t => t.options.id !== id));
417
420
  }, duration);
418
- timeouts.add(exit);
419
- timeouts.add(remove);
420
421
  }
421
422
  });
422
- return () => {
423
- unsub();
424
- timeouts.forEach(clearTimeout);
425
- timeouts.clear();
426
- };
423
+ return () => unsub();
427
424
  }, []);
428
425
  return /*#__PURE__*/React.createElement("div", {
429
426
  style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "A lightweight JavaScript UI micro-library.",
5
5
  "type": "module",
6
6
  "main": "./dist/kitzo.umd.js",