rsuite 5.76.0 → 5.76.2
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 +18 -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 +52 -39
- package/cjs/toaster/render.d.ts +3 -0
- package/cjs/toaster/render.js +43 -0
- package/cjs/toaster/toaster.js +34 -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 +53 -40
- package/esm/toaster/render.d.ts +3 -0
- package/esm/toaster/render.js +35 -0
- package/esm/toaster/toaster.js +32 -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 | null;
|
|
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 | null;
|
|
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,23 @@
|
|
|
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
|
-
import { useClassNames } from "../internals/hooks/index.js";
|
|
13
|
-
import { guid, createChainedFunction, render } from "../internals/utils/index.js";
|
|
14
13
|
import ToastContext from "./ToastContext.js";
|
|
14
|
+
import canUseDOM from 'dom-lib/canUseDOM';
|
|
15
|
+
import { useClassNames } from "../internals/hooks/index.js";
|
|
16
|
+
import { guid, createChainedFunction } from "../internals/utils/index.js";
|
|
17
|
+
import { render } from "./render.js";
|
|
18
|
+
export var defaultToasterContainer = function defaultToasterContainer() {
|
|
19
|
+
return canUseDOM ? document.body : null;
|
|
20
|
+
};
|
|
15
21
|
export var toastPlacements = ['topCenter', 'bottomCenter', 'topStart', 'topEnd', 'bottomStart', 'bottomEnd'];
|
|
16
22
|
var useMessages = function useMessages() {
|
|
17
23
|
var _useState = useState([]),
|
|
@@ -80,7 +86,6 @@ var useMessages = function useMessages() {
|
|
|
80
86
|
};
|
|
81
87
|
};
|
|
82
88
|
var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
83
|
-
var rootRef = useRef();
|
|
84
89
|
var _props$as = props.as,
|
|
85
90
|
Component = _props$as === void 0 ? 'div' : _props$as,
|
|
86
91
|
className = props.className,
|
|
@@ -88,7 +93,6 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
88
93
|
classPrefix = _props$classPrefix === void 0 ? 'toast-container' : _props$classPrefix,
|
|
89
94
|
_props$placement = props.placement,
|
|
90
95
|
placement = _props$placement === void 0 ? 'topCenter' : _props$placement,
|
|
91
|
-
callback = props.callback,
|
|
92
96
|
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
93
97
|
var _useClassNames = useClassNames(classPrefix),
|
|
94
98
|
withClassPrefix = _useClassNames.withClassPrefix,
|
|
@@ -102,7 +106,6 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
102
106
|
messages = _useMessages.messages;
|
|
103
107
|
useImperativeHandle(ref, function () {
|
|
104
108
|
return {
|
|
105
|
-
root: rootRef.current,
|
|
106
109
|
push: push,
|
|
107
110
|
clear: clear,
|
|
108
111
|
remove: remove
|
|
@@ -111,9 +114,15 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
111
114
|
var elements = messages.map(function (item) {
|
|
112
115
|
var mouseReset = item.mouseReset,
|
|
113
116
|
duration = item.duration,
|
|
114
|
-
node = item.node
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
node = item.node;
|
|
118
|
+
return /*#__PURE__*/React.createElement(ToastContext.Provider, {
|
|
119
|
+
value: {
|
|
120
|
+
usedToaster: true,
|
|
121
|
+
mouseReset: mouseReset,
|
|
122
|
+
duration: duration
|
|
123
|
+
},
|
|
124
|
+
key: item.key
|
|
125
|
+
}, /*#__PURE__*/React.createElement(Transition, {
|
|
117
126
|
in: item.visible,
|
|
118
127
|
exitedClassName: rootPrefix('toast-fade-exited'),
|
|
119
128
|
exitingClassName: rootPrefix('toast-fade-exiting'),
|
|
@@ -132,40 +141,44 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
132
141
|
}),
|
|
133
142
|
className: merge(rootPrefix('toast'), (_node$props2 = node.props) === null || _node$props2 === void 0 ? void 0 : _node$props2.className, transitionClassName)
|
|
134
143
|
}));
|
|
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);
|
|
144
|
+
}));
|
|
144
145
|
});
|
|
145
146
|
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
147
|
className: classes
|
|
151
148
|
}), elements);
|
|
152
149
|
});
|
|
153
|
-
ToastContainer.getInstance = function (
|
|
154
|
-
var
|
|
155
|
-
rest
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
150
|
+
ToastContainer.getInstance = /*#__PURE__*/function () {
|
|
151
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(props) {
|
|
152
|
+
var container, rest, getRefResolve, getRefPromise, containerRef, containerId;
|
|
153
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
154
|
+
while (1) switch (_context.prev = _context.next) {
|
|
155
|
+
case 0:
|
|
156
|
+
container = props.container, rest = _objectWithoutPropertiesLoose(props, _excluded3);
|
|
157
|
+
getRefResolve = null;
|
|
158
|
+
getRefPromise = new Promise(function (res) {
|
|
159
|
+
getRefResolve = res;
|
|
160
|
+
});
|
|
161
|
+
containerRef = /*#__PURE__*/React.createRef(); // promise containerId & containerRef all have value
|
|
162
|
+
containerId = render(/*#__PURE__*/React.createElement(ToastContainer, _extends({}, rest, {
|
|
163
|
+
ref: function ref(_ref3) {
|
|
164
|
+
containerRef.current = _ref3;
|
|
165
|
+
getRefResolve && getRefResolve();
|
|
166
|
+
}
|
|
167
|
+
})), container);
|
|
168
|
+
_context.next = 7;
|
|
169
|
+
return getRefPromise;
|
|
170
|
+
case 7:
|
|
171
|
+
return _context.abrupt("return", [containerRef, containerId]);
|
|
172
|
+
case 8:
|
|
173
|
+
case "end":
|
|
174
|
+
return _context.stop();
|
|
175
|
+
}
|
|
176
|
+
}, _callee);
|
|
177
|
+
}));
|
|
178
|
+
return function (_x) {
|
|
179
|
+
return _ref2.apply(this, arguments);
|
|
180
|
+
};
|
|
181
|
+
}();
|
|
169
182
|
ToastContainer.displayName = 'ToastContainer';
|
|
170
183
|
ToastContainer.propTypes = {
|
|
171
184
|
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,25 @@ _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
|
+
_options$container = _options.container,
|
|
60
|
+
container = _options$container === void 0 ? defaultToasterContainer : _options$container,
|
|
58
61
|
restOptions = _objectWithoutPropertiesLoose(_options, _excluded);
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
var containerElement = typeof container === 'function' ? container() : container;
|
|
63
|
+
var containerElementId = containerElement ? containerElement[toasterKeyOfContainerElement] : null;
|
|
64
|
+
if (containerElementId) {
|
|
65
|
+
var existedContainer = getContainer(containerElementId, placement);
|
|
66
|
+
if (existedContainer) {
|
|
67
|
+
var _existedContainer$cur;
|
|
68
|
+
return (_existedContainer$cur = existedContainer.current) === null || _existedContainer$cur === void 0 ? void 0 : _existedContainer$cur.push(message, restOptions);
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
var newOptions = _extends({}, options, {
|
|
72
|
+
container: containerElement,
|
|
73
|
+
placement: placement
|
|
74
|
+
});
|
|
75
|
+
return createContainer(placement, newOptions).then(function (ref) {
|
|
64
76
|
var _ref$current;
|
|
65
77
|
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message, restOptions);
|
|
66
78
|
});
|
|
@@ -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;
|