rsuite 5.76.0 → 5.76.1

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
@@ -1,3 +1,12 @@
1
+ ## [5.76.1](https://github.com/rsuite/rsuite/compare/v5.76.0...v5.76.1) (2024-12-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **useToaster:** support dynamic container of useToaster with correct styles ([#4088](https://github.com/rsuite/rsuite/issues/4088)) ([62b1a12](https://github.com/rsuite/rsuite/commit/62b1a128bd0f68ddc22a5b0f1acf27c5bc56a69e))
7
+
8
+
9
+
1
10
  # [5.76.0](https://github.com/rsuite/rsuite/compare/v5.75.0...v5.76.0) (2024-12-20)
2
11
 
3
12
 
@@ -142,9 +142,7 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
142
142
  formattedMonthPattern: string;
143
143
  formattedDayPattern: string;
144
144
  shortDateFormat: string;
145
- shortTimeFormat: string; /**
146
- * The prefix of the component CSS class
147
- */
145
+ shortTimeFormat: string;
148
146
  dateLocale: any;
149
147
  } | undefined;
150
148
  Calendar?: {
@@ -165,9 +163,7 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
165
163
  formattedMonthPattern: string;
166
164
  formattedDayPattern: string;
167
165
  shortDateFormat: string;
168
- shortTimeFormat: string; /**
169
- * The prefix of the component CSS class
170
- */
166
+ shortTimeFormat: string;
171
167
  dateLocale: any;
172
168
  } | undefined;
173
169
  DatePicker?: {
@@ -188,9 +184,7 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
188
184
  formattedMonthPattern: string;
189
185
  formattedDayPattern: string;
190
186
  shortDateFormat: string;
191
- shortTimeFormat: string; /**
192
- * The prefix of the component CSS class
193
- */
187
+ shortTimeFormat: string;
194
188
  dateLocale: any;
195
189
  } | undefined;
196
190
  DateRangePicker?: {
@@ -212,14 +206,14 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
212
206
  formattedMonthPattern: string;
213
207
  formattedDayPattern: string;
214
208
  shortDateFormat: string;
215
- shortTimeFormat: string; /**
216
- * The prefix of the component CSS class
217
- */
209
+ shortTimeFormat: string;
218
210
  dateLocale: any;
219
211
  } | undefined;
220
212
  Combobox?: {
221
213
  noResultsText: string;
222
- placeholder: string;
214
+ placeholder: string; /**
215
+ * The locale object that contains the language and formatting rules for the date.
216
+ */
223
217
  searchPlaceholder: string;
224
218
  checkAll: string;
225
219
  } | undefined;
@@ -227,7 +221,9 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
227
221
  newItem: string;
228
222
  createOption: string;
229
223
  noResultsText: string;
230
- placeholder: string;
224
+ placeholder: string; /**
225
+ * The locale object that contains the language and formatting rules for the date.
226
+ */
231
227
  searchPlaceholder: string;
232
228
  checkAll: string;
233
229
  } | undefined;
@@ -235,7 +231,9 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
235
231
  newItem: string;
236
232
  createOption: string;
237
233
  noResultsText: string;
238
- placeholder: string;
234
+ placeholder: string; /**
235
+ * The locale object that contains the language and formatting rules for the date.
236
+ */
239
237
  searchPlaceholder: string;
240
238
  checkAll: string;
241
239
  } | undefined;
@@ -32,14 +32,15 @@ function CustomProvider(props) {
32
32
  _props$iconClassPrefi = props.iconClassPrefix,
33
33
  iconClassPrefix = _props$iconClassPrefi === void 0 ? classPrefix : _props$iconClassPrefi,
34
34
  theme = props.theme,
35
- container = props.toastContainer,
35
+ _props$toastContainer = props.toastContainer,
36
+ toastContainer = _props$toastContainer === void 0 ? _ToastContainer.defaultToasterContainer : _props$toastContainer,
36
37
  disableRipple = props.disableRipple,
37
38
  csp = props.csp,
38
39
  disableInlineStyles = props.disableInlineStyles,
39
40
  rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
40
41
  var toasters = (0, _react.useRef)(new Map());
41
42
  var _usePortal = (0, _hooks.usePortal)({
42
- container: container,
43
+ container: toastContainer,
43
44
  waitMount: true
44
45
  }),
45
46
  Portal = _usePortal.Portal;
@@ -49,9 +50,10 @@ function CustomProvider(props) {
49
50
  theme: theme,
50
51
  toasters: toasters,
51
52
  disableRipple: disableRipple,
52
- components: components
53
+ components: components,
54
+ toastContainer: toastContainer
53
55
  }, rest);
