kitzo 2.0.3 → 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 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.1/dist/kitzo.umd.min.js"></script>
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 => 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) {
@@ -389,6 +393,7 @@ function ToastContainer(props) {
389
393
  const unsub = subscribe(toast => {
390
394
  const duration = toast.options.duration;
391
395
  const id = toast.options.id;
396
+ console.log(id);
392
397
  setToasts(prev => {
393
398
  const exists = prev.some(t => t.options.id === id);
394
399
  if (exists) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "A lightweight JavaScript UI micro-library.",
5
5
  "type": "module",
6
6
  "main": "./dist/kitzo.umd.js",