@canonical/react-components 2.2.3 → 2.3.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/NotificationProvider/NotificationProvider.js +3 -2
- package/dist/components/NotificationProvider/messageBuilder.js +4 -4
- package/dist/components/NotificationProvider/types.d.ts +1 -1
- package/dist/components/{Notification → Notifications/Notification}/Notification.d.ts +1 -1
- package/dist/components/{Notification → Notifications/Notification}/Notification.js +2 -2
- package/dist/components/Notifications/ToastNotification/Animate.d.ts +11 -0
- package/dist/components/Notifications/ToastNotification/Animate.js +58 -0
- package/dist/components/Notifications/ToastNotification/Toast.scss +116 -0
- package/dist/components/Notifications/ToastNotification/ToastNotification.d.ts +10 -0
- package/dist/components/Notifications/ToastNotification/ToastNotification.js +63 -0
- package/dist/components/Notifications/ToastNotification/ToastNotification.stories.d.ts +6 -0
- package/dist/components/Notifications/ToastNotification/ToastNotification.stories.js +63 -0
- package/dist/components/Notifications/ToastNotification/ToastNotificationList.d.ts +21 -0
- package/dist/components/Notifications/ToastNotification/ToastNotificationList.js +215 -0
- package/dist/components/Notifications/ToastNotification/ToastNotificationProvider.d.ts +74 -0
- package/dist/components/Notifications/ToastNotification/ToastNotificationProvider.js +206 -0
- package/dist/components/Notifications/ToastNotification/index.d.ts +5 -0
- package/dist/components/Notifications/ToastNotification/index.js +35 -0
- package/dist/components/Notifications/index.d.ts +4 -0
- package/dist/components/Notifications/index.js +45 -0
- package/dist/components/Slider/Slider.js +1 -0
- package/dist/esm/components/NotificationProvider/NotificationProvider.js +2 -1
- package/dist/esm/components/NotificationProvider/messageBuilder.js +1 -1
- package/dist/esm/components/NotificationProvider/types.d.ts +1 -1
- package/dist/esm/components/{Notification → Notifications/Notification}/Notification.d.ts +1 -1
- package/dist/esm/components/{Notification → Notifications/Notification}/Notification.js +2 -2
- package/dist/esm/components/Notifications/Notification/Notification.test.d.ts +1 -0
- package/dist/esm/components/Notifications/ToastNotification/Animate.d.ts +11 -0
- package/dist/esm/components/Notifications/ToastNotification/Animate.js +51 -0
- package/dist/esm/components/Notifications/ToastNotification/Toast.scss +116 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotification.d.ts +10 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotification.js +56 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotification.stories.d.ts +6 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotification.stories.js +54 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotification.test.d.ts +1 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotificationList.d.ts +21 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotificationList.js +208 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotificationProvider.d.ts +74 -0
- package/dist/esm/components/Notifications/ToastNotification/ToastNotificationProvider.js +201 -0
- package/dist/esm/components/Notifications/ToastNotification/index.d.ts +5 -0
- package/dist/esm/components/Notifications/ToastNotification/index.js +4 -0
- package/dist/esm/components/Notifications/index.d.ts +4 -0
- package/dist/esm/components/Notifications/index.js +2 -0
- package/dist/esm/components/Slider/Slider.js +1 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/usePrefersReducedMotion.d.ts +6 -0
- package/dist/esm/hooks/usePrefersReducedMotion.js +23 -0
- package/dist/esm/hooks/usePrefersReducedMotion.test.d.ts +1 -0
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +3 -2
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/usePrefersReducedMotion.d.ts +6 -0
- package/dist/hooks/usePrefersReducedMotion.js +30 -0
- package/dist/hooks/usePrefersReducedMotion.test.d.ts +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +38 -3
- package/package.json +1 -1
- /package/dist/components/{Notification → Notifications/Notification}/Notification.stories.d.ts +0 -0
- /package/dist/components/{Notification → Notifications/Notification}/Notification.stories.js +0 -0
- /package/dist/components/{Notification → Notifications/Notification}/Notification.test.d.ts +0 -0
- /package/dist/components/{Notification → Notifications/Notification}/index.d.ts +0 -0
- /package/dist/components/{Notification → Notifications/Notification}/index.js +0 -0
- /package/dist/{esm/components/Notification/Notification.test.d.ts → components/Notifications/ToastNotification/ToastNotification.test.d.ts} +0 -0
- /package/dist/esm/components/{Notification → Notifications/Notification}/Notification.stories.d.ts +0 -0
- /package/dist/esm/components/{Notification → Notifications/Notification}/Notification.stories.js +0 -0
- /package/dist/esm/components/{Notification → Notifications/Notification}/index.d.ts +0 -0
- /package/dist/esm/components/{Notification → Notifications/Notification}/index.js +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { NotificationAction, NotificationType } from "../../NotificationProvider";
|
|
2
|
+
import type { ValueOf } from "../../../types";
|
|
3
|
+
import { NotificationSeverity } from "../../Notifications";
|
|
4
|
+
import type { FC, PropsWithChildren, ReactNode } from "react";
|
|
5
|
+
export type ToastNotificationType = NotificationType & {
|
|
6
|
+
timestamp?: ReactNode;
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
interface ToastNotificationHelper {
|
|
10
|
+
notifications: ToastNotificationType[];
|
|
11
|
+
success: (message: ReactNode, actions?: NotificationAction[]) => ToastNotificationType;
|
|
12
|
+
info: (message: ReactNode, title?: string) => ToastNotificationType;
|
|
13
|
+
failure: (title: string, error: unknown, message?: ReactNode, actions?: NotificationAction[]) => ToastNotificationType;
|
|
14
|
+
clear: (notification?: ToastNotificationType[]) => void;
|
|
15
|
+
toggleListView: () => void;
|
|
16
|
+
isListView: boolean;
|
|
17
|
+
countBySeverity: GroupedNotificationCount;
|
|
18
|
+
}
|
|
19
|
+
export type GroupedNotificationCount = {
|
|
20
|
+
[key in ValueOf<typeof NotificationSeverity>]?: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The `ToastNotificationProvider` can be used to manage toast notifications.
|
|
24
|
+
|
|
25
|
+
Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
|
|
26
|
+
Notifications automatically dismiss after a delay unless manually dismissed or expanded.
|
|
27
|
+
|
|
28
|
+
| **Values** | **Description** |
|
|
29
|
+
|----------------------------------|---------------------------------------------------------------------------------|
|
|
30
|
+
| `toastNotify.success()` | Displays a success toast. Optionally accepts actions. |
|
|
31
|
+
| `toastNotify.info()` | Displays an info toast. Optionally accepts a custom title. |
|
|
32
|
+
| `toastNotify.failure()` | Displays a failure toast with an error and optional message or actions. |
|
|
33
|
+
| `toastNotify.clear()` | Clears specific toasts, or all toasts if none are specified. |
|
|
34
|
+
| `toastNotify.toggleListView()` | Toggles the notification list view open or closed. |
|
|
35
|
+
| `toastNotify.countBySeverity` | Returns the count of notifications grouped by severity (e.g., success, info). |
|
|
36
|
+
|
|
37
|
+
Some example usages:
|
|
38
|
+
|
|
39
|
+
1. **Show a success toast:**
|
|
40
|
+
```
|
|
41
|
+
toastNotify.success("Your changes have been saved.");
|
|
42
|
+
toastNotify.success("Your changes have been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
|
|
43
|
+
```
|
|
44
|
+
2. **Show an info toast:**
|
|
45
|
+
```
|
|
46
|
+
toastNotify.info("Your changes are syncing in the background.");
|
|
47
|
+
toastNotify.info("Your changes are syncing in the background.", "Syncing");
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
3. **Show a failure toast:**
|
|
51
|
+
```
|
|
52
|
+
toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
|
|
53
|
+
toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.", [{label: "Retry", onClick: () => console.log("Retry clicked")}]);
|
|
54
|
+
```
|
|
55
|
+
4. **Clear notifications:**
|
|
56
|
+
```
|
|
57
|
+
toastNotify.clear(); // clears all toast notifications
|
|
58
|
+
toastNotify.clear([notificationId]); // clears specific toast notifications
|
|
59
|
+
```
|
|
60
|
+
5. **Toggle the notification list view:**
|
|
61
|
+
```
|
|
62
|
+
toastNotify.toggleListView();
|
|
63
|
+
```
|
|
64
|
+
6. **Get the count of notifications by severity:**
|
|
65
|
+
```
|
|
66
|
+
const count = toastNotify.countBySeverity;
|
|
67
|
+
console.log(count.positive);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Alternatively, you can use the `ToastNotification` and `ToastNotificationList` components directly, without using the provider.
|
|
71
|
+
*/
|
|
72
|
+
declare const ToastNotificationProvider: FC<PropsWithChildren>;
|
|
73
|
+
export default ToastNotificationProvider;
|
|
74
|
+
export declare const useToastNotification: () => ToastNotificationHelper;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToastNotification = exports.default = void 0;
|
|
7
|
+
var _NotificationProvider = require("../../NotificationProvider");
|
|
8
|
+
var _ = require("./..");
|
|
9
|
+
var _ToastNotification = _interopRequireDefault(require("./ToastNotification"));
|
|
10
|
+
var _ToastNotificationList = _interopRequireDefault(require("./ToastNotificationList"));
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
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; }
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
const HIDE_NOTIFICATION_DELAY = 5000;
|
|
16
|
+
const initialNotification = {
|
|
17
|
+
id: "",
|
|
18
|
+
message: "",
|
|
19
|
+
type: "positive"
|
|
20
|
+
};
|
|
21
|
+
const ToastNotificationContext = /*#__PURE__*/(0, _react.createContext)({
|
|
22
|
+
/** List of all active toast notifications */
|
|
23
|
+
notifications: [],
|
|
24
|
+
/** Show a success toast. Optionally pass actions. */
|
|
25
|
+
success: () => initialNotification,
|
|
26
|
+
/** Show an info toast. Optionally pass a custom title. */
|
|
27
|
+
info: () => initialNotification,
|
|
28
|
+
/** Show a failure toast with an error and optional message/actions. */
|
|
29
|
+
failure: () => initialNotification,
|
|
30
|
+
/** Clear one or more specific toasts, or all if none provided. */
|
|
31
|
+
clear: () => null,
|
|
32
|
+
/** Toggle between single toast view and list view. */
|
|
33
|
+
toggleListView: () => null,
|
|
34
|
+
/** Whether the notification list view is currently open. */
|
|
35
|
+
isListView: false,
|
|
36
|
+
/** Grouped count of notifications by severity (positive, info, etc.). */
|
|
37
|
+
countBySeverity: {}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The `ToastNotificationProvider` can be used to manage toast notifications.
|
|
42
|
+
|
|
43
|
+
Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
|
|
44
|
+
Notifications automatically dismiss after a delay unless manually dismissed or expanded.
|
|
45
|
+
|
|
46
|
+
| **Values** | **Description** |
|
|
47
|
+
|----------------------------------|---------------------------------------------------------------------------------|
|
|
48
|
+
| `toastNotify.success()` | Displays a success toast. Optionally accepts actions. |
|
|
49
|
+
| `toastNotify.info()` | Displays an info toast. Optionally accepts a custom title. |
|
|
50
|
+
| `toastNotify.failure()` | Displays a failure toast with an error and optional message or actions. |
|
|
51
|
+
| `toastNotify.clear()` | Clears specific toasts, or all toasts if none are specified. |
|
|
52
|
+
| `toastNotify.toggleListView()` | Toggles the notification list view open or closed. |
|
|
53
|
+
| `toastNotify.countBySeverity` | Returns the count of notifications grouped by severity (e.g., success, info). |
|
|
54
|
+
|
|
55
|
+
Some example usages:
|
|
56
|
+
|
|
57
|
+
1. **Show a success toast:**
|
|
58
|
+
```
|
|
59
|
+
toastNotify.success("Your changes have been saved.");
|
|
60
|
+
toastNotify.success("Your changes have been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
|
|
61
|
+
```
|
|
62
|
+
2. **Show an info toast:**
|
|
63
|
+
```
|
|
64
|
+
toastNotify.info("Your changes are syncing in the background.");
|
|
65
|
+
toastNotify.info("Your changes are syncing in the background.", "Syncing");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
3. **Show a failure toast:**
|
|
69
|
+
```
|
|
70
|
+
toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
|
|
71
|
+
toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.", [{label: "Retry", onClick: () => console.log("Retry clicked")}]);
|
|
72
|
+
```
|
|
73
|
+
4. **Clear notifications:**
|
|
74
|
+
```
|
|
75
|
+
toastNotify.clear(); // clears all toast notifications
|
|
76
|
+
toastNotify.clear([notificationId]); // clears specific toast notifications
|
|
77
|
+
```
|
|
78
|
+
5. **Toggle the notification list view:**
|
|
79
|
+
```
|
|
80
|
+
toastNotify.toggleListView();
|
|
81
|
+
```
|
|
82
|
+
6. **Get the count of notifications by severity:**
|
|
83
|
+
```
|
|
84
|
+
const count = toastNotify.countBySeverity;
|
|
85
|
+
console.log(count.positive);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Alternatively, you can use the `ToastNotification` and `ToastNotificationList` components directly, without using the provider.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
const ToastNotificationProvider = _ref => {
|
|
92
|
+
let {
|
|
93
|
+
children
|
|
94
|
+
} = _ref;
|
|
95
|
+
const [notifications, setNotifications] = (0, _react.useState)([]);
|
|
96
|
+
const [showList, setShowList] = (0, _react.useState)(false);
|
|
97
|
+
const [notificationTimer, setNotificationTimer] = (0, _react.useState)(null);
|
|
98
|
+
|
|
99
|
+
// cleanup on timer if unmounted
|
|
100
|
+
(0, _react.useEffect)(() => {
|
|
101
|
+
return () => {
|
|
102
|
+
if (notificationTimer) {
|
|
103
|
+
clearTimeout(notificationTimer);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}, []);
|
|
107
|
+
const showNotificationWithDelay = () => {
|
|
108
|
+
setNotificationTimer(prevTimer => {
|
|
109
|
+
if (prevTimer) {
|
|
110
|
+
clearTimeout(prevTimer);
|
|
111
|
+
}
|
|
112
|
+
if (!showList) {
|
|
113
|
+
return setTimeout(() => {
|
|
114
|
+
setNotificationTimer(null);
|
|
115
|
+
}, HIDE_NOTIFICATION_DELAY);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
const clearNotificationTimer = () => {
|
|
121
|
+
setNotificationTimer(prevTimer => {
|
|
122
|
+
if (prevTimer) {
|
|
123
|
+
clearTimeout(prevTimer);
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const addNotification = notification => {
|
|
129
|
+
const notificationToAdd = {
|
|
130
|
+
...notification,
|
|
131
|
+
timestamp: new Date().toLocaleString(),
|
|
132
|
+
id: Date.now().toString() + (Math.random() + 1).toString(36).substring(7)
|
|
133
|
+
};
|
|
134
|
+
setNotifications(prev => {
|
|
135
|
+
return [...prev, notificationToAdd];
|
|
136
|
+
});
|
|
137
|
+
showNotificationWithDelay();
|
|
138
|
+
return notificationToAdd;
|
|
139
|
+
};
|
|
140
|
+
const clear = notifications => {
|
|
141
|
+
if (!notifications) {
|
|
142
|
+
setNotifications([]);
|
|
143
|
+
setShowList(false);
|
|
144
|
+
clearNotificationTimer();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
setNotifications(prev => {
|
|
148
|
+
const removeIdLookup = new Set(notifications);
|
|
149
|
+
const newNotifications = prev.filter(item => !removeIdLookup.has(item));
|
|
150
|
+
|
|
151
|
+
// if we are clearing the last notification from an expanded list,
|
|
152
|
+
// then we want to collapse the list as well if all notifications has been cleared
|
|
153
|
+
if (!newNotifications.length) {
|
|
154
|
+
setShowList(false);
|
|
155
|
+
}
|
|
156
|
+
return newNotifications;
|
|
157
|
+
});
|
|
158
|
+
clearNotificationTimer();
|
|
159
|
+
};
|
|
160
|
+
const toggleListView = () => {
|
|
161
|
+
clearNotificationTimer();
|
|
162
|
+
setShowList(prev => !prev);
|
|
163
|
+
};
|
|
164
|
+
const countBySeverity = {
|
|
165
|
+
positive: 0,
|
|
166
|
+
negative: 0,
|
|
167
|
+
caution: 0,
|
|
168
|
+
information: 0
|
|
169
|
+
};
|
|
170
|
+
notifications.forEach(notification => {
|
|
171
|
+
countBySeverity[notification.type] += 1;
|
|
172
|
+
});
|
|
173
|
+
const helper = {
|
|
174
|
+
notifications,
|
|
175
|
+
failure: (title, error, message, actions) => addNotification((0, _NotificationProvider.failure)(title, error, message, actions)),
|
|
176
|
+
info: (message, title) => addNotification((0, _NotificationProvider.info)(message, title)),
|
|
177
|
+
success: (message, actions) => addNotification({
|
|
178
|
+
message,
|
|
179
|
+
actions,
|
|
180
|
+
type: _.NotificationSeverity.POSITIVE
|
|
181
|
+
}),
|
|
182
|
+
clear,
|
|
183
|
+
toggleListView,
|
|
184
|
+
isListView: showList,
|
|
185
|
+
countBySeverity
|
|
186
|
+
};
|
|
187
|
+
const latestNotification = notifications[notifications.length - 1];
|
|
188
|
+
const hasNotifications = !!notifications.length;
|
|
189
|
+
const showNotification = hasNotifications && !showList && notificationTimer;
|
|
190
|
+
const showNotificationList = hasNotifications && showList;
|
|
191
|
+
return /*#__PURE__*/_react.default.createElement(ToastNotificationContext.Provider, {
|
|
192
|
+
value: helper
|
|
193
|
+
}, children, /*#__PURE__*/_react.default.createElement(_ToastNotification.default, {
|
|
194
|
+
notification: latestNotification,
|
|
195
|
+
onDismiss: clear,
|
|
196
|
+
show: !!showNotification
|
|
197
|
+
}), /*#__PURE__*/_react.default.createElement(_ToastNotificationList.default, {
|
|
198
|
+
notifications: notifications,
|
|
199
|
+
groupedCount: countBySeverity,
|
|
200
|
+
show: showNotificationList,
|
|
201
|
+
onDismiss: clear
|
|
202
|
+
}));
|
|
203
|
+
};
|
|
204
|
+
var _default = exports.default = ToastNotificationProvider;
|
|
205
|
+
const useToastNotification = () => (0, _react.useContext)(ToastNotificationContext);
|
|
206
|
+
exports.useToastNotification = useToastNotification;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as ToastNotificationProvider } from "./ToastNotificationProvider";
|
|
2
|
+
export { useToastNotification } from "./ToastNotificationProvider";
|
|
3
|
+
export type { ToastNotificationType } from "./ToastNotificationProvider";
|
|
4
|
+
export { default as ToastNotification } from "./ToastNotification";
|
|
5
|
+
export { default as ToastNotificationList } from "./ToastNotificationList";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ToastNotification", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ToastNotification.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ToastNotificationList", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _ToastNotificationList.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ToastNotificationProvider", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _ToastNotificationProvider.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "useToastNotification", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _ToastNotificationProvider.useToastNotification;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _ToastNotificationProvider = _interopRequireWildcard(require("./ToastNotificationProvider"));
|
|
31
|
+
var _ToastNotification = _interopRequireDefault(require("./ToastNotification"));
|
|
32
|
+
var _ToastNotificationList = _interopRequireDefault(require("./ToastNotificationList"));
|
|
33
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
35
|
+
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; }
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default, NotificationSeverity } from "./Notification";
|
|
2
|
+
export type { NotificationProps } from "./Notification";
|
|
3
|
+
export type { ToastNotificationType } from "./ToastNotification";
|
|
4
|
+
export { ToastNotification, ToastNotificationList, useToastNotification, ToastNotificationProvider, } from "./ToastNotification";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "NotificationSeverity", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _Notification.NotificationSeverity;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ToastNotification", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _ToastNotification.ToastNotification;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ToastNotificationList", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _ToastNotification.ToastNotificationList;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ToastNotificationProvider", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _ToastNotification.ToastNotificationProvider;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "default", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _Notification.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "useToastNotification", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _ToastNotification.useToastNotification;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _Notification = _interopRequireWildcard(require("./Notification"));
|
|
43
|
+
var _ToastNotification = require("./ToastNotification");
|
|
44
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
45
|
+
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; }
|
|
@@ -75,6 +75,7 @@ const Slider = _ref => {
|
|
|
75
75
|
style: style,
|
|
76
76
|
type: "range"
|
|
77
77
|
}, inputProps)), showInput && /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
78
|
+
"aria-label": typeof label === "string" ? label : undefined,
|
|
78
79
|
"aria-describedby": help ? helpId : null,
|
|
79
80
|
"aria-errormessage": hasError ? validationId : null,
|
|
80
81
|
"aria-invalid": hasError,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
2
2
|
import fastDeepEqual from "fast-deep-equal";
|
|
3
3
|
import { info as _info, failure as _failure, success as _success, queue } from "./messageBuilder";
|
|
4
|
-
import Notification
|
|
4
|
+
import Notification from "../Notifications";
|
|
5
|
+
import { DefaultTitles } from "../Notifications/Notification/Notification";
|
|
5
6
|
var NotifyContext = /*#__PURE__*/createContext({
|
|
6
7
|
notification: null,
|
|
7
8
|
clear: () => undefined,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { ValueOf } from "../../types";
|
|
3
|
-
import { NotificationSeverity } from "../
|
|
3
|
+
import { NotificationSeverity } from "../Notifications";
|
|
4
4
|
export interface NotifyProviderProps {
|
|
5
5
|
state?: {
|
|
6
6
|
queuedNotification: NotificationType | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ElementType } from "react";
|
|
2
2
|
import type { HTMLProps, ReactNode } from "react";
|
|
3
|
-
import type { ClassName, PropsWithSpread, ValueOf } from "
|
|
3
|
+
import type { ClassName, PropsWithSpread, ValueOf } from "../../../types";
|
|
4
4
|
export declare enum Label {
|
|
5
5
|
Close = "Close notification"
|
|
6
6
|
}
|
|
@@ -4,8 +4,8 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import React, { useEffect, useRef } from "react";
|
|
7
|
-
import Button, { ButtonAppearance } from "
|
|
8
|
-
import { IS_DEV, isReactNode } from "
|
|
7
|
+
import Button, { ButtonAppearance } from "../../Button";
|
|
8
|
+
import { IS_DEV, isReactNode } from "../../../utils";
|
|
9
9
|
export var Label = /*#__PURE__*/function (Label) {
|
|
10
10
|
Label["Close"] = "Close notification";
|
|
11
11
|
return Label;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FC, PropsWithChildren } from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
show: boolean;
|
|
4
|
+
from: Keyframe;
|
|
5
|
+
to: Keyframe;
|
|
6
|
+
exitAnimation?: Keyframe[];
|
|
7
|
+
options?: KeyframeAnimationOptions;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const Animate: FC<PropsWithChildren<Props>>;
|
|
11
|
+
export default Animate;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { usePrefersReducedMotion } from "../../../hooks";
|
|
4
|
+
var Animate = _ref => {
|
|
5
|
+
var {
|
|
6
|
+
show,
|
|
7
|
+
children,
|
|
8
|
+
from,
|
|
9
|
+
to,
|
|
10
|
+
exitAnimation,
|
|
11
|
+
options = {
|
|
12
|
+
duration: 500,
|
|
13
|
+
fill: "forwards"
|
|
14
|
+
},
|
|
15
|
+
className
|
|
16
|
+
} = _ref;
|
|
17
|
+
var containerRef = useRef(null);
|
|
18
|
+
var preferReducedMotion = usePrefersReducedMotion();
|
|
19
|
+
|
|
20
|
+
// This state is used so that we trigger a extra render cycle
|
|
21
|
+
// to animate the child component when it is being unmounted
|
|
22
|
+
var [removeState, setRemove] = useState(!show);
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
var element = containerRef.current;
|
|
25
|
+
if (show) {
|
|
26
|
+
setRemove(false);
|
|
27
|
+
if (!element || preferReducedMotion) return;
|
|
28
|
+
element.animate([from, to], options);
|
|
29
|
+
} else {
|
|
30
|
+
if (!element) return;
|
|
31
|
+
if (preferReducedMotion) {
|
|
32
|
+
setRemove(true);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
var animation = element.animate(exitAnimation || [to, from], options);
|
|
36
|
+
animation.onfinish = () => {
|
|
37
|
+
setRemove(true);
|
|
38
|
+
// This is important, else the next render cycle due to setRemove will cause flickering effect
|
|
39
|
+
element.style.display = "none";
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}, [show, removeState]);
|
|
43
|
+
if (removeState) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
47
|
+
ref: containerRef,
|
|
48
|
+
className: className
|
|
49
|
+
}, children);
|
|
50
|
+
};
|
|
51
|
+
export default Animate;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
@import "vanilla-framework/scss/settings";
|
|
2
|
+
@import "vanilla-framework/scss/build";
|
|
3
|
+
|
|
4
|
+
.toast-animate {
|
|
5
|
+
position: relative;
|
|
6
|
+
z-index: 101;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.toast-notification,
|
|
10
|
+
.toast-notification-list {
|
|
11
|
+
bottom: 3.5rem;
|
|
12
|
+
margin: 0 1.5rem;
|
|
13
|
+
position: absolute;
|
|
14
|
+
right: 0;
|
|
15
|
+
|
|
16
|
+
@media screen and (min-width: $breakpoint-small) and (max-width: $breakpoint-large) {
|
|
17
|
+
width: 500px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@media screen and (min-width: $breakpoint-large) {
|
|
21
|
+
width: 600px;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.toast-notification {
|
|
26
|
+
box-shadow: 0 0 calc($sp-unit * 4) $sp-unit rgb(0 0 0 / 15%);
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
z-index: 101;
|
|
29
|
+
|
|
30
|
+
@media screen and (max-width: $breakpoint-small) {
|
|
31
|
+
left: 0;
|
|
32
|
+
margin: 1.5rem auto;
|
|
33
|
+
max-width: 400px;
|
|
34
|
+
width: 95vw;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.toast-notification-list {
|
|
39
|
+
background-color: white;
|
|
40
|
+
box-shadow: 0 0 calc($sp-unit * 4) $sp-unit rgb(0 0 0 / 22%);
|
|
41
|
+
max-height: calc(100vh - 4.5rem);
|
|
42
|
+
overflow: auto;
|
|
43
|
+
padding: 0 0.5rem;
|
|
44
|
+
z-index: 102;
|
|
45
|
+
|
|
46
|
+
.individual-notification {
|
|
47
|
+
margin: 0.5rem 0;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.dismiss {
|
|
52
|
+
align-items: center;
|
|
53
|
+
background-color: white;
|
|
54
|
+
bottom: 0;
|
|
55
|
+
display: flex;
|
|
56
|
+
justify-content: space-between;
|
|
57
|
+
padding: 0.5rem 0;
|
|
58
|
+
padding-left: 0.8rem;
|
|
59
|
+
position: sticky;
|
|
60
|
+
z-index: 10;
|
|
61
|
+
|
|
62
|
+
.dismiss-button {
|
|
63
|
+
align-items: center;
|
|
64
|
+
display: flex;
|
|
65
|
+
|
|
66
|
+
.dismiss-text {
|
|
67
|
+
align-items: center;
|
|
68
|
+
display: flex;
|
|
69
|
+
gap: $sph--x-small;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.filters {
|
|
74
|
+
display: flex;
|
|
75
|
+
|
|
76
|
+
.filter-button {
|
|
77
|
+
align-items: center;
|
|
78
|
+
border: none;
|
|
79
|
+
display: flex;
|
|
80
|
+
gap: $sph--x-small;
|
|
81
|
+
justify-content: center;
|
|
82
|
+
margin-right: $sph--small !important;
|
|
83
|
+
padding: calc(0.4rem - 1px);
|
|
84
|
+
|
|
85
|
+
/* stylelint-disable max-nesting-depth */
|
|
86
|
+
/* stylelint-disable-next-line selector-max-type */
|
|
87
|
+
span {
|
|
88
|
+
padding: 0;
|
|
89
|
+
text-align: center;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* stylelint-disable-next-line selector-class-pattern */
|
|
93
|
+
.p-icon--info--notification {
|
|
94
|
+
@extend %icon;
|
|
95
|
+
@include vf-icon-info-coloured-themed;
|
|
96
|
+
}
|
|
97
|
+
/* stylelint-enable max-nesting-depth */
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@media screen and (max-width: $breakpoint-small) {
|
|
102
|
+
align-items: flex-start;
|
|
103
|
+
flex-direction: column;
|
|
104
|
+
gap: 0.5rem;
|
|
105
|
+
margin-bottom: 0.5rem;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@media screen and (max-width: $breakpoint-small) {
|
|
110
|
+
bottom: 2rem;
|
|
111
|
+
left: 0;
|
|
112
|
+
margin: 1.5rem auto;
|
|
113
|
+
max-width: 400px;
|
|
114
|
+
width: 95vw;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToastNotificationType } from "./ToastNotificationProvider";
|
|
2
|
+
import type { FC } from "react";
|
|
3
|
+
import "./Toast.scss";
|
|
4
|
+
interface Props {
|
|
5
|
+
notification: ToastNotificationType;
|
|
6
|
+
onDismiss: (notification?: ToastNotificationType[]) => void;
|
|
7
|
+
show: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const ToastNotification: FC<Props>;
|
|
10
|
+
export default ToastNotification;
|