54
- }, [classPrefix, theme, disableRipple, components, rest]);
56
+ }, [classPrefix, theme, disableRipple, components, toastContainer, rest]);
55
57
  var iconContext = (0, _react.useMemo)(function () {
56
58
  return {
57
59
  classPrefix: iconClassPrefix,
@@ -13,7 +13,6 @@ export { placementPolyfill } from './placementPolyfill';
13
13
  export { mergeRefs } from './mergeRefs';
14
14
  export { shallowEqual, shallowEqualArray } from './shallowEqual';
15
15
  export { composeFunctions } from './composeFunctions';
16
- export { render } from './render';
17
16
  export { safeSetSelection } from './safeSetSelection';
18
17
  export { getStringLength } from './getStringLength';
19
18
  export { getDataGroupBy } from './getDataGroupBy';
@@ -20,7 +20,6 @@ var _exportNames = {
20
20
  shallowEqual: true,
21
21
  shallowEqualArray: true,
22
22
  composeFunctions: true,
23
- render: true,
24
23
  safeSetSelection: true,
25
24
  getStringLength: true,
26
25
  getDataGroupBy: true,
@@ -32,7 +31,7 @@ var _exportNames = {
32
31
  isFocusLeaving: true,
33
32
  isFocusableElement: true
34
33
  };
35
- exports.warnOnce = exports.tplTransform = exports.stringifyReactNode = exports.shallowEqualArray = exports.shallowEqual = exports.safeSetSelection = exports.render = exports.reactToString = exports.prefix = exports.placementPolyfill = exports.mergeRefs = exports.isOneOf = exports.isFocusableElement = exports.isFocusLeaving = exports.isFocusEntering = exports.guid = exports.getStringLength = exports.getSafeRegExpString = exports.getDataGroupBy = exports.getDOMNode = exports.getClassNamePrefix = exports.deprecateComponent = exports.defaultClassPrefix = exports.createComponent = exports.createChainedFunction = exports.composeFunctions = exports.attachParent = exports.ReactChildren = void 0;
34
+ exports.warnOnce = exports.tplTransform = exports.stringifyReactNode = exports.shallowEqualArray = exports.shallowEqual = exports.safeSetSelection = exports.reactToString = exports.prefix = exports.placementPolyfill = exports.mergeRefs = exports.isOneOf = exports.isFocusableElement = exports.isFocusLeaving = exports.isFocusEntering = exports.guid = exports.getStringLength = exports.getSafeRegExpString = exports.getDataGroupBy = exports.getDOMNode = exports.getClassNamePrefix = exports.deprecateComponent = exports.defaultClassPrefix = exports.createComponent = exports.createChainedFunction = exports.composeFunctions = exports.attachParent = exports.ReactChildren = void 0;
36
35
  var _BrowserDetection = require("./BrowserDetection");
37
36
  Object.keys(_BrowserDetection).forEach(function (key) {
38
37
  if (key === "default" || key === "__esModule") return;
@@ -77,8 +76,6 @@ exports.shallowEqual = _shallowEqual.shallowEqual;
77
76
  exports.shallowEqualArray = _shallowEqual.shallowEqualArray;
78
77
  var _composeFunctions = require("./composeFunctions");
79
78
  exports.composeFunctions = _composeFunctions.composeFunctions;
80
- var _render = require("./render");
81
- exports.render = _render.render;
82
79
  var _safeSetSelection = require("./safeSetSelection");
83
80
  exports.safeSetSelection = _safeSetSelection.safeSetSelection;
84
81
  var _getStringLength = require("./getStringLength");
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { WithAsProps, RsRefForwardingComponent } from '../internals/types';
3
+ export declare const defaultToasterContainer: HTMLElement;
3
4
  export type PlacementType = 'topCenter' | 'bottomCenter' | 'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd';
4
5
  export declare const toastPlacements: PlacementType[];
5
6
  export interface ToastContainerProps extends WithAsProps {
@@ -21,10 +22,6 @@ export interface ToastContainerProps extends WithAsProps {
21
22
  * Reset the hide timer if the mouse moves over the message.
22
23
  */
23
24
  mouseReset?: boolean;
24
- /**
25
- * Callback fired when the component mounts
26
- */
27
- callback?: (ref: React.RefObject<ToastContainerInstance>) => void;
28
25
  }
29
26
  interface PushOptions {
30
27
  duration?: number;
@@ -32,7 +29,6 @@ interface PushOptions {
32
29
  container?: HTMLElement | (() => HTMLElement);
33
30
  }
34
31
  export interface ToastContainerInstance {
35
- root: HTMLElement;
36
32
  push: (message: React.ReactNode, options?: PushOptions) => string;
37
33
  remove: (key: string) => void;
38
34
  clear: () => void;
@@ -41,8 +37,12 @@ export interface ToastContainerInstance {
41
37
  export interface NodeProps extends WithAsProps {
42
38
  onClose?: (event?: React.MouseEvent<HTMLDivElement>) => void;
43
39
  }
40
+ export type GetInstancePropsType = Omit<ToastContainerProps, 'container' | 'placement'> & {
41
+ container: HTMLElement;
42
+ placement: PlacementType;
43
+ };
44
44
  interface ToastContainerComponent extends RsRefForwardingComponent<'div', ToastContainerProps> {
45
- getInstance: (props: ToastContainerProps) => Promise<[React.RefObject<ToastContainerInstance>, () => void]>;
45
+ getInstance: (props: GetInstancePropsType) => Promise<[React.RefObject<ToastContainerInstance>, string]>;
46
46
  }
47
47
  declare const ToastContainer: ToastContainerComponent;
48
48
  export default ToastContainer;
@@ -3,22 +3,25 @@
3
3
 
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
5
  exports.__esModule = true;
6
- exports.toastPlacements = exports.default = void 0;
6
+ exports.toastPlacements = exports.defaultToasterContainer = exports.default = void 0;
7
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
8
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
7
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
8
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
11
  var _react = _interopRequireWildcard(require("react"));
10
- var _reactDom = require("react-dom");
11
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
12
13
  var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
13
14
  var _Transition = _interopRequireDefault(require("../Animation/Transition"));
14
15
  var _hooks = require("../internals/hooks");
15
16
  var _utils = require("../internals/utils");
16
17
  var _ToastContext = _interopRequireDefault(require("./ToastContext"));
17
- var _excluded = ["as", "className", "classPrefix", "placement", "callback"],
18
+ var _render = require("./render");
19
+ var _excluded = ["as", "className", "classPrefix", "placement"],
18
20
  _excluded2 = ["className"],
19
21
  _excluded3 = ["container"];
20
22
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
23
  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 && {}.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; }
24
+ var defaultToasterContainer = exports.defaultToasterContainer = document.body;
22
25
  var toastPlacements = exports.toastPlacements = ['topCenter', 'bottomCenter', 'topStart', 'topEnd', 'bottomStart', 'bottomEnd'];
23
26
  var useMessages = function useMessages() {
24
27
  var _useState = (0, _react.useState)([]),
@@ -87,7 +90,6 @@ var useMessages = function useMessages() {
87
90
  };
88
91
  };
89
92
  var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
90
- var rootRef = (0, _react.useRef)();
91
93
  var _props$as = props.as,
92
94
  Component = _props$as === void 0 ? 'div' : _props$as,
93
95
  className = props.className,
@@ -95,7 +97,6 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
95
97
  classPrefix = _props$classPrefix === void 0 ? 'toast-container' : _props$classPrefix,
96
98
  _props$placement = props.placement,
97
99
  placement = _props$placement === void 0 ? 'topCenter' : _props$placement,
98
- callback = props.callback,
99
100
  rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
100
101
  var _useClassNames = (0, _hooks.useClassNames)(classPrefix),
101
102
  withClassPrefix = _useClassNames.withClassPrefix,
@@ -109,7 +110,6 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
109
110
  messages = _useMessages.messages;
110
111
  (0, _react.useImperativeHandle)(ref, function () {
111
112
  return {
112
- root: rootRef.current,
113
113
  push: push,
114
114
  clear: clear,
115
115
  remove: remove
@@ -118,9 +118,15 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
118
118
  var elements = messages.map(function (item) {
119
119
  var mouseReset = item.mouseReset,
120
120
  duration = item.duration,
121
- node = item.node,
122
- container = item.container;
123
- var toastWithTransition = /*#__PURE__*/_react.default.createElement(_Transition.default, {
121
+ node = item.node;
122
+ return /*#__PURE__*/_react.default.createElement(_ToastContext.default.Provider, {
123
+ value: {
124
+ usedToaster: true,
125
+ mouseReset: mouseReset,
126
+ duration: duration
127
+ },
128
+ key: item.key
129
+ }, /*#__PURE__*/_react.default.createElement(_Transition.default, {
124
130
  in: item.visible,
125
131
  exitedClassName: rootPrefix('toast-fade-exited'),
126
132
  exitingClassName: rootPrefix('toast-fade-exiting'),
@@ -139,40 +145,44 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
139
145
  }),
140
146
  className: merge(rootPrefix('toast'), (_node$props2 = node.props) === null || _node$props2 === void 0 ? void 0 : _node$props2.className, transitionClassName)
141
147
  }));
142
- });
143
- return /*#__PURE__*/_react.default.createElement(_ToastContext.default.Provider, {
144
- value: {
145
- usedToaster: true,
146
- mouseReset: mouseReset,
147
- duration: duration
148
- },
149
- key: item.key
150
- }, container ? /*#__PURE__*/(0, _reactDom.createPortal)(toastWithTransition, typeof container === 'function' ? container() : container) : toastWithTransition);
148
+ }));
151
149
  });
152
150
  return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, rest, {
153
- ref: function ref(selfRef) {
154
- rootRef.current = selfRef;
155
- callback === null || callback === void 0 || callback(selfRef);
156
- },
157
151
  className: classes
158
152
  }), elements);
159
153
  });
160
- ToastContainer.getInstance = function (props) {
161
- var container = props.container,
162
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded3);
163
- var containerRef = /*#__PURE__*/_react.default.createRef();
164
- var containerElement = (typeof container === 'function' ? container() : container) || document.body;
165
- return new Promise(function (resolve) {
166
- var renderCallback = function renderCallback() {
167
- resolve([containerRef, unmount]);
168
- };
169
- var _render = (0, _utils.render)(/*#__PURE__*/_react.default.createElement(ToastContainer, (0, _extends2.default)({}, rest, {
170
- ref: containerRef,
171
- callback: renderCallback
172
- })), containerElement),
173
- unmount = _render.unmount;
174
- });
175
- };
154
+ ToastContainer.getInstance = /*#__PURE__*/function () {
155
+ var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(props) {
156
+ var container, rest, getRefResolve, getRefPromise, containerRef, containerId;
157
+ return _regenerator.default.wrap(function _callee$(_context) {
158
+ while (1) switch (_context.prev = _context.next) {
159
+ case 0:
160
+ container = props.container, rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded3);
161
+ getRefResolve = null;
162
+ getRefPromise = new Promise(function (res) {
163
+ getRefResolve = res;
164
+ });
165
+ containerRef = /*#__PURE__*/_react.default.createRef(); // promise containerId & containerRef all have value
166
+ containerId = (0, _render.render)(/*#__PURE__*/_react.default.createElement(ToastContainer, (0, _extends2.default)({}, rest, {
167
+ ref: function ref(_ref3) {
168
+ containerRef.current = _ref3;
169
+ getRefResolve && getRefResolve();
170
+ }
171
+ })), container);
172
+ _context.next = 7;
173
+ return getRefPromise;
174
+ case 7:
175
+ return _context.abrupt("return", [containerRef, containerId]);
176
+ case 8:
177
+ case "end":
178
+ return _context.stop();
179
+ }
180
+ }, _callee);
181
+ }));
182
+ return function (_x) {
183
+ return _ref2.apply(this, arguments);
184
+ };
185
+ }();
176
186
  ToastContainer.displayName = 'ToastContainer';
