@snack-uikit/toaster 0.3.21-preview-85c5f47b.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/CHANGELOG.md +317 -0
- package/LICENSE +201 -0
- package/README.md +84 -0
- package/dist/components/ToastSystemEvent/ToastSystemEvent.d.ts +23 -0
- package/dist/components/ToastSystemEvent/ToastSystemEvent.js +36 -0
- package/dist/components/ToastSystemEvent/constants.d.ts +15 -0
- package/dist/components/ToastSystemEvent/constants.js +16 -0
- package/dist/components/ToastSystemEvent/index.d.ts +1 -0
- package/dist/components/ToastSystemEvent/index.js +1 -0
- package/dist/components/ToastSystemEvent/styles.module.css +183 -0
- package/dist/components/ToastSystemEvent/utils.d.ts +2 -0
- package/dist/components/ToastSystemEvent/utils.js +17 -0
- package/dist/components/ToastUserAction/ToastUserAction.d.ts +19 -0
- package/dist/components/ToastUserAction/ToastUserAction.js +26 -0
- package/dist/components/ToastUserAction/constants.d.ts +10 -0
- package/dist/components/ToastUserAction/constants.js +12 -0
- package/dist/components/ToastUserAction/index.d.ts +1 -0
- package/dist/components/ToastUserAction/index.js +1 -0
- package/dist/components/ToastUserAction/styles.module.css +56 -0
- package/dist/components/ToastUserAction/utils.d.ts +2 -0
- package/dist/components/ToastUserAction/utils.js +16 -0
- package/dist/components/ToasterContainer/ToasterContainer.d.ts +21 -0
- package/dist/components/ToasterContainer/ToasterContainer.js +36 -0
- package/dist/components/ToasterContainer/index.d.ts +1 -0
- package/dist/components/ToasterContainer/index.js +1 -0
- package/dist/components/ToasterContainer/styles.module.css +78 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +22 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.js +199 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/testIds.d.ts +16 -0
- package/dist/testIds.js +18 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.js +5 -0
- package/package.json +43 -0
- package/src/components/ToastSystemEvent/ToastSystemEvent.tsx +119 -0
- package/src/components/ToastSystemEvent/constants.ts +17 -0
- package/src/components/ToastSystemEvent/index.ts +1 -0
- package/src/components/ToastSystemEvent/styles.module.scss +194 -0
- package/src/components/ToastSystemEvent/utils.tsx +18 -0
- package/src/components/ToastUserAction/ToastUserAction.tsx +68 -0
- package/src/components/ToastUserAction/constants.tsx +11 -0
- package/src/components/ToastUserAction/index.ts +1 -0
- package/src/components/ToastUserAction/styles.module.scss +66 -0
- package/src/components/ToastUserAction/utils.tsx +17 -0
- package/src/components/ToasterContainer/ToasterContainer.tsx +93 -0
- package/src/components/ToasterContainer/index.ts +1 -0
- package/src/components/ToasterContainer/styles.module.scss +81 -0
- package/src/components/index.ts +3 -0
- package/src/constants.ts +25 -0
- package/src/helpers.tsx +293 -0
- package/src/index.ts +3 -0
- package/src/testIds.ts +21 -0
- package/src/types.ts +82 -0
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// eslint-disable-next-line react/no-deprecated
|
|
3
|
+
import { render } from 'react-dom';
|
|
4
|
+
import { toast } from 'react-toastify';
|
|
5
|
+
import { ToasterContainer, ToastSystemEvent, ToastUserAction, } from './components';
|
|
6
|
+
import { AUTO_CLOSE_TIME, TOASTER_CONTAINER_DEFAULT_PROPS, TOASTER_CONTAINER_PREFIX, TOASTER_ROOT_ID, } from './constants';
|
|
7
|
+
import { ToasterType, } from './types';
|
|
8
|
+
function getToasterContainer({ type, toasterParent, containerProps, }) {
|
|
9
|
+
const containerId = (containerProps === null || containerProps === void 0 ? void 0 : containerProps.containerId) || `${TOASTER_CONTAINER_PREFIX}${type}`;
|
|
10
|
+
const toasterContainerProps = Object.assign(Object.assign(Object.assign({}, TOASTER_CONTAINER_DEFAULT_PROPS[type]), (containerProps || {})), { containerId });
|
|
11
|
+
const toasterRootId = `${TOASTER_ROOT_ID}__${type}`;
|
|
12
|
+
let rootInDOM = toasterParent.querySelector(`#${toasterRootId}`);
|
|
13
|
+
if (!rootInDOM) {
|
|
14
|
+
rootInDOM = document.createElement('div');
|
|
15
|
+
rootInDOM.id = toasterRootId;
|
|
16
|
+
toasterParent.appendChild(rootInDOM);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
toasterContainer: rootInDOM,
|
|
20
|
+
toasterContainerProps,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function getToastOptions({ type, toastOptions, containerId, }) {
|
|
24
|
+
return {
|
|
25
|
+
toastId: toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.id,
|
|
26
|
+
autoClose: AUTO_CLOSE_TIME[type],
|
|
27
|
+
containerId: containerId || `${TOASTER_CONTAINER_PREFIX}${type}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function getToastComponent({ type, toasterProps, }) {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case ToasterType.UserAction:
|
|
33
|
+
return _jsx(ToastUserAction, Object.assign({}, toasterProps));
|
|
34
|
+
case ToasterType.SystemEvent:
|
|
35
|
+
return _jsx(ToastSystemEvent, Object.assign({}, toasterProps));
|
|
36
|
+
default:
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const openToast = ({ type, toasterProps, containerProps, toastOptions, toasterParent = document.body, }) => {
|
|
41
|
+
const { toasterContainer, toasterContainerProps } = getToasterContainer({
|
|
42
|
+
type,
|
|
43
|
+
toasterParent,
|
|
44
|
+
containerProps,
|
|
45
|
+
});
|
|
46
|
+
const options = getToastOptions({
|
|
47
|
+
type,
|
|
48
|
+
toasterProps,
|
|
49
|
+
toastOptions,
|
|
50
|
+
containerId: toasterContainerProps.containerId,
|
|
51
|
+
});
|
|
52
|
+
const toasterComponent = getToastComponent({
|
|
53
|
+
type,
|
|
54
|
+
toasterProps,
|
|
55
|
+
});
|
|
56
|
+
return new Promise(resolve => {
|
|
57
|
+
render(_jsx(ToasterContainer, Object.assign({}, toasterContainerProps)), toasterContainer, () => {
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
resolve(toast(toasterComponent, options));
|
|
60
|
+
}, 0);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const updateToast = (id, { type, toasterProps, toastOptions, containerId }) => {
|
|
65
|
+
const options = getToastOptions({ type, toasterProps, toastOptions, containerId });
|
|
66
|
+
const toastComponent = getToastComponent({
|
|
67
|
+
type,
|
|
68
|
+
toasterProps,
|
|
69
|
+
});
|
|
70
|
+
return toast.update(id, Object.assign(Object.assign({}, options), { render: toastComponent }));
|
|
71
|
+
};
|
|
72
|
+
export const dismissToast = toast.dismiss;
|
|
73
|
+
export const isToastActive = toast.isActive;
|
|
74
|
+
const userAction = {
|
|
75
|
+
success(options) {
|
|
76
|
+
return openToast({
|
|
77
|
+
type: ToasterType.UserAction,
|
|
78
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Success }),
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
neutral(options) {
|
|
82
|
+
return openToast({
|
|
83
|
+
type: ToasterType.UserAction,
|
|
84
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Neutral }),
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
error(options) {
|
|
88
|
+
return openToast({
|
|
89
|
+
type: ToasterType.UserAction,
|
|
90
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Error }),
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
warning(options) {
|
|
94
|
+
return openToast({
|
|
95
|
+
type: ToasterType.UserAction,
|
|
96
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Warning }),
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
update: {
|
|
100
|
+
success(id, options) {
|
|
101
|
+
updateToast(id, {
|
|
102
|
+
type: ToasterType.UserAction,
|
|
103
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Success }),
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
neutral(id, options) {
|
|
107
|
+
updateToast(id, {
|
|
108
|
+
type: ToasterType.UserAction,
|
|
109
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Neutral }),
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
warning(id, options) {
|
|
113
|
+
updateToast(id, {
|
|
114
|
+
type: ToasterType.UserAction,
|
|
115
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Warning }),
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
error(id, options) {
|
|
119
|
+
updateToast(id, {
|
|
120
|
+
type: ToasterType.UserAction,
|
|
121
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastUserAction.appearances.Error }),
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
dismiss(id) {
|
|
126
|
+
return toast.dismiss(id);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const systemEvent = {
|
|
130
|
+
success(options) {
|
|
131
|
+
return openToast({
|
|
132
|
+
type: ToasterType.SystemEvent,
|
|
133
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Success }),
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
neutral(options) {
|
|
137
|
+
return openToast({
|
|
138
|
+
type: ToasterType.SystemEvent,
|
|
139
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Neutral }),
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
warning(options) {
|
|
143
|
+
return openToast({
|
|
144
|
+
type: ToasterType.SystemEvent,
|
|
145
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Warning }),
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
error(options) {
|
|
149
|
+
return openToast({
|
|
150
|
+
type: ToasterType.SystemEvent,
|
|
151
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Error }),
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
errorCritical(options) {
|
|
155
|
+
return openToast({
|
|
156
|
+
type: ToasterType.SystemEvent,
|
|
157
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.ErrorCritical }),
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
update: {
|
|
161
|
+
success(id, options) {
|
|
162
|
+
return updateToast(id, {
|
|
163
|
+
type: ToasterType.SystemEvent,
|
|
164
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Success }),
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
neutral(id, options) {
|
|
168
|
+
return updateToast(id, {
|
|
169
|
+
type: ToasterType.SystemEvent,
|
|
170
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Neutral }),
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
warning(id, options) {
|
|
174
|
+
return updateToast(id, {
|
|
175
|
+
type: ToasterType.SystemEvent,
|
|
176
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Warning }),
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
error(id, options) {
|
|
180
|
+
return updateToast(id, {
|
|
181
|
+
type: ToasterType.SystemEvent,
|
|
182
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.Error }),
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
errorCritical(id, options) {
|
|
186
|
+
return updateToast(id, {
|
|
187
|
+
type: ToasterType.SystemEvent,
|
|
188
|
+
toasterProps: Object.assign(Object.assign({}, options), { appearance: ToastSystemEvent.appearances.ErrorCritical }),
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
dismiss(id) {
|
|
193
|
+
return toast.dismiss(id);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
export const toaster = {
|
|
197
|
+
userAction,
|
|
198
|
+
systemEvent,
|
|
199
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { toaster } from './helpers';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const TOAST_SYSTEM_EVENT_TEST_IDS: {
|
|
2
|
+
icon: string;
|
|
3
|
+
main: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
buttonClose: string;
|
|
7
|
+
link: string;
|
|
8
|
+
progressbar: string;
|
|
9
|
+
buttonCloseColumn: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const TOAST_USER_ACTION_TEST_IDS: {
|
|
12
|
+
main: string;
|
|
13
|
+
label: string;
|
|
14
|
+
icon: string;
|
|
15
|
+
link: string;
|
|
16
|
+
};
|
package/dist/testIds.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const TOAST_SYSTEM_EVENT_TEST_ID = 'toast-system-event';
|
|
2
|
+
export const TOAST_SYSTEM_EVENT_TEST_IDS = {
|
|
3
|
+
icon: `${TOAST_SYSTEM_EVENT_TEST_ID}__icon`,
|
|
4
|
+
main: TOAST_SYSTEM_EVENT_TEST_ID,
|
|
5
|
+
title: `${TOAST_SYSTEM_EVENT_TEST_ID}__title`,
|
|
6
|
+
description: `${TOAST_SYSTEM_EVENT_TEST_ID}__description`,
|
|
7
|
+
buttonClose: `${TOAST_SYSTEM_EVENT_TEST_ID}__button-close`,
|
|
8
|
+
link: `${TOAST_SYSTEM_EVENT_TEST_ID}__link`,
|
|
9
|
+
progressbar: `${TOAST_SYSTEM_EVENT_TEST_ID}__progressbar`,
|
|
10
|
+
buttonCloseColumn: `${TOAST_SYSTEM_EVENT_TEST_ID}button-close-column`,
|
|
11
|
+
};
|
|
12
|
+
const TOAST_USER_ACTION_TEST_ID = 'toast-user-action';
|
|
13
|
+
export const TOAST_USER_ACTION_TEST_IDS = {
|
|
14
|
+
main: TOAST_USER_ACTION_TEST_ID,
|
|
15
|
+
label: `${TOAST_USER_ACTION_TEST_ID}__label`,
|
|
16
|
+
icon: `${TOAST_USER_ACTION_TEST_ID}__icon`,
|
|
17
|
+
link: `${TOAST_USER_ACTION_TEST_ID}__link`,
|
|
18
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Id, ToastOptions as RtToastOptions } from 'react-toastify';
|
|
2
|
+
import { ToasterContainerProps, ToastSystemEventProps, ToastUserActionProps } from './components';
|
|
3
|
+
export type ToasterId = Id;
|
|
4
|
+
export type PromisedId = Promise<ToasterId>;
|
|
5
|
+
export type ToastOptions = {
|
|
6
|
+
id?: ToasterId;
|
|
7
|
+
autoClose?: RtToastOptions['autoClose'];
|
|
8
|
+
onClose?: RtToastOptions['onClose'];
|
|
9
|
+
};
|
|
10
|
+
export declare enum ToasterType {
|
|
11
|
+
SystemEvent = "system-event",
|
|
12
|
+
UserAction = "user-action"
|
|
13
|
+
}
|
|
14
|
+
export type ToasterPropsMap = {
|
|
15
|
+
[ToasterType.UserAction]: ToastUserActionProps;
|
|
16
|
+
[ToasterType.SystemEvent]: ToastSystemEventProps;
|
|
17
|
+
};
|
|
18
|
+
type OpenNotificationProps<T extends keyof ToasterPropsMap> = {
|
|
19
|
+
type: T;
|
|
20
|
+
toasterProps?: ToasterPropsMap[T];
|
|
21
|
+
containerProps?: ToasterContainerProps;
|
|
22
|
+
toastOptions?: ToastOptions;
|
|
23
|
+
toasterParent?: HTMLDivElement;
|
|
24
|
+
};
|
|
25
|
+
type DefaultToasterProps<T extends keyof ToasterPropsMap> = {
|
|
26
|
+
toasterProps: ToasterPropsMap[T];
|
|
27
|
+
};
|
|
28
|
+
export type OpenToast = <T extends keyof ToasterPropsMap>(props: DefaultToasterProps<T> & OpenNotificationProps<T>) => PromisedId;
|
|
29
|
+
export type UpdateToast = <T extends keyof ToasterPropsMap>(id: string | number, props: {
|
|
30
|
+
type: T;
|
|
31
|
+
toasterProps: ToasterPropsMap[T];
|
|
32
|
+
toastOptions?: ToastOptions;
|
|
33
|
+
containerId?: ToasterContainerProps['containerId'];
|
|
34
|
+
}) => void;
|
|
35
|
+
export type UserActionOptions = Omit<ToastUserActionProps, 'appearance'> & Pick<ToastOptions, 'id'>;
|
|
36
|
+
export type SystemEventOptions = Omit<ToastSystemEventProps, 'appearance'> & Pick<ToastOptions, 'id'>;
|
|
37
|
+
export type Toaster = {
|
|
38
|
+
userAction: {
|
|
39
|
+
success(options: UserActionOptions): PromisedId;
|
|
40
|
+
neutral(options: UserActionOptions): PromisedId;
|
|
41
|
+
warning(options: UserActionOptions): PromisedId;
|
|
42
|
+
error(options: UserActionOptions): PromisedId;
|
|
43
|
+
update: {
|
|
44
|
+
success(id: ToasterId, options: UserActionOptions): void;
|
|
45
|
+
neutral(id: ToasterId, options: UserActionOptions): void;
|
|
46
|
+
warning(id: ToasterId, options: UserActionOptions): void;
|
|
47
|
+
error(id: ToasterId, options: UserActionOptions): void;
|
|
48
|
+
};
|
|
49
|
+
dismiss(id?: ToasterId): void;
|
|
50
|
+
};
|
|
51
|
+
systemEvent: {
|
|
52
|
+
success(options: SystemEventOptions): PromisedId;
|
|
53
|
+
neutral(options: SystemEventOptions): PromisedId;
|
|
54
|
+
warning(options: SystemEventOptions): PromisedId;
|
|
55
|
+
error(options: SystemEventOptions): PromisedId;
|
|
56
|
+
errorCritical(options: SystemEventOptions): PromisedId;
|
|
57
|
+
update: {
|
|
58
|
+
success(id: ToasterId, options: SystemEventOptions): void;
|
|
59
|
+
neutral(id: ToasterId, options: SystemEventOptions): void;
|
|
60
|
+
warning(id: ToasterId, options: SystemEventOptions): void;
|
|
61
|
+
error(id: ToasterId, options: SystemEventOptions): void;
|
|
62
|
+
errorCritical(id: ToasterId, options: SystemEventOptions): void;
|
|
63
|
+
};
|
|
64
|
+
dismiss(id?: ToasterId): void;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export {};
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snack-uikit/toaster",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"title": "Toaster",
|
|
7
|
+
"version": "0.3.21-preview-85c5f47b.0",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"*.css",
|
|
10
|
+
"*.woff",
|
|
11
|
+
"*.woff2"
|
|
12
|
+
],
|
|
13
|
+
"description": "",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"homepage": "https://github.com/cloud-ru-tech/snack-uikit/tree/master/packages/toaster",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/cloud-ru-tech/snack-uikit.git",
|
|
20
|
+
"directory": "packages/toaster"
|
|
21
|
+
},
|
|
22
|
+
"author": "Nikita Ershov <niershov@cloud.ru>",
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Nikita Ershov <niershov@cloud.ru>"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src",
|
|
29
|
+
"./CHANGELOG.md",
|
|
30
|
+
"./LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"scripts": {},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@snack-uikit/icons": "0.18.2-preview-85c5f47b.0",
|
|
36
|
+
"@snack-uikit/link": "0.7.1-preview-85c5f47b.0",
|
|
37
|
+
"@snack-uikit/truncate-string": "0.2.17-preview-85c5f47b.0",
|
|
38
|
+
"@snack-uikit/utils": "2.0.2-preview-85c5f47b.0",
|
|
39
|
+
"classnames": "2.3.2",
|
|
40
|
+
"react-toastify": "9.1.3"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "6a7eef41d780d945f64f791448eaa72b9e0ae72d"
|
|
43
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { MouseEvent, useMemo } from 'react';
|
|
3
|
+
import { ToastContentProps as RtToastContentProps } from 'react-toastify';
|
|
4
|
+
|
|
5
|
+
import { CrossSVG } from '@snack-uikit/icons';
|
|
6
|
+
import { Link } from '@snack-uikit/link';
|
|
7
|
+
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
8
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
9
|
+
|
|
10
|
+
import { AUTO_CLOSE_TIME } from '../../constants';
|
|
11
|
+
import { TOAST_SYSTEM_EVENT_TEST_IDS } from '../../testIds';
|
|
12
|
+
import { ToasterType } from '../../types';
|
|
13
|
+
import { APPEARANCE_TO_ON_COLOR_MAP, ToastSystemEventAppearance } from './constants';
|
|
14
|
+
import styles from './styles.module.scss';
|
|
15
|
+
import { getIcon } from './utils';
|
|
16
|
+
|
|
17
|
+
export type ToastSystemEventLink = {
|
|
18
|
+
text: string;
|
|
19
|
+
href: string;
|
|
20
|
+
onClick?(e: MouseEvent<HTMLAnchorElement>): void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ToastSystemEventProps = Partial<RtToastContentProps> &
|
|
24
|
+
WithSupportProps<{
|
|
25
|
+
title: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
appearance?: ToastSystemEventAppearance;
|
|
28
|
+
link?: ToastSystemEventLink;
|
|
29
|
+
progressBar?: boolean;
|
|
30
|
+
closable?: boolean;
|
|
31
|
+
className?: string;
|
|
32
|
+
onCloseClick?(e: MouseEvent<HTMLButtonElement>, close?: () => void): void;
|
|
33
|
+
}>;
|
|
34
|
+
|
|
35
|
+
export function ToastSystemEvent({
|
|
36
|
+
appearance = ToastSystemEventAppearance.Neutral,
|
|
37
|
+
onCloseClick,
|
|
38
|
+
progressBar = true,
|
|
39
|
+
closable = true,
|
|
40
|
+
title,
|
|
41
|
+
description,
|
|
42
|
+
link,
|
|
43
|
+
closeToast,
|
|
44
|
+
className,
|
|
45
|
+
...rest
|
|
46
|
+
}: ToastSystemEventProps) {
|
|
47
|
+
const handleCloseClick = (e: MouseEvent<HTMLButtonElement>) => {
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
onCloseClick ? onCloseClick(e, closeToast) : closeToast?.();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const icon = useMemo(() => getIcon(appearance), [appearance]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div className={cn(styles.container, className)} {...extractSupportProps(rest)} data-appearance={appearance}>
|
|
56
|
+
<div className={styles.icon}>{icon}</div>
|
|
57
|
+
|
|
58
|
+
<div className={styles.content}>
|
|
59
|
+
<div>
|
|
60
|
+
<span className={styles.title}>
|
|
61
|
+
<TruncateString text={title} maxLines={1} hideTooltip data-test-id={TOAST_SYSTEM_EVENT_TEST_IDS.title} />
|
|
62
|
+
</span>
|
|
63
|
+
|
|
64
|
+
{description && (
|
|
65
|
+
<span className={styles.description}>
|
|
66
|
+
<TruncateString
|
|
67
|
+
maxLines={4}
|
|
68
|
+
text={description}
|
|
69
|
+
hideTooltip
|
|
70
|
+
data-test-id={TOAST_SYSTEM_EVENT_TEST_IDS.description}
|
|
71
|
+
/>
|
|
72
|
+
</span>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
{link && (
|
|
77
|
+
<Link
|
|
78
|
+
text={link.text}
|
|
79
|
+
href={link.href}
|
|
80
|
+
size={Link.sizes.M}
|
|
81
|
+
onClick={link.onClick}
|
|
82
|
+
onColor={APPEARANCE_TO_ON_COLOR_MAP[appearance]}
|
|
83
|
+
data-test-id={TOAST_SYSTEM_EVENT_TEST_IDS.link}
|
|
84
|
+
onSurface={
|
|
85
|
+
appearance === ToastSystemEventAppearance.ErrorCritical
|
|
86
|
+
? Link.onSurfaces.Accent
|
|
87
|
+
: Link.onSurfaces.Background
|
|
88
|
+
}
|
|
89
|
+
/>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
{closable && (
|
|
94
|
+
<button
|
|
95
|
+
className={styles.buttonClose}
|
|
96
|
+
onClick={handleCloseClick}
|
|
97
|
+
data-test-id={TOAST_SYSTEM_EVENT_TEST_IDS.buttonClose}
|
|
98
|
+
// TODO add translations
|
|
99
|
+
aria-label='close notification'
|
|
100
|
+
>
|
|
101
|
+
<CrossSVG />
|
|
102
|
+
</button>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{progressBar && (
|
|
106
|
+
<div
|
|
107
|
+
role='progressbar'
|
|
108
|
+
// TODO add translations
|
|
109
|
+
aria-label='progressbar'
|
|
110
|
+
data-test-id={TOAST_SYSTEM_EVENT_TEST_IDS.progressbar}
|
|
111
|
+
className={styles.progress}
|
|
112
|
+
style={{ animationDuration: `${AUTO_CLOSE_TIME[ToasterType.SystemEvent]}ms` }}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ToastSystemEvent.appearances = ToastSystemEventAppearance;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OnColor } from '@snack-uikit/link';
|
|
2
|
+
|
|
3
|
+
export enum ToastSystemEventAppearance {
|
|
4
|
+
Neutral = 'neutral',
|
|
5
|
+
Error = 'error',
|
|
6
|
+
ErrorCritical = 'errorCritical',
|
|
7
|
+
Warning = 'warning',
|
|
8
|
+
Success = 'success',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const APPEARANCE_TO_ON_COLOR_MAP = {
|
|
12
|
+
[ToastSystemEventAppearance.Neutral]: OnColor.InvertNeutral,
|
|
13
|
+
[ToastSystemEventAppearance.Error]: OnColor.InvertNeutral,
|
|
14
|
+
[ToastSystemEventAppearance.ErrorCritical]: OnColor.Red,
|
|
15
|
+
[ToastSystemEventAppearance.Warning]: OnColor.InvertNeutral,
|
|
16
|
+
[ToastSystemEventAppearance.Success]: OnColor.InvertNeutral,
|
|
17
|
+
} as const;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ToastSystemEvent';
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-toaster-toasterSystemEvent';
|
|
2
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
|
|
3
|
+
@import '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
|
|
4
|
+
|
|
5
|
+
@mixin colorMap($background-color, $icon-color, $title-color, $description-color, $progress-color) {
|
|
6
|
+
background-color: $background-color;
|
|
7
|
+
|
|
8
|
+
.icon {
|
|
9
|
+
color: $icon-color;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.title {
|
|
13
|
+
color: $title-color;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.description {
|
|
17
|
+
color: $description-color;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.progress {
|
|
21
|
+
background-color: $progress-color;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.icon {
|
|
26
|
+
svg {
|
|
27
|
+
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
28
|
+
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.buttonClose {
|
|
33
|
+
@include composite-var($toaster-system-event-toast-button-close);
|
|
34
|
+
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
margin: 0;
|
|
43
|
+
padding: 0;
|
|
44
|
+
|
|
45
|
+
color: $sys-invert-neutral-text-light;
|
|
46
|
+
|
|
47
|
+
background-color: transparent;
|
|
48
|
+
border: none;
|
|
49
|
+
|
|
50
|
+
svg {
|
|
51
|
+
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
52
|
+
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&:hover {
|
|
56
|
+
color: $sys-invert-neutral-text-main;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&:focus,
|
|
60
|
+
&:active {
|
|
61
|
+
color: $sys-invert-neutral-accent-pressed;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&:focus-visible {
|
|
65
|
+
@include outline-var($container-focused-s);
|
|
66
|
+
|
|
67
|
+
color: $sys-invert-neutral-text-main;
|
|
68
|
+
outline-color: $sys-available-on-complementary;
|
|
69
|
+
outline-offset: $spacing-state-focus-offset;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.content {
|
|
74
|
+
@include composite-var($toaster-system-event-toast-content);
|
|
75
|
+
|
|
76
|
+
display: flex;
|
|
77
|
+
flex: 1;
|
|
78
|
+
flex-direction: column;
|
|
79
|
+
word-break: break-word;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.title {
|
|
83
|
+
@include composite-var($sans-title-s);
|
|
84
|
+
|
|
85
|
+
display: grid;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.description {
|
|
89
|
+
@include composite-var($sans-body-m);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@keyframes progressBarAnimation {
|
|
93
|
+
0% {
|
|
94
|
+
width: 100%;
|
|
95
|
+
}
|
|
96
|
+
100% {
|
|
97
|
+
width: 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.progress {
|
|
102
|
+
@include composite-var($toaster-system-event-toast-progress-bar);
|
|
103
|
+
|
|
104
|
+
position: absolute;
|
|
105
|
+
bottom: 0;
|
|
106
|
+
left: 0;
|
|
107
|
+
|
|
108
|
+
width: 0;
|
|
109
|
+
|
|
110
|
+
animation: progressBarAnimation linear 1 forwards;
|
|
111
|
+
animation-play-state: active;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.container {
|
|
115
|
+
@include composite-var($toaster-system-event-toast-container);
|
|
116
|
+
|
|
117
|
+
cursor: default;
|
|
118
|
+
|
|
119
|
+
position: relative;
|
|
120
|
+
|
|
121
|
+
overflow: hidden;
|
|
122
|
+
display: flex;
|
|
123
|
+
|
|
124
|
+
box-sizing: border-box;
|
|
125
|
+
|
|
126
|
+
&:hover .progress {
|
|
127
|
+
animation-play-state: paused;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
&[data-appearance='neutral'] {
|
|
132
|
+
@include colorMap(
|
|
133
|
+
$sys-invert-neutral-background,
|
|
134
|
+
$sys-invert-neutral-accent-default,
|
|
135
|
+
$sys-invert-neutral-text-main,
|
|
136
|
+
$sys-invert-neutral-text-support,
|
|
137
|
+
$sys-neutral-accent-default
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
&[data-appearance='error'] {
|
|
142
|
+
@include colorMap(
|
|
143
|
+
$sys-invert-neutral-background,
|
|
144
|
+
$sys-red-accent-default,
|
|
145
|
+
$sys-invert-neutral-text-main,
|
|
146
|
+
$sys-invert-neutral-text-support,
|
|
147
|
+
$sys-red-accent-default
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&[data-appearance='errorCritical'] {
|
|
152
|
+
@include colorMap(
|
|
153
|
+
$sys-red-accent-default,
|
|
154
|
+
$sys-red-on-accent,
|
|
155
|
+
$sys-red-on-accent,
|
|
156
|
+
$sys-red-on-accent,
|
|
157
|
+
$sys-red-decor-activated
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
.buttonClose {
|
|
161
|
+
color: $sys-red-on-accent;
|
|
162
|
+
opacity: $opacity-a064;
|
|
163
|
+
|
|
164
|
+
&:hover,
|
|
165
|
+
&:focus-visible {
|
|
166
|
+
opacity: 1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
&:active {
|
|
170
|
+
opacity: $opacity-a048;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&[data-appearance='warning'] {
|
|
176
|
+
@include colorMap(
|
|
177
|
+
$sys-invert-neutral-background,
|
|
178
|
+
$sys-yellow-accent-default,
|
|
179
|
+
$sys-invert-neutral-text-main,
|
|
180
|
+
$sys-invert-neutral-text-support,
|
|
181
|
+
$sys-yellow-accent-default
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&[data-appearance='success'] {
|
|
186
|
+
@include colorMap(
|
|
187
|
+
$sys-invert-neutral-background,
|
|
188
|
+
$sys-green-accent-default,
|
|
189
|
+
$sys-invert-neutral-text-main,
|
|
190
|
+
$sys-invert-neutral-text-support,
|
|
191
|
+
$sys-green-accent-default
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|