@canonical/react-components 3.4.3 → 3.5.0
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/components/Notifications/ToastNotification/ToastNotification.stories.js +29 -4
- package/dist/components/Notifications/ToastNotification/ToastNotificationProvider.d.ts +3 -0
- package/dist/components/Notifications/ToastNotification/ToastNotificationProvider.js +12 -5
- package/dist/esm/components/Notifications/ToastNotification/ToastNotification.stories.js +29 -4
- package/dist/esm/components/Notifications/ToastNotification/ToastNotificationProvider.d.ts +3 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotificationProvider.js +12 -5
- package/package.json +1 -1
|
@@ -12,21 +12,46 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
12
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
13
|
const meta = {
|
|
14
14
|
component: _index.ToastNotificationProvider,
|
|
15
|
-
tags: ["autodocs"]
|
|
15
|
+
tags: ["autodocs"],
|
|
16
|
+
argTypes: {
|
|
17
|
+
autoDismissDelay: {
|
|
18
|
+
control: {
|
|
19
|
+
type: "select"
|
|
20
|
+
},
|
|
21
|
+
options: [1000, 2000, 3000, 5000, 10000, 0],
|
|
22
|
+
labels: {
|
|
23
|
+
1000: "1 second",
|
|
24
|
+
2000: "2 seconds",
|
|
25
|
+
3000: "3 seconds",
|
|
26
|
+
5000: "5 seconds (default)",
|
|
27
|
+
10000: "10 seconds",
|
|
28
|
+
0: "Persistent (no auto-hide)"
|
|
29
|
+
},
|
|
30
|
+
description: "Delay in milliseconds before hiding notification, or 0 for persistent notifications"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
autoDismissDelay: 5000
|
|
35
|
+
}
|
|
16
36
|
};
|
|
17
37
|
var _default = exports.default = meta;
|
|
18
38
|
const Default = exports.Default = {
|
|
19
39
|
name: "Default",
|
|
20
|
-
render:
|
|
40
|
+
render: args => /*#__PURE__*/_react.default.createElement(ToastNotificationStoryWrapper, args)
|
|
21
41
|
};
|
|
22
|
-
const ToastNotificationStoryWrapper =
|
|
42
|
+
const ToastNotificationStoryWrapper = _ref => {
|
|
43
|
+
let {
|
|
44
|
+
autoDismissDelay
|
|
45
|
+
} = _ref;
|
|
23
46
|
(0, _react.useEffect)(() => {
|
|
24
47
|
const root = document.getElementById("storybook-root");
|
|
25
48
|
if (root) {
|
|
26
49
|
root.style.height = "90vh";
|
|
27
50
|
}
|
|
28
51
|
}, []);
|
|
29
|
-
return /*#__PURE__*/_react.default.createElement(_index.ToastNotificationProvider,
|
|
52
|
+
return /*#__PURE__*/_react.default.createElement(_index.ToastNotificationProvider, {
|
|
53
|
+
autoDismissDelay: autoDismissDelay
|
|
54
|
+
}, /*#__PURE__*/_react.default.createElement(PreloadedList, null));
|
|
30
55
|
};
|
|
31
56
|
const PreloadedList = () => {
|
|
32
57
|
const toastNotify = (0, _index.useToastNotification)();
|
|
@@ -8,6 +8,7 @@ export type ToastNotificationType = NotificationType & {
|
|
|
8
8
|
};
|
|
9
9
|
interface Props {
|
|
10
10
|
onDismiss?: (notifications?: ToastNotificationType[]) => void;
|
|
11
|
+
autoDismissDelay?: number;
|
|
11
12
|
}
|
|
12
13
|
interface ToastNotificationHelper {
|
|
13
14
|
notifications: ToastNotificationType[];
|
|
@@ -29,6 +30,8 @@ export type GroupedNotificationCount = {
|
|
|
29
30
|
Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
|
|
30
31
|
Notifications automatically dismiss after a delay unless manually dismissed or expanded.
|
|
31
32
|
|
|
33
|
+
To make the notification persistent (i.e., not auto-dismiss), set the `autoDismissDelay` prop to `0` when using the provider: `<ToastNotificationProvider autoDismissDelay={0}>`
|
|
34
|
+
|
|
32
35
|
| **Values** | **Description** |
|
|
33
36
|
|----------------------------------|--------------------------------------------------------------------------------|
|
|
34
37
|
| `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
|
|
@@ -44,6 +44,8 @@ const ToastNotificationContext = /*#__PURE__*/(0, _react.createContext)({
|
|
|
44
44
|
Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
|
|
45
45
|
Notifications automatically dismiss after a delay unless manually dismissed or expanded.
|
|
46
46
|
|
|
47
|
+
To make the notification persistent (i.e., not auto-dismiss), set the `autoDismissDelay` prop to `0` when using the provider: `<ToastNotificationProvider autoDismissDelay={0}>`
|
|
48
|
+
|
|
47
49
|
| **Values** | **Description** |
|
|
48
50
|
|----------------------------------|--------------------------------------------------------------------------------|
|
|
49
51
|
| `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
|
|
@@ -103,7 +105,8 @@ Alternatively, you can use the `ToastNotification` and `ToastNotificationList` c
|
|
|
103
105
|
const ToastNotificationProvider = _ref => {
|
|
104
106
|
let {
|
|
105
107
|
children,
|
|
106
|
-
onDismiss
|
|
108
|
+
onDismiss,
|
|
109
|
+
autoDismissDelay = HIDE_NOTIFICATION_DELAY
|
|
107
110
|
} = _ref;
|
|
108
111
|
const [notifications, setNotifications] = (0, _react.useState)([]);
|
|
109
112
|
const [showList, setShowList] = (0, _react.useState)(false);
|
|
@@ -112,7 +115,7 @@ const ToastNotificationProvider = _ref => {
|
|
|
112
115
|
// cleanup on timer if unmounted
|
|
113
116
|
(0, _react.useEffect)(() => {
|
|
114
117
|
return () => {
|
|
115
|
-
if (notificationTimer) {
|
|
118
|
+
if (notificationTimer && typeof notificationTimer !== "boolean") {
|
|
116
119
|
clearTimeout(notificationTimer);
|
|
117
120
|
}
|
|
118
121
|
};
|
|
@@ -120,20 +123,24 @@ const ToastNotificationProvider = _ref => {
|
|
|
120
123
|
}, []);
|
|
121
124
|
const showNotificationWithDelay = () => {
|
|
122
125
|
setNotificationTimer(prevTimer => {
|
|
123
|
-
if (prevTimer) {
|
|
126
|
+
if (prevTimer && typeof prevTimer !== "boolean") {
|
|
124
127
|
clearTimeout(prevTimer);
|
|
125
128
|
}
|
|
126
129
|
if (!showList) {
|
|
130
|
+
// If autoDismissDelay is 0, make notification persistent (no auto-hide)
|
|
131
|
+
if (!autoDismissDelay) {
|
|
132
|
+
return true; // Set a truthy value to indicate notification should show
|
|
133
|
+
}
|
|
127
134
|
return setTimeout(() => {
|
|
128
135
|
setNotificationTimer(null);
|
|
129
|
-
},
|
|
136
|
+
}, autoDismissDelay);
|
|
130
137
|
}
|
|
131
138
|
return null;
|
|
132
139
|
});
|
|
133
140
|
};
|
|
134
141
|
const clearNotificationTimer = () => {
|
|
135
142
|
setNotificationTimer(prevTimer => {
|
|
136
|
-
if (prevTimer) {
|
|
143
|
+
if (prevTimer && typeof prevTimer !== "boolean") {
|
|
137
144
|
clearTimeout(prevTimer);
|
|
138
145
|
}
|
|
139
146
|
return null;
|
|
@@ -3,21 +3,46 @@ import { ToastNotificationProvider, useToastNotification } from "./index";
|
|
|
3
3
|
import Button from "../../Button";
|
|
4
4
|
var meta = {
|
|
5
5
|
component: ToastNotificationProvider,
|
|
6
|
-
tags: ["autodocs"]
|
|
6
|
+
tags: ["autodocs"],
|
|
7
|
+
argTypes: {
|
|
8
|
+
autoDismissDelay: {
|
|
9
|
+
control: {
|
|
10
|
+
type: "select"
|
|
11
|
+
},
|
|
12
|
+
options: [1000, 2000, 3000, 5000, 10000, 0],
|
|
13
|
+
labels: {
|
|
14
|
+
1000: "1 second",
|
|
15
|
+
2000: "2 seconds",
|
|
16
|
+
3000: "3 seconds",
|
|
17
|
+
5000: "5 seconds (default)",
|
|
18
|
+
10000: "10 seconds",
|
|
19
|
+
0: "Persistent (no auto-hide)"
|
|
20
|
+
},
|
|
21
|
+
description: "Delay in milliseconds before hiding notification, or 0 for persistent notifications"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
args: {
|
|
25
|
+
autoDismissDelay: 5000
|
|
26
|
+
}
|
|
7
27
|
};
|
|
8
28
|
export default meta;
|
|
9
29
|
export var Default = {
|
|
10
30
|
name: "Default",
|
|
11
|
-
render:
|
|
31
|
+
render: args => /*#__PURE__*/React.createElement(ToastNotificationStoryWrapper, args)
|
|
12
32
|
};
|
|
13
|
-
var ToastNotificationStoryWrapper =
|
|
33
|
+
var ToastNotificationStoryWrapper = _ref => {
|
|
34
|
+
var {
|
|
35
|
+
autoDismissDelay
|
|
36
|
+
} = _ref;
|
|
14
37
|
useEffect(() => {
|
|
15
38
|
var root = document.getElementById("storybook-root");
|
|
16
39
|
if (root) {
|
|
17
40
|
root.style.height = "90vh";
|
|
18
41
|
}
|
|
19
42
|
}, []);
|
|
20
|
-
return /*#__PURE__*/React.createElement(ToastNotificationProvider,
|
|
43
|
+
return /*#__PURE__*/React.createElement(ToastNotificationProvider, {
|
|
44
|
+
autoDismissDelay: autoDismissDelay
|
|
45
|
+
}, /*#__PURE__*/React.createElement(PreloadedList, null));
|
|
21
46
|
};
|
|
22
47
|
var PreloadedList = () => {
|
|
23
48
|
var toastNotify = useToastNotification();
|
|
@@ -8,6 +8,7 @@ export type ToastNotificationType = NotificationType & {
|
|
|
8
8
|
};
|
|
9
9
|
interface Props {
|
|
10
10
|
onDismiss?: (notifications?: ToastNotificationType[]) => void;
|
|
11
|
+
autoDismissDelay?: number;
|
|
11
12
|
}
|
|
12
13
|
interface ToastNotificationHelper {
|
|
13
14
|
notifications: ToastNotificationType[];
|
|
@@ -29,6 +30,8 @@ export type GroupedNotificationCount = {
|
|
|
29
30
|
Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
|
|
30
31
|
Notifications automatically dismiss after a delay unless manually dismissed or expanded.
|
|
31
32
|
|
|
33
|
+
To make the notification persistent (i.e., not auto-dismiss), set the `autoDismissDelay` prop to `0` when using the provider: `<ToastNotificationProvider autoDismissDelay={0}>`
|
|
34
|
+
|
|
32
35
|
| **Values** | **Description** |
|
|
33
36
|
|----------------------------------|--------------------------------------------------------------------------------|
|
|
34
37
|
| `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
|
|
@@ -41,6 +41,8 @@ var ToastNotificationContext = /*#__PURE__*/createContext({
|
|
|
41
41
|
Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
|
|
42
42
|
Notifications automatically dismiss after a delay unless manually dismissed or expanded.
|
|
43
43
|
|
|
44
|
+
To make the notification persistent (i.e., not auto-dismiss), set the `autoDismissDelay` prop to `0` when using the provider: `<ToastNotificationProvider autoDismissDelay={0}>`
|
|
45
|
+
|
|
44
46
|
| **Values** | **Description** |
|
|
45
47
|
|----------------------------------|--------------------------------------------------------------------------------|
|
|
46
48
|
| `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
|
|
@@ -100,7 +102,8 @@ Alternatively, you can use the `ToastNotification` and `ToastNotificationList` c
|
|
|
100
102
|
var ToastNotificationProvider = _ref => {
|
|
101
103
|
var {
|
|
102
104
|
children,
|
|
103
|
-
onDismiss
|
|
105
|
+
onDismiss,
|
|
106
|
+
autoDismissDelay = HIDE_NOTIFICATION_DELAY
|
|
104
107
|
} = _ref;
|
|
105
108
|
var [notifications, setNotifications] = useState([]);
|
|
106
109
|
var [showList, setShowList] = useState(false);
|
|
@@ -109,7 +112,7 @@ var ToastNotificationProvider = _ref => {
|
|
|
109
112
|
// cleanup on timer if unmounted
|
|
110
113
|
useEffect(() => {
|
|
111
114
|
return () => {
|
|
112
|
-
if (notificationTimer) {
|
|
115
|
+
if (notificationTimer && typeof notificationTimer !== "boolean") {
|
|
113
116
|
clearTimeout(notificationTimer);
|
|
114
117
|
}
|
|
115
118
|
};
|
|
@@ -117,20 +120,24 @@ var ToastNotificationProvider = _ref => {
|
|
|
117
120
|
}, []);
|
|
118
121
|
var showNotificationWithDelay = () => {
|
|
119
122
|
setNotificationTimer(prevTimer => {
|
|
120
|
-
if (prevTimer) {
|
|
123
|
+
if (prevTimer && typeof prevTimer !== "boolean") {
|
|
121
124
|
clearTimeout(prevTimer);
|
|
122
125
|
}
|
|
123
126
|
if (!showList) {
|
|
127
|
+
// If autoDismissDelay is 0, make notification persistent (no auto-hide)
|
|
128
|
+
if (!autoDismissDelay) {
|
|
129
|
+
return true; // Set a truthy value to indicate notification should show
|
|
130
|
+
}
|
|
124
131
|
return setTimeout(() => {
|
|
125
132
|
setNotificationTimer(null);
|
|
126
|
-
},
|
|
133
|
+
}, autoDismissDelay);
|
|
127
134
|
}
|
|
128
135
|
return null;
|
|
129
136
|
});
|
|
130
137
|
};
|
|
131
138
|
var clearNotificationTimer = () => {
|
|
132
139
|
setNotificationTimer(prevTimer => {
|
|
133
|
-
if (prevTimer) {
|
|
140
|
+
if (prevTimer && typeof prevTimer !== "boolean") {
|
|
134
141
|
clearTimeout(prevTimer);
|
|
135
142
|
}
|
|
136
143
|
return null;
|