177
187
  ToastContainer.propTypes = {
178
188
  className: _propTypes.default.string,
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const toasterKeyOfContainerElement = "toasterId";
3
+ export declare function render(element: React.ReactElement<any>, container: HTMLElement): string;
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ exports.__esModule = true;
6
+ exports.render = render;
7
+ exports.toasterKeyOfContainerElement = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _utils = require("../internals/utils");
10
+ var ReactDOM = _interopRequireWildcard(require("react-dom"));
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
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 && {}.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
+ var majorVersion = parseInt(_react.default.version);
14
+ var SuperposedReactDOM = ReactDOM;
15
+ var toasterKeyOfContainerElement = exports.toasterKeyOfContainerElement = 'toasterId';
16
+ function render(element, container) {
17
+ var mountElement = document.createElement('div');
18
+ mountElement.className = 'rs-toaster-mount-element';
19
+ var containerElement = container;
20
+
21
+ // Add the detached element to the root
22
+ containerElement.appendChild(mountElement);
23
+ var newContainerId = (0, _utils.guid)();
24
+ if (!containerElement[toasterKeyOfContainerElement]) {
25
+ // attach the containerId to the containerElement
26
+ containerElement[toasterKeyOfContainerElement] = newContainerId;
27
+ }
28
+ if (majorVersion >= 18) {
29
+ /**
30
+ * ignore react 18 warnings
31
+ * Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".
32
+ */
33
+ ReactDOM['__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'].usingClientEntryPoint = true;
34
+ var createRoot = SuperposedReactDOM.createRoot;
35
+ var root = createRoot(mountElement, {
36
+ identifierPrefix: 'rs-root-'
37
+ });
38
+ root.render(element);
39
+ } else {
40
+ SuperposedReactDOM.render(element, mountElement);
41
+ }
42
+ return containerElement[toasterKeyOfContainerElement];
43
+ }
@@ -5,17 +5,20 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  exports.__esModule = true;
6
6
  exports.default = void 0;
7
7
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _ToastContainer = _interopRequireDefault(require("./ToastContainer"));
11
- var _excluded = ["placement"];
12
- var defaultContainerId = 'default';
11
+ var _ToastContainer = _interopRequireWildcard(require("./ToastContainer"));
12
+ var _render = require("./render");
13
+ var _excluded = ["placement", "container"];
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
+ 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 && {}.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
16
  var containers = new Map();
14
17
 
15
18
  /**
16
- * Create a container by Id.
17
- * @param containerId
18
- * @param options
19
+ * Create a container instance.
20
+ * @param placement
21
+ * @param props
19
22
  */
20
23
  function createContainer(_x, _x2) {
21
24
  return _createContainer.apply(this, arguments);
@@ -23,10 +26,11 @@ function createContainer(_x, _x2) {
23
26
  /**
24
27
  * Get the container by ID. Use default ID when ID is not available.
25
28
  * @param containerId
29
+ * @param placement
26
30
  */
27
31
  function _createContainer() {
28
- _createContainer = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(containerId, props) {
29
- var _yield$ToastContainer, container;
32
+ _createContainer = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(placement, props) {
33
+ var _yield$ToastContainer, container, containerId;
30
34
  return _regenerator.default.wrap(function _callee$(_context) {
31
35
  while (1) switch (_context.prev = _context.next) {
32
36
  case 0:
@@ -35,9 +39,10 @@ function _createContainer() {
35
39
  case 2:
36
40
  _yield$ToastContainer = _context.sent;
37
41
  container = _yield$ToastContainer[0];
38
- containers.set(containerId || defaultContainerId, container);
42
+ containerId = _yield$ToastContainer[1];
43
+ containers.set(containerId + "_" + placement, container);
39
44
  return _context.abrupt("return", container);
40
- case 6:
45
+ case 7:
41
46
  case "end":
42
47
  return _context.stop();
43
48
  }
@@ -45,11 +50,8 @@ function _createContainer() {
45
50
  }));
46
51
  return _createContainer.apply(this, arguments);
47
52
  }
48
- function getContainer(containerId) {
49
- if (containers.size == 0) {
50
- return null;
51
- }
52
- return containers.get(containerId || defaultContainerId);
53
+ function getContainer(containerId, placement) {
54
+ return containers.get(containerId + "_" + placement);
53
55
  }
54
56
  var _toaster = function toaster(message) {
55
57
  return _toaster.push(message);
@@ -59,13 +61,24 @@ _toaster.push = function (message, options) {
59
61
  options = {};
60
62
  }
61
63
  var _options = options,
62
- containerId = _options.placement,
64
+ _options$placement = _options.placement,
65
+ placement = _options$placement === void 0 ? 'topCenter' : _options$placement,
66
+ container = _options.container,
63
67
  restOptions = (0, _objectWithoutPropertiesLoose2.default)(_options, _excluded);
64
- var container = getContainer(containerId);
65
- if (container !== null && container !== void 0 && container.current) {
66
- return container.current.push(message, restOptions);
68
+ var containerElement = (typeof container === 'function' ? container() : container) || _ToastContainer.defaultToasterContainer;
69
+ var containerElementId = containerElement[_render.toasterKeyOfContainerElement];
70
+ if (containerElementId) {
71
+ var existedContainer = getContainer(containerElementId, placement);
72
+ if (existedContainer) {
73
+ var _existedContainer$cur;
74
+ return (_existedContainer$cur = existedContainer.current) === null || _existedContainer$cur === void 0 ? void 0 : _existedContainer$cur.push(message, restOptions);
75
+ }
67
76
  }
68
- return createContainer(containerId !== null && containerId !== void 0 ? containerId : '', options).then(function (ref) {
77
+ var newOptions = (0, _extends2.default)({}, options, {
78
+ container: containerElement,
79
+ placement: placement
80
+ });
81
+ return createContainer(placement, newOptions).then(function (ref) {
69
82
  var _ref$current;
70
83
  return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message, restOptions);
71
84
  });
@@ -19,7 +19,8 @@ var _CustomProvider = require("../CustomProvider/CustomProvider");
19
19
  */
20
20
  var useToaster = function useToaster() {
21
21
  var _useContext = (0, _react.useContext)(_CustomProvider.CustomContext),
22
- toasters = _useContext.toasters;
22
+ toasters = _useContext.toasters,
23
+ toastContainer = _useContext.toastContainer;
23
24
  return (0, _react.useMemo)(function () {
24
25
  return {
25
26
  /**
@@ -31,9 +32,13 @@ var useToaster = function useToaster() {
31
32
  * @returns The key of the toast message.
32
33
  */
33
34
  push: function push(message, options) {
34
- var _toasters$current;
35
- var customToaster = toasters === null || toasters === void 0 || (_toasters$current = toasters.current) === null || _toasters$current === void 0 ? void 0 : _toasters$current.get((options === null || options === void 0 ? void 0 : options.placement) || 'topCenter');
36
- return customToaster ? customToaster.push(message, options) : _toaster.default.push(message, options);
35
+ var container = (typeof (options === null || options === void 0 ? void 0 : options.container) === 'function' ? options === null || options === void 0 ? void 0 : options.container() : options === null || options === void 0 ? void 0 : options.container) || toastContainer;
36
+ if (container === toastContainer) {
37
+ var _toasters$current;
38
+ return toasters === null || toasters === void 0 || (_toasters$current = toasters.current) === null || _toasters$current === void 0 || (_toasters$current = _toasters$current.get((options === null || options === void 0 ? void 0 : options.placement) || 'topCenter')) === null || _toasters$current === void 0 ? void 0 : _toasters$current.push(message, options);
39
+ } else {
40
+ return _toaster.default.push(message, options);
41
+ }
37
42
  },
38
43
  /**
39
44
  * Remove a toast message.
@@ -55,6 +60,6 @@ var useToaster = function useToaster() {
55
60
  }) : _toaster.default.clear();
56
61
  }
57
62
  };
58
- }, [toasters]);
63
+ }, [toastContainer, toasters]);
59
64
  };
60
65
  var _default = exports.default = useToaster;