@doist/reactist 20.2.0 → 20.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.
@@ -1262,24 +1262,44 @@ const InternalToast = /*#__PURE__*/React__default.forwardRef(function InternalTo
1262
1262
  clearTimeout(timeoutRef.current);
1263
1263
  timeoutRef.current = undefined;
1264
1264
  }, []);
1265
+ const removeToast = React__default.useCallback(function removeToast() {
1266
+ onRemoveToast(toastId);
1267
+ onDismiss == null ? void 0 : onDismiss();
1268
+ }, [onDismiss, onRemoveToast, toastId]);
1265
1269
  React__default.useEffect(function setupAutoDismiss() {
1266
1270
  if (!timeoutRunning || !autoDismissDelay) return;
1267
- timeoutRef.current = window.setTimeout(() => {
1268
- onRemoveToast(toastId);
1269
- onDismiss == null ? void 0 : onDismiss();
1270
- }, autoDismissDelay * 1000);
1271
+ timeoutRef.current = window.setTimeout(removeToast, autoDismissDelay * 1000);
1271
1272
  return stopTimeout;
1272
- }, [autoDismissDelay, onDismiss, onRemoveToast, toastId, stopTimeout, timeoutRunning]);
1273
+ }, [autoDismissDelay, removeToast, stopTimeout, timeoutRunning]);
1274
+ /**
1275
+ * If the action is toast action object and not a custom element,
1276
+ * the `onClick` property is wrapped in another handler responsible
1277
+ * for removing the toast when the action is triggered.
1278
+ */
1279
+
1280
+ const actionWithCustomActionHandler = React__default.useMemo(() => {
1281
+ if (!isActionObject(action)) {
1282
+ return action;
1283
+ }
1284
+
1285
+ return _objectSpread2(_objectSpread2({}, action), {}, {
1286
+ onClick: function handleActionClick() {
1287
+ if (!action) {
1288
+ return;
1289
+ }
1290
+
1291
+ action.onClick();
1292
+ removeToast();
1293
+ }
1294
+ });
1295
+ }, [action, removeToast]);
1273
1296
  return /*#__PURE__*/React__default.createElement(StaticToast, {
1274
1297
  ref: ref,
1275
1298
  message: message,
1276
1299
  description: description,
1277
1300
  icon: icon,
1278
- action: action,
1279
- onDismiss: showDismissButton ? () => {
1280
- onDismiss == null ? void 0 : onDismiss();
1281
- onRemoveToast(toastId);
1282
- } : undefined,
1301
+ action: actionWithCustomActionHandler,
1302
+ onDismiss: showDismissButton ? removeToast : undefined,
1283
1303
  dismissLabel: dismissLabel,
1284
1304
  // @ts-expect-error
1285
1305
  onMouseEnter: stopTimeout,