@jobber/components 6.118.2 → 6.118.3-CLEANUPfi-067b29f.2

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.
@@ -18,9 +18,11 @@ interface ActionToastProps extends BaseToastProps {
18
18
  actionLabel: string;
19
19
  }
20
20
  export type ToastProps = XOR<BaseToastProps, ActionToastProps>;
21
- type ToastPropsInternal = Omit<ToastProps, "id">;
21
+ interface ToastPropsInternal extends Omit<ToastProps, "id"> {
22
+ readonly onHide?: () => void;
23
+ }
22
24
  export interface ToastRef {
23
25
  add(props: ToastProps): void;
24
26
  }
25
- export declare function Toast({ message, variation, action, actionLabel, }: ToastPropsInternal): React.JSX.Element;
27
+ export declare function Toast({ message, variation, action, actionLabel, onHide, }: ToastPropsInternal): React.JSX.Element;
26
28
  export {};
@@ -10,11 +10,14 @@ var Typography = require('./Typography-cjs.js');
10
10
 
11
11
  var styles = {"wrapper":"_0Tvq24WjeX8-","container":"GznHKPkdb1s-","toast":"W8zgWZqmIlk-","slice":"ol3srk7PviM-","button":"ibhpdUt9YLo-","spinning":"_5Wy5Wra20Vk-"};
12
12
 
13
- function Toast({ message, variation = "success", action, actionLabel, }) {
13
+ function Toast({ message, variation = "success", action, actionLabel, onHide, }) {
14
14
  const [visible, setVisible] = React.useState(true);
15
15
  const icon = getIcon();
16
- let timer;
17
- React.useEffect(() => startTimer(), []);
16
+ const timer = React.useRef(undefined);
17
+ React.useEffect(() => {
18
+ startTimer();
19
+ return () => stopTimer();
20
+ }, []);
18
21
  return (React.createElement(framerMotion.AnimatePresence, null, visible && (React.createElement(framerMotion.motion.div, { className: styles.toast, initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, onMouseEnter: () => stopTimer(), onMouseLeave: () => startTimer(), exit: {
19
22
  opacity: 0,
20
23
  scale: 0.8,
@@ -28,13 +31,15 @@ function Toast({ message, variation = "success", action, actionLabel, }) {
28
31
  React.createElement("div", { className: styles.button },
29
32
  React.createElement(Button.Button, { icon: "remove", ariaLabel: "Hide Notification", onClick: handleToastClose, type: "tertiary", variation: "subtle" })))))));
30
33
  function startTimer() {
31
- timer = setTimeout(() => handleToastClose(), getTimeout());
34
+ clearTimeout(timer.current);
35
+ timer.current = setTimeout(() => handleToastClose(), getTimeout());
32
36
  }
33
37
  function stopTimer() {
34
- clearTimeout(timer);
38
+ clearTimeout(timer.current);
35
39
  }
36
40
  function handleToastClose() {
37
- if (!window)
41
+ onHide === null || onHide === void 0 ? void 0 : onHide();
42
+ if (!globalThis.window)
38
43
  return;
39
44
  setVisible(false);
40
45
  }
@@ -100,7 +105,7 @@ function ToastInternal(_, ref) {
100
105
  ]);
101
106
  },
102
107
  }));
103
- return (React.createElement("div", { className: styles.container }, toasts.map(toast => (React.createElement(Toast, Object.assign({}, toast, { key: toast.id }))))));
108
+ return (React.createElement("div", { className: styles.container }, toasts.map(toast => (React.createElement(Toast, Object.assign({}, toast, { key: toast.id, onHide: () => setToasts(prev => prev.filter(t => t.id !== toast.id)) }))))));
104
109
  }
105
110
 
106
111
  exports.Toast = Toast;
@@ -1,4 +1,4 @@
1
- import React__default, { useState, useEffect, forwardRef, useImperativeHandle, useRef } from 'react';
1
+ import React__default, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import { AnimatePresence, motion } from 'framer-motion';
4
4
  import { I as Icon } from './Icon-es.js';
@@ -8,11 +8,14 @@ import { T as Typography } from './Typography-es.js';
8
8
 
9
9
  var styles = {"wrapper":"_0Tvq24WjeX8-","container":"GznHKPkdb1s-","toast":"W8zgWZqmIlk-","slice":"ol3srk7PviM-","button":"ibhpdUt9YLo-","spinning":"_5Wy5Wra20Vk-"};
10
10
 
11
- function Toast({ message, variation = "success", action, actionLabel, }) {
11
+ function Toast({ message, variation = "success", action, actionLabel, onHide, }) {
12
12
  const [visible, setVisible] = useState(true);
13
13
  const icon = getIcon();
14
- let timer;
15
- useEffect(() => startTimer(), []);
14
+ const timer = useRef(undefined);
15
+ useEffect(() => {
16
+ startTimer();
17
+ return () => stopTimer();
18
+ }, []);
16
19
  return (React__default.createElement(AnimatePresence, null, visible && (React__default.createElement(motion.div, { className: styles.toast, initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, onMouseEnter: () => stopTimer(), onMouseLeave: () => startTimer(), exit: {
17
20
  opacity: 0,
18
21
  scale: 0.8,
@@ -26,13 +29,15 @@ function Toast({ message, variation = "success", action, actionLabel, }) {
26
29
  React__default.createElement("div", { className: styles.button },
27
30
  React__default.createElement(Button, { icon: "remove", ariaLabel: "Hide Notification", onClick: handleToastClose, type: "tertiary", variation: "subtle" })))))));
28
31
  function startTimer() {
29
- timer = setTimeout(() => handleToastClose(), getTimeout());
32
+ clearTimeout(timer.current);
33
+ timer.current = setTimeout(() => handleToastClose(), getTimeout());
30
34
  }
31
35
  function stopTimer() {
32
- clearTimeout(timer);
36
+ clearTimeout(timer.current);
33
37
  }
34
38
  function handleToastClose() {
35
- if (!window)
39
+ onHide === null || onHide === void 0 ? void 0 : onHide();
40
+ if (!globalThis.window)
36
41
  return;
37
42
  setVisible(false);
38
43
  }
@@ -98,7 +103,7 @@ function ToastInternal(_, ref) {
98
103
  ]);
99
104
  },
100
105
  }));
101
- return (React__default.createElement("div", { className: styles.container }, toasts.map(toast => (React__default.createElement(Toast, Object.assign({}, toast, { key: toast.id }))))));
106
+ return (React__default.createElement("div", { className: styles.container }, toasts.map(toast => (React__default.createElement(Toast, Object.assign({}, toast, { key: toast.id, onHide: () => setToasts(prev => prev.filter(t => t.id !== toast.id)) }))))));
102
107
  }
103
108
 
104
109
  export { Toast as T, showToast as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "6.118.2",
3
+ "version": "6.118.3-CLEANUPfi-067b29f.2+067b29fdf",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -541,5 +541,5 @@
541
541
  "> 1%",
542
542
  "IE 10"
543
543
  ],
544
- "gitHead": "77bb214822ff1ca35fb32915961d0a7151b23d8c"
544
+ "gitHead": "067b29fdfdc6d727a0d32d0bb9af6f7aef455325"
545
545
  }