@snack-uikit/toaster 0.5.5 → 0.6.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 CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.6.0 (2024-01-24)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-4182:** add onClose callback prop ([6046778](https://github.com/cloud-ru-tech/snack-uikit/commit/60467789d5e6bc940e3f7cf902df7da69b0a0e0b))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.5.5 (2024-01-23)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -11,10 +11,10 @@
11
11
  import { toaster } from '@snack-uikit/toaster';
12
12
 
13
13
  // create userAction toast
14
- const userActionId = await toaster.userAction.success({ label });
14
+ const userActionId = await toaster.userAction.success({ label, id });
15
15
 
16
16
  // create systemEvent toast
17
- const systemEventId = await toaster.systemEvent.success({ title, description });
17
+ const systemEventId = await toaster.systemEvent.success({ title, description, id });
18
18
 
19
19
  // update userAction toast
20
20
  toaster.userAction.update.error(userActionId, { label: 'new text' });
@@ -47,6 +47,7 @@ type ToastUserActionProps = Partial<RtToastContentProps> &
47
47
  label: string;
48
48
  link?: ToastUserActionLink;
49
49
  className?: string;
50
+ onClose(id?: string | number): void;
50
51
  }>;
51
52
 
52
53
  type ToastSystemEventLink = {
@@ -64,6 +65,7 @@ type ToastSystemEventProps = Partial<RtToastContentProps> &
64
65
  closable?: boolean;
65
66
  className?: string;
66
67
  onCloseClick?(e: MouseEvent<HTMLButtonElement>, close?: () => void): void;
68
+ onClose(id?: string | number): void;
67
69
  }>;
68
70
  ```
69
71
 
@@ -2,6 +2,7 @@ import { MouseEvent } from 'react';
2
2
  import { ToastContentProps as RtToastContentProps } from 'react-toastify';
3
3
  import { WithSupportProps } from '@snack-uikit/utils';
4
4
  import { ButtonActionProps } from '../../helperComponents/ButtonAction';
5
+ import { ToasterId } from '../../types';
5
6
  import { ToastSystemEventAppearance } from './types';
6
7
  export type ToastSystemEventLink = {
7
8
  text: string;
@@ -17,6 +18,7 @@ export type ToastSystemEventProps = Partial<RtToastContentProps> & WithSupportPr
17
18
  closable?: boolean;
18
19
  className?: string;
19
20
  onCloseClick?(e: MouseEvent<HTMLButtonElement>, close?: () => void): void;
21
+ onClose?(id?: ToasterId): void;
20
22
  action?: ButtonActionProps[];
21
23
  loading?: never;
22
24
  }>;
@@ -1,6 +1,7 @@
1
1
  import { MouseEvent } from 'react';
2
2
  import { ToastContentProps as RtToastContentProps } from 'react-toastify';
3
3
  import { WithSupportProps } from '@snack-uikit/utils';
4
+ import { ToasterId } from '../../types';
4
5
  import { ToastUserActionAppearance } from './types';
5
6
  export type ToastUserActionLink = {
6
7
  text: string;
@@ -13,5 +14,6 @@ export type ToastUserActionProps = Partial<RtToastContentProps> & WithSupportPro
13
14
  link?: ToastUserActionLink;
14
15
  className?: string;
15
16
  loading?: boolean;
17
+ onClose?(id?: ToasterId): void;
16
18
  }>;
17
19
  export declare function ToastUserAction({ appearance, label, link, className, loading, ...rest }: ToastUserActionProps): import("react/jsx-runtime").JSX.Element;
package/dist/helpers.js CHANGED
@@ -23,6 +23,10 @@ function getToasterContainer({ type, toasterParent, containerProps, }) {
23
23
  function getToastOptions({ type, toastOptions, containerId, toasterProps, }) {
24
24
  return {
25
25
  toastId: toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.id,
26
+ onClose: ((data) => {
27
+ var _a;
28
+ (_a = toasterProps === null || toasterProps === void 0 ? void 0 : toasterProps.onClose) === null || _a === void 0 ? void 0 : _a.call(toasterProps, data === null || data === void 0 ? void 0 : data.id);
29
+ }),
26
30
  autoClose: (toasterProps === null || toasterProps === void 0 ? void 0 : toasterProps.loading) ? false : AUTO_CLOSE_TIME[type],
27
31
  containerId: containerId || `${TOASTER_CONTAINER_PREFIX}${type}`,
28
32
  };
package/dist/types.d.ts CHANGED
@@ -5,7 +5,7 @@ export type PromisedId = Promise<ToasterId>;
5
5
  export type ToastOptions = {
6
6
  id?: ToasterId;
7
7
  autoClose?: RtToastOptions['autoClose'];
8
- onClose?: RtToastOptions['onClose'];
8
+ onClose?(id?: ToasterId): void;
9
9
  };
10
10
  export declare enum ToasterType {
11
11
  SystemEvent = "system-event",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Toaster",
7
- "version": "0.5.5",
7
+ "version": "0.6.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -40,5 +40,5 @@
40
40
  "classnames": "2.3.2",
41
41
  "react-toastify": "9.1.3"
42
42
  },
43
- "gitHead": "c292f4c45173928f57cc5c9f3cb02efb26887b64"
43
+ "gitHead": "ef4e92aab9e2c187fe746a1520d884589994a80b"
44
44
  }
@@ -10,7 +10,7 @@ import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
10
10
  import { AUTO_CLOSE_TIME } from '../../constants';
11
11
  import { ButtonAction, ButtonActionProps } from '../../helperComponents/ButtonAction';
12
12
  import { TOAST_SYSTEM_EVENT_TEST_IDS } from '../../testIds';
13
- import { ToasterType } from '../../types';
13
+ import { ToasterId, ToasterType } from '../../types';
14
14
  import { APPEARANCE_TO_ON_COLOR_MAP } from './constants';
15
15
  import styles from './styles.module.scss';
16
16
  import { ToastSystemEventAppearance } from './types';
@@ -32,6 +32,7 @@ export type ToastSystemEventProps = Partial<RtToastContentProps> &
32
32
  closable?: boolean;
33
33
  className?: string;
34
34
  onCloseClick?(e: MouseEvent<HTMLButtonElement>, close?: () => void): void;
35
+ onClose?(id?: ToasterId): void;
35
36
  action?: ButtonActionProps[];
36
37
  loading?: never;
37
38
  }>;
@@ -7,6 +7,7 @@ import { Sun } from '@snack-uikit/loaders';
7
7
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
8
8
 
9
9
  import { TOAST_USER_ACTION_TEST_IDS } from '../../testIds';
10
+ import { ToasterId } from '../../types';
10
11
  import styles from './styles.module.scss';
11
12
  import { ToastUserActionAppearance } from './types';
12
13
  import { getIcon } from './utils';
@@ -24,6 +25,7 @@ export type ToastUserActionProps = Partial<RtToastContentProps> &
24
25
  link?: ToastUserActionLink;
25
26
  className?: string;
26
27
  loading?: boolean;
28
+ onClose?(id?: ToasterId): void;
27
29
  }>;
28
30
 
29
31
  export function ToastUserAction({
package/src/helpers.tsx CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from './constants';
19
19
  import {
20
20
  OpenToast,
21
+ SystemEventOptions,
21
22
  Toaster,
22
23
  ToasterId,
23
24
  ToasterPropsMap,
@@ -73,6 +74,9 @@ function getToastOptions<T extends keyof ToasterPropsMap>({
73
74
  }): RtToastOptions {
74
75
  return {
75
76
  toastId: toastOptions?.id,
77
+ onClose: ((data: { id: ToasterId }) => {
78
+ toasterProps?.onClose?.(data?.id);
79
+ }) as RtToastOptions['onClose'],
76
80
  autoClose: toasterProps?.loading ? false : AUTO_CLOSE_TIME[type],
77
81
  containerId: containerId || `${TOASTER_CONTAINER_PREFIX}${type}`,
78
82
  };
@@ -211,35 +215,35 @@ const userAction = {
211
215
  };
212
216
 
213
217
  const systemEvent = {
214
- success(options: ToastSystemEventProps) {
218
+ success(options: SystemEventOptions) {
215
219
  return openToast({
216
220
  type: ToasterType.SystemEvent,
217
221
  toasterProps: { ...options, appearance: 'success' },
218
222
  });
219
223
  },
220
224
 
221
- neutral(options: ToastSystemEventProps) {
225
+ neutral(options: SystemEventOptions) {
222
226
  return openToast({
223
227
  type: ToasterType.SystemEvent,
224
228
  toasterProps: { ...options, appearance: 'neutral' },
225
229
  });
226
230
  },
227
231
 
228
- warning(options: ToastSystemEventProps) {
232
+ warning(options: SystemEventOptions) {
229
233
  return openToast({
230
234
  type: ToasterType.SystemEvent,
231
235
  toasterProps: { ...options, appearance: 'warning' },
232
236
  });
233
237
  },
234
238
 
235
- error(options: ToastSystemEventProps) {
239
+ error(options: SystemEventOptions) {
236
240
  return openToast({
237
241
  type: ToasterType.SystemEvent,
238
242
  toasterProps: { ...options, appearance: 'error' },
239
243
  });
240
244
  },
241
245
 
242
- errorCritical(options: ToastSystemEventProps) {
246
+ errorCritical(options: SystemEventOptions) {
243
247
  return openToast({
244
248
  type: ToasterType.SystemEvent,
245
249
  toasterProps: { ...options, appearance: 'errorCritical' },
@@ -247,35 +251,35 @@ const systemEvent = {
247
251
  },
248
252
 
249
253
  update: {
250
- success(id: ToasterId, options: ToastSystemEventProps) {
254
+ success(id: ToasterId, options: SystemEventOptions) {
251
255
  return updateToast(id, {
252
256
  type: ToasterType.SystemEvent,
253
257
  toasterProps: { ...options, appearance: 'success' },
254
258
  });
255
259
  },
256
260
 
257
- neutral(id: ToasterId, options: ToastSystemEventProps) {
261
+ neutral(id: ToasterId, options: SystemEventOptions) {
258
262
  return updateToast(id, {
259
263
  type: ToasterType.SystemEvent,
260
264
  toasterProps: { ...options, appearance: 'neutral' },
261
265
  });
262
266
  },
263
267
 
264
- warning(id: ToasterId, options: ToastSystemEventProps) {
268
+ warning(id: ToasterId, options: SystemEventOptions) {
265
269
  return updateToast(id, {
266
270
  type: ToasterType.SystemEvent,
267
271
  toasterProps: { ...options, appearance: 'warning' },
268
272
  });
269
273
  },
270
274
 
271
- error(id: ToasterId, options: ToastSystemEventProps) {
275
+ error(id: ToasterId, options: SystemEventOptions) {
272
276
  return updateToast(id, {
273
277
  type: ToasterType.SystemEvent,
274
278
  toasterProps: { ...options, appearance: 'error' },
275
279
  });
276
280
  },
277
281
 
278
- errorCritical(id: ToasterId, options: ToastSystemEventProps) {
282
+ errorCritical(id: ToasterId, options: SystemEventOptions) {
279
283
  return updateToast(id, {
280
284
  type: ToasterType.SystemEvent,
281
285
  toasterProps: { ...options, appearance: 'errorCritical' },
package/src/types.ts CHANGED
@@ -8,7 +8,7 @@ export type PromisedId = Promise<ToasterId>;
8
8
  export type ToastOptions = {
9
9
  id?: ToasterId;
10
10
  autoClose?: RtToastOptions['autoClose'];
11
- onClose?: RtToastOptions['onClose'];
11
+ onClose?(id?: ToasterId): void;
12
12
  };
13
13
 
14
14
  export enum ToasterType {