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 +9 -0
- package/cjs/CustomProvider/CustomProvider.d.ts +13 -15
- package/cjs/CustomProvider/CustomProvider.js +6 -4
- package/cjs/internals/utils/index.d.ts +0 -1
- package/cjs/internals/utils/index.js +1 -4
- package/cjs/toaster/ToastContainer.d.ts +6 -6
- package/cjs/toaster/ToastContainer.js +48 -38
- package/cjs/toaster/render.d.ts +3 -0
- package/cjs/toaster/render.js +43 -0
- package/cjs/toaster/toaster.js +33 -20
- package/cjs/useToaster/useToaster.js +10 -5
- package/dist/rsuite.js +18 -18
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/CustomProvider/CustomProvider.d.ts +13 -15
- package/esm/CustomProvider/CustomProvider.js +7 -5
- package/esm/internals/utils/index.d.ts +0 -1
- package/esm/internals/utils/index.js +0 -1
- package/esm/toaster/ToastContainer.d.ts +6 -6
- package/esm/toaster/ToastContainer.js +49 -39
- package/esm/toaster/render.d.ts +3 -0
- package/esm/toaster/render.js +35 -0
- package/esm/toaster/toaster.js +31 -20
- package/esm/useToaster/useToaster.js +10 -5
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -7,7 +7,7 @@ import IconProvider from '@rsuite/icons/IconProvider';
|
|
|
7
7
|
import { usePortal, useIsomorphicLayoutEffect } from "../internals/hooks/index.js";
|
|
8
8
|
import { getClassNamePrefix, prefix } from "../internals/utils/prefix.js";
|
|
9
9
|
import { addClass, removeClass, canUseDOM } from "../DOMHelper/index.js";
|
|
10
|
-
import ToastContainer, { toastPlacements } from "../toaster/ToastContainer.js";
|
|
10
|
+
import ToastContainer, { toastPlacements, defaultToasterContainer } from "../toaster/ToastContainer.js";
|
|
11
11
|
export var CustomContext = /*#__PURE__*/React.createContext({});
|
|
12
12
|
var themes = ['light', 'dark', 'high-contrast'];
|
|
13
13
|
|
|
@@ -24,14 +24,15 @@ export default function CustomProvider(props) {
|
|
|
24
24
|
_props$iconClassPrefi = props.iconClassPrefix,
|
|
25
25
|
iconClassPrefix = _props$iconClassPrefi === void 0 ? classPrefix : _props$iconClassPrefi,
|
|
26
26
|
theme = props.theme,
|
|
27
|
-
|
|
27
|
+
_props$toastContainer = props.toastContainer,
|
|
28
|
+
toastContainer = _props$toastContainer === void 0 ? defaultToasterContainer : _props$toastContainer,
|
|
28
29
|
disableRipple = props.disableRipple,
|
|
29
30
|
csp = props.csp,
|
|
30
31
|
disableInlineStyles = props.disableInlineStyles,
|
|
31
32
|
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
32
33
|
var toasters = useRef(new Map());
|
|
33
34
|
var _usePortal = usePortal({
|
|
34
|
-
container:
|
|
35
|
+
container: toastContainer,
|
|
35
36
|
waitMount: true
|
|
36
37
|
}),
|
|
37
38
|
Portal = _usePortal.Portal;
|
|
@@ -41,9 +42,10 @@ export default function CustomProvider(props) {
|
|
|
41
42
|
theme: theme,
|
|
42
43
|
toasters: toasters,
|
|
43
44
|
disableRipple: disableRipple,
|
|
44
|
-
components: components
|
|
45
|
+
components: components,
|
|
46
|
+
toastContainer: toastContainer
|
|
45
47
|
}, rest);
|
|
46
|
-
}, [classPrefix, theme, disableRipple, components, rest]);
|
|
48
|
+
}, [classPrefix, theme, disableRipple, components, toastContainer, rest]);
|
|
47
49
|
var iconContext = useMemo(function () {
|
|
48
50
|
return {
|
|
49
51
|
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';
|
|
@@ -14,7 +14,6 @@ export { placementPolyfill } from "./placementPolyfill.js";
|
|
|
14
14
|
export { mergeRefs } from "./mergeRefs.js";
|
|
15
15
|
export { shallowEqual, shallowEqualArray } from "./shallowEqual.js";
|
|
16
16
|
export { composeFunctions } from "./composeFunctions.js";
|
|
17
|
-
export { render } from "./render.js";
|
|
18
17
|
export { safeSetSelection } from "./safeSetSelection.js";
|
|
19
18
|
export { getStringLength } from "./getStringLength.js";
|
|
20
19
|
export { getDataGroupBy } from "./getDataGroupBy.js";
|
|
@@ -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:
|
|
45
|
+
getInstance: (props: GetInstancePropsType) => Promise<[React.RefObject<ToastContainerInstance>, string]>;
|
|
46
46
|
}
|
|
47
47
|
declare const ToastContainer: ToastContainerComponent;
|
|
48
48
|
export default ToastContainer;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
4
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
var _excluded = ["as", "className", "classPrefix", "placement"
|
|
5
|
+
var _excluded = ["as", "className", "classPrefix", "placement"],
|
|
5
6
|
_excluded2 = ["className"],
|
|
6
7
|
_excluded3 = ["container"];
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
8
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
|
+
import React, { useState, useImperativeHandle, useCallback } from 'react';
|
|
9
10
|
import PropTypes from 'prop-types';
|
|
10
11
|
import kebabCase from 'lodash/kebabCase';
|
|
11
12
|
import Transition from "../Animation/Transition.js";
|
|
12
13
|
import { useClassNames } from "../internals/hooks/index.js";
|
|
13
|
-
import { guid, createChainedFunction
|
|
14
|
+
import { guid, createChainedFunction } from "../internals/utils/index.js";
|
|
14
15
|
import ToastContext from "./ToastContext.js";
|
|
16
|
+
import { render } from "./render.js";
|
|
17
|
+
export var defaultToasterContainer = document.body;
|
|
15
18
|
export var toastPlacements = ['topCenter', 'bottomCenter', 'topStart', 'topEnd', 'bottomStart', 'bottomEnd'];
|
|
16
19
|
var useMessages = function useMessages() {
|
|
17
20
|
var _useState = useState([]),
|
|
@@ -80,7 +83,6 @@ var useMessages = function useMessages() {
|
|
|
80
83
|
};
|
|
81
84
|
};
|
|
82
85
|
var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
83
|
-
var rootRef = useRef();
|
|
84
86
|
var _props$as = props.as,
|
|
85
87
|
Component = _props$as === void 0 ? 'div' : _props$as,
|
|
86
88
|
className = props.className,
|
|
@@ -88,7 +90,6 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
88
90
|
classPrefix = _props$classPrefix === void 0 ? 'toast-container' : _props$classPrefix,
|
|
89
91
|
_props$placement = props.placement,
|
|
90
92
|
placement = _props$placement === void 0 ? 'topCenter' : _props$placement,
|
|
91
|
-
callback = props.callback,
|
|
92
93
|
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
93
94
|
var _useClassNames = useClassNames(classPrefix),
|
|
94
95
|
withClassPrefix = _useClassNames.withClassPrefix,
|
|
@@ -102,7 +103,6 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
102
103
|
messages = _useMessages.messages;
|
|
103
104
|
useImperativeHandle(ref, function () {
|
|
104
105
|
return {
|
|
105
|
-
root: rootRef.current,
|
|
106
106
|
push: push,
|
|
107
107
|
clear: clear,
|
|
108
108
|
remove: remove
|
|
@@ -111,9 +111,15 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
111
111
|
var elements = messages.map(function (item) {
|
|
112
112
|
var mouseReset = item.mouseReset,
|
|
113
113
|
duration = item.duration,
|
|
114
|
-
node = item.node
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
node = item.node;
|
|
115
|
+
return /*#__PURE__*/React.createElement(ToastContext.Provider, {
|
|
116
|
+
value: {
|
|
117
|
+
usedToaster: true,
|
|
118
|
+
mouseReset: mouseReset,
|
|
119
|
+
duration: duration
|
|
120
|
+
},
|
|
121
|
+
key: item.key
|
|
122
|
+
}, /*#__PURE__*/React.createElement(Transition, {
|
|
117
123
|
in: item.visible,
|
|
118
124
|
exitedClassName: rootPrefix('toast-fade-exited'),
|
|
119
125
|
exitingClassName: rootPrefix('toast-fade-exiting'),
|
|
@@ -132,40 +138,44 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
132
138
|
}),
|
|
133
139
|
className: merge(rootPrefix('toast'), (_node$props2 = node.props) === null || _node$props2 === void 0 ? void 0 : _node$props2.className, transitionClassName)
|
|
134
140
|
}));
|
|
135
|
-
});
|
|
136
|
-
return /*#__PURE__*/React.createElement(ToastContext.Provider, {
|
|
137
|
-
value: {
|
|
138
|
-
usedToaster: true,
|
|
139
|
-
mouseReset: mouseReset,
|
|
140
|
-
duration: duration
|
|
141
|
-
},
|
|
142
|
-
key: item.key
|
|
143
|
-
}, container ? /*#__PURE__*/createPortal(toastWithTransition, typeof container === 'function' ? container() : container) : toastWithTransition);
|
|
141
|
+
}));
|
|
144
142
|
});
|
|
145
143
|
return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
146
|
-
ref: function ref(selfRef) {
|
|
147
|
-
rootRef.current = selfRef;
|
|
148
|
-
callback === null || callback === void 0 || callback(selfRef);
|
|
149
|
-
},
|
|
150
144
|
className: classes
|
|
151
145
|
}), elements);
|
|
152
146
|
});
|
|
153
|
-
ToastContainer.getInstance = function (
|
|
154
|
-
var
|
|
155
|
-
rest
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
147
|
+
ToastContainer.getInstance = /*#__PURE__*/function () {
|
|
148
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(props) {
|
|
149
|
+
var container, rest, getRefResolve, getRefPromise, containerRef, containerId;
|
|
150
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
151
|
+
while (1) switch (_context.prev = _context.next) {
|
|
152
|
+
case 0:
|
|
153
|
+
container = props.container, rest = _objectWithoutPropertiesLoose(props, _excluded3);
|
|
154
|
+
getRefResolve = null;
|
|
155
|
+
getRefPromise = new Promise(function (res) {
|
|
156
|
+
getRefResolve = res;
|
|
157
|
+
});
|
|
158
|
+
containerRef = /*#__PURE__*/React.createRef(); // promise containerId & containerRef all have value
|
|
159
|
+
containerId = render(/*#__PURE__*/React.createElement(ToastContainer, _extends({}, rest, {
|
|
160
|
+
ref: function ref(_ref3) {
|
|
161
|
+
containerRef.current = _ref3;
|
|
162
|
+
getRefResolve && getRefResolve();
|
|
163
|
+
}
|
|
164
|
+
})), container);
|
|
165
|
+
_context.next = 7;
|
|
166
|
+
return getRefPromise;
|
|
167
|
+
case 7:
|
|
168
|
+
return _context.abrupt("return", [containerRef, containerId]);
|
|
169
|
+
case 8:
|
|
170
|
+
case "end":
|
|
171
|
+
return _context.stop();
|
|
172
|
+
}
|
|
173
|
+
}, _callee);
|
|
174
|
+
}));
|
|
175
|
+
return function (_x) {
|
|
176
|
+
return _ref2.apply(this, arguments);
|
|
177
|
+
};
|
|
178
|
+
}();
|
|
169
179
|
ToastContainer.displayName = 'ToastContainer';
|
|
170
180
|
ToastContainer.propTypes = {
|
|
171
181
|
className: PropTypes.string,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { guid } from "../internals/utils/index.js";
|
|
4
|
+
import * as ReactDOM from 'react-dom';
|
|
5
|
+
var majorVersion = parseInt(React.version);
|
|
6
|
+
var SuperposedReactDOM = ReactDOM;
|
|
7
|
+
export var toasterKeyOfContainerElement = 'toasterId';
|
|
8
|
+
export function render(element, container) {
|
|
9
|
+
var mountElement = document.createElement('div');
|
|
10
|
+
mountElement.className = 'rs-toaster-mount-element';
|
|
11
|
+
var containerElement = container;
|
|
12
|
+
|
|
13
|
+
// Add the detached element to the root
|
|
14
|
+
containerElement.appendChild(mountElement);
|
|
15
|
+
var newContainerId = guid();
|
|
16
|
+
if (!containerElement[toasterKeyOfContainerElement]) {
|
|
17
|
+
// attach the containerId to the containerElement
|
|
18
|
+
containerElement[toasterKeyOfContainerElement] = newContainerId;
|
|
19
|
+
}
|
|
20
|
+
if (majorVersion >= 18) {
|
|
21
|
+
/**
|
|
22
|
+
* ignore react 18 warnings
|
|
23
|
+
* Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".
|
|
24
|
+
*/
|
|
25
|
+
ReactDOM['__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'].usingClientEntryPoint = true;
|
|
26
|
+
var createRoot = SuperposedReactDOM.createRoot;
|
|
27
|
+
var root = createRoot(mountElement, {
|
|
28
|
+
identifierPrefix: 'rs-root-'
|
|
29
|
+
});
|
|
30
|
+
root.render(element);
|
|
31
|
+
} else {
|
|
32
|
+
SuperposedReactDOM.render(element, mountElement);
|
|
33
|
+
}
|
|
34
|
+
return containerElement[toasterKeyOfContainerElement];
|
|
35
|
+
}
|
package/esm/toaster/toaster.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
4
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
-
var _excluded = ["placement"];
|
|
5
|
+
var _excluded = ["placement", "container"];
|
|
5
6
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
-
import ToastContainer from "./ToastContainer.js";
|
|
7
|
-
|
|
7
|
+
import ToastContainer, { defaultToasterContainer } from "./ToastContainer.js";
|
|
8
|
+
import { toasterKeyOfContainerElement } from "./render.js";
|
|
8
9
|
var containers = new Map();
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* Create a container
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
12
|
+
* Create a container instance.
|
|
13
|
+
* @param placement
|
|
14
|
+
* @param props
|
|
14
15
|
*/
|
|
15
16
|
function createContainer(_x, _x2) {
|
|
16
17
|
return _createContainer.apply(this, arguments);
|
|
@@ -18,10 +19,11 @@ function createContainer(_x, _x2) {
|
|
|
18
19
|
/**
|
|
19
20
|
* Get the container by ID. Use default ID when ID is not available.
|
|
20
21
|
* @param containerId
|
|
22
|
+
* @param placement
|
|
21
23
|
*/
|
|
22
24
|
function _createContainer() {
|
|
23
|
-
_createContainer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(
|
|
24
|
-
var _yield$ToastContainer, container;
|
|
25
|
+
_createContainer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(placement, props) {
|
|
26
|
+
var _yield$ToastContainer, container, containerId;
|
|
25
27
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
26
28
|
while (1) switch (_context.prev = _context.next) {
|
|
27
29
|
case 0:
|
|
@@ -30,9 +32,10 @@ function _createContainer() {
|
|
|
30
32
|
case 2:
|
|
31
33
|
_yield$ToastContainer = _context.sent;
|
|
32
34
|
container = _yield$ToastContainer[0];
|
|
33
|
-
|
|
35
|
+
containerId = _yield$ToastContainer[1];
|
|
36
|
+
containers.set(containerId + "_" + placement, container);
|
|
34
37
|
return _context.abrupt("return", container);
|
|
35
|
-
case
|
|
38
|
+
case 7:
|
|
36
39
|
case "end":
|
|
37
40
|
return _context.stop();
|
|
38
41
|
}
|
|
@@ -40,11 +43,8 @@ function _createContainer() {
|
|
|
40
43
|
}));
|
|
41
44
|
return _createContainer.apply(this, arguments);
|
|
42
45
|
}
|
|
43
|
-
function getContainer(containerId) {
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return containers.get(containerId || defaultContainerId);
|
|
46
|
+
function getContainer(containerId, placement) {
|
|
47
|
+
return containers.get(containerId + "_" + placement);
|
|
48
48
|
}
|
|
49
49
|
var _toaster = function toaster(message) {
|
|
50
50
|
return _toaster.push(message);
|
|
@@ -54,13 +54,24 @@ _toaster.push = function (message, options) {
|
|
|
54
54
|
options = {};
|
|
55
55
|
}
|
|
56
56
|
var _options = options,
|
|
57
|
-
|
|
57
|
+
_options$placement = _options.placement,
|
|
58
|
+
placement = _options$placement === void 0 ? 'topCenter' : _options$placement,
|
|
59
|
+
container = _options.container,
|
|
58
60
|
restOptions = _objectWithoutPropertiesLoose(_options, _excluded);
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
var containerElement = (typeof container === 'function' ? container() : container) || defaultToasterContainer;
|
|
62
|
+
var containerElementId = containerElement[toasterKeyOfContainerElement];
|
|
63
|
+
if (containerElementId) {
|
|
64
|
+
var existedContainer = getContainer(containerElementId, placement);
|
|
65
|
+
if (existedContainer) {
|
|
66
|
+
var _existedContainer$cur;
|
|
67
|
+
return (_existedContainer$cur = existedContainer.current) === null || _existedContainer$cur === void 0 ? void 0 : _existedContainer$cur.push(message, restOptions);
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
|
-
|
|
70
|
+
var newOptions = _extends({}, options, {
|
|
71
|
+
container: containerElement,
|
|
72
|
+
placement: placement
|
|
73
|
+
});
|
|
74
|
+
return createContainer(placement, newOptions).then(function (ref) {
|
|
64
75
|
var _ref$current;
|
|
65
76
|
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message, restOptions);
|
|
66
77
|
});
|
|
@@ -13,7 +13,8 @@ import { CustomContext } from "../CustomProvider/CustomProvider.js";
|
|
|
13
13
|
*/
|
|
14
14
|
var useToaster = function useToaster() {
|
|
15
15
|
var _useContext = useContext(CustomContext),
|
|
16
|
-
toasters = _useContext.toasters
|
|
16
|
+
toasters = _useContext.toasters,
|
|
17
|
+
toastContainer = _useContext.toastContainer;
|
|
17
18
|
return useMemo(function () {
|
|
18
19
|
return {
|
|
19
20
|
/**
|
|
@@ -25,9 +26,13 @@ var useToaster = function useToaster() {
|
|
|
25
26
|
* @returns The key of the toast message.
|
|
26
27
|
*/
|
|
27
28
|
push: function push(message, options) {
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
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;
|
|
30
|
+
if (container === toastContainer) {
|
|
31
|
+
var _toasters$current;
|
|
32
|
+
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);
|
|
33
|
+
} else {
|
|
34
|
+
return toaster.push(message, options);
|
|
35
|
+
}
|
|
31
36
|
},
|
|
32
37
|
/**
|
|
33
38
|
* Remove a toast message.
|
|
@@ -49,6 +54,6 @@ var useToaster = function useToaster() {
|
|
|
49
54
|
}) : toaster.clear();
|
|
50
55
|
}
|
|
51
56
|
};
|
|
52
|
-
}, [toasters]);
|
|
57
|
+
}, [toastContainer, toasters]);
|
|
53
58
|
};
|
|
54
59
|
export default useToaster;
|