rsuite 5.75.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/Image/package.json +7 -0
  3. package/Image/styles/index.css +33 -0
  4. package/Image/styles/index.less +34 -0
  5. package/cjs/Carousel/Carousel.js +1 -0
  6. package/cjs/CustomProvider/CustomProvider.d.ts +13 -15
  7. package/cjs/CustomProvider/CustomProvider.js +6 -4
  8. package/cjs/CustomProvider/types.d.ts +2 -0
  9. package/cjs/Image/Image.d.ts +42 -0
  10. package/cjs/Image/Image.js +102 -0
  11. package/cjs/Image/ImageWrapper.d.ts +1 -0
  12. package/cjs/Image/ImageWrapper.js +10 -0
  13. package/cjs/Image/hooks/useImage.d.ts +14 -0
  14. package/cjs/Image/hooks/useImage.js +68 -0
  15. package/cjs/Image/index.d.ts +3 -0
  16. package/cjs/Image/index.js +8 -0
  17. package/cjs/index.d.ts +2 -0
  18. package/cjs/index.js +4 -2
  19. package/cjs/internals/utils/getDOMNode.js +2 -1
  20. package/cjs/internals/utils/index.d.ts +0 -1
  21. package/cjs/internals/utils/index.js +1 -4
  22. package/cjs/toaster/ToastContainer.d.ts +6 -6
  23. package/cjs/toaster/ToastContainer.js +48 -38
  24. package/cjs/toaster/render.d.ts +3 -0
  25. package/cjs/toaster/render.js +43 -0
  26. package/cjs/toaster/toaster.js +33 -20
  27. package/cjs/useToaster/useToaster.js +10 -5
  28. package/dist/rsuite-no-reset-rtl.css +34 -0
  29. package/dist/rsuite-no-reset-rtl.min.css +1 -1
  30. package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
  31. package/dist/rsuite-no-reset.css +34 -0
  32. package/dist/rsuite-no-reset.min.css +1 -1
  33. package/dist/rsuite-no-reset.min.css.map +1 -1
  34. package/dist/rsuite-rtl.css +34 -0
  35. package/dist/rsuite-rtl.min.css +1 -1
  36. package/dist/rsuite-rtl.min.css.map +1 -1
  37. package/dist/rsuite.css +34 -0
  38. package/dist/rsuite.js +63 -19
  39. package/dist/rsuite.js.map +1 -1
  40. package/dist/rsuite.min.css +1 -1
  41. package/dist/rsuite.min.css.map +1 -1
  42. package/dist/rsuite.min.js +1 -1
  43. package/dist/rsuite.min.js.map +1 -1
  44. package/esm/Carousel/Carousel.js +1 -0
  45. package/esm/CustomProvider/CustomProvider.d.ts +13 -15
  46. package/esm/CustomProvider/CustomProvider.js +7 -5
  47. package/esm/CustomProvider/types.d.ts +2 -0
  48. package/esm/Image/Image.d.ts +42 -0
  49. package/esm/Image/Image.js +97 -0
  50. package/esm/Image/ImageWrapper.d.ts +1 -0
  51. package/esm/Image/ImageWrapper.js +6 -0
  52. package/esm/Image/hooks/useImage.d.ts +14 -0
  53. package/esm/Image/hooks/useImage.js +63 -0
  54. package/esm/Image/index.d.ts +3 -0
  55. package/esm/Image/index.js +3 -0
  56. package/esm/index.d.ts +2 -0
  57. package/esm/index.js +1 -0
  58. package/esm/internals/utils/getDOMNode.js +2 -1
  59. package/esm/internals/utils/index.d.ts +0 -1
  60. package/esm/internals/utils/index.js +0 -1
  61. package/esm/toaster/ToastContainer.d.ts +6 -6
  62. package/esm/toaster/ToastContainer.js +49 -39
  63. package/esm/toaster/render.d.ts +3 -0
  64. package/esm/toaster/render.js +35 -0
  65. package/esm/toaster/toaster.js +31 -20
  66. package/esm/useToaster/useToaster.js +10 -5
  67. package/package.json +1 -1
  68. package/styles/index.less +1 -0
@@ -134,6 +134,7 @@ var Carousel = /*#__PURE__*/React.forwardRef(function (props, ref) {
134
134
  }), /*#__PURE__*/React.createElement("div", {
135
135
  className: prefix('content')
136
136
  }, /*#__PURE__*/React.createElement("div", {
137
+ "data-testid": "carousel-slider",
137
138
  className: prefix('slider'),
138
139
  style: sliderStyles,
139
140
  onTransitionEnd: handleTransitionEnd
@@ -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
- container = props.toastContainer,
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: 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,
@@ -53,6 +53,7 @@ import type { InputProps } from '../Input';
53
53
  import type { InputGroupProps } from '../InputGroup';
54
54
  import type { InputNumberProps } from '../InputNumber';
55
55
  import type { InputPickerProps } from '../InputPicker';
56
+ import type { ImageProps } from '../Image';
56
57
  import type { ListProps } from '../List';
57
58
  import type { LoaderProps } from '../Loader';
58
59
  import type { MaskedInputProps } from '../MaskedInput';
@@ -164,6 +165,7 @@ export interface ReactSuiteComponents {
164
165
  InputGroup: ComponentProps<InputGroupProps>;
165
166
  InputNumber: ComponentProps<InputNumberProps>;
166
167
  InputPicker: ComponentProps<InputPickerProps>;
168
+ Image: ComponentProps<ImageProps>;
167
169
  List: ComponentProps<ListProps>;
168
170
  Loader: ComponentProps<LoaderProps>;
169
171
  MaskedInput: ComponentProps<MaskedInputProps>;
@@ -0,0 +1,42 @@
1
+ import React, { CSSProperties } from 'react';
2
+ import type { WithAsProps, RsRefForwardingComponent } from '../internals/types';
3
+ export interface ImageProps extends WithAsProps, Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'placeholder'> {
4
+ /**
5
+ * An image may appear with border.
6
+ */
7
+ bordered?: boolean;
8
+ /**
9
+ * An image may appear circular.
10
+ */
11
+ circle?: boolean;
12
+ /**
13
+ * The fallback image when the src fails to load.
14
+ */
15
+ fallbackSrc?: string;
16
+ /**
17
+ * An image may appear rounded.
18
+ */
19
+ rounded?: boolean;
20
+ /**
21
+ * Whether there is a shadow.
22
+ */
23
+ shaded?: boolean;
24
+ /**
25
+ * It maps to css `object-fit` property.
26
+ */
27
+ fit?: CSSProperties['objectFit'];
28
+ /**
29
+ * It maps to css `object-position` property.
30
+ */
31
+ position?: CSSProperties['objectPosition'];
32
+ /**
33
+ * The placeholder to display when the image is loading.
34
+ */
35
+ placeholder?: React.ReactNode;
36
+ /**
37
+ * Whether the image should be zoomed when hovered.
38
+ */
39
+ zoomed?: boolean;
40
+ }
41
+ declare const Image: RsRefForwardingComponent<'img', ImageProps>;
42
+ export default Image;
@@ -0,0 +1,97 @@
1
+ 'use client';
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
+ var _excluded = ["as", "bordered", "classPrefix", "className", "circle", "crossOrigin", "fit", "fallbackSrc", "loading", "rounded", "srcSet", "sizes", "shaded", "src", "style", "position", "placeholder", "width", "height", "zoomed"];
5
+ import React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import { useClassNames } from "../internals/hooks/index.js";
8
+ import { ImageWrapper } from "./ImageWrapper.js";
9
+ import { useImage } from "./hooks/useImage.js";
10
+ import { useCustom } from "../CustomProvider/index.js";
11
+ var Image = /*#__PURE__*/React.forwardRef(function (props, ref) {
12
+ var _extends2;
13
+ var _useCustom = useCustom('Image', props),
14
+ propsWithDefaults = _useCustom.propsWithDefaults;
15
+ var _propsWithDefaults$as = propsWithDefaults.as,
16
+ Component = _propsWithDefaults$as === void 0 ? 'img' : _propsWithDefaults$as,
17
+ bordered = propsWithDefaults.bordered,
18
+ _propsWithDefaults$cl = propsWithDefaults.classPrefix,
19
+ classPrefix = _propsWithDefaults$cl === void 0 ? 'image' : _propsWithDefaults$cl,
20
+ className = propsWithDefaults.className,
21
+ circle = propsWithDefaults.circle,
22
+ crossOrigin = propsWithDefaults.crossOrigin,
23
+ fit = propsWithDefaults.fit,
24
+ fallbackSrc = propsWithDefaults.fallbackSrc,
25
+ loading = propsWithDefaults.loading,
26
+ rounded = propsWithDefaults.rounded,
27
+ srcSet = propsWithDefaults.srcSet,
28
+ sizes = propsWithDefaults.sizes,
29
+ shaded = propsWithDefaults.shaded,
30
+ src = propsWithDefaults.src,
31
+ style = propsWithDefaults.style,
32
+ position = propsWithDefaults.position,
33
+ placeholder = propsWithDefaults.placeholder,
34
+ width = propsWithDefaults.width,
35
+ height = propsWithDefaults.height,
36
+ zoomed = propsWithDefaults.zoomed,
37
+ rest = _objectWithoutPropertiesLoose(propsWithDefaults, _excluded);
38
+ var _useClassNames = useClassNames(classPrefix),
39
+ merge = _useClassNames.merge,
40
+ withClassPrefix = _useClassNames.withClassPrefix;
41
+ var classes = merge(className, withClassPrefix({
42
+ circle: circle,
43
+ bordered: bordered,
44
+ rounded: rounded,
45
+ shaded: shaded,
46
+ zoomed: zoomed
47
+ }));
48
+ var imgProps = {
49
+ crossOrigin: crossOrigin,
50
+ srcSet: srcSet,
51
+ sizes: sizes,
52
+ loading: loading
53
+ };
54
+ var _useImage = useImage(_extends({
55
+ src: src,
56
+ fallbackSrc: fallbackSrc
57
+ }, imgProps)),
58
+ imgSrc = _useImage.imgSrc,
59
+ isLoading = _useImage.isLoading;
60
+ var styles = _extends({}, style, (_extends2 = {}, _extends2['--rs-object-fit'] = fit, _extends2['--rs-object-position'] = position, _extends2));
61
+ var wrapStyles = {
62
+ width: width,
63
+ height: height
64
+ };
65
+ var image = /*#__PURE__*/React.createElement(Component, _extends({
66
+ ref: ref,
67
+ src: imgSrc,
68
+ className: classes,
69
+ style: styles,
70
+ width: width,
71
+ height: height
72
+ }, imgProps, rest));
73
+ if (zoomed) {
74
+ return /*#__PURE__*/React.createElement(ImageWrapper, {
75
+ style: wrapStyles
76
+ }, image);
77
+ }
78
+ if (placeholder) {
79
+ return /*#__PURE__*/React.createElement(ImageWrapper, {
80
+ style: wrapStyles
81
+ }, isLoading && placeholder, image);
82
+ }
83
+ return image;
84
+ });
85
+ Image.displayName = 'Image';
86
+ Image.propTypes = {
87
+ bordered: PropTypes.bool,
88
+ circle: PropTypes.bool,
89
+ fallbackSrc: PropTypes.string,
90
+ fit: PropTypes.string,
91
+ position: PropTypes.string,
92
+ rounded: PropTypes.bool,
93
+ shaded: PropTypes.bool,
94
+ placeholder: PropTypes.node,
95
+ zoomed: PropTypes.bool
96
+ };
97
+ export default Image;
@@ -0,0 +1 @@
1
+ export declare const ImageWrapper: import("../internals/types").RsRefForwardingComponent<"div", import("../internals/utils").ComponentProps>;
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ import { createComponent } from "../internals/utils/index.js";
3
+ export var ImageWrapper = createComponent({
4
+ name: 'ImageWrapper',
5
+ componentAs: 'div'
6
+ });
@@ -0,0 +1,14 @@
1
+ interface UseImageProps {
2
+ src?: string;
3
+ fallbackSrc?: string;
4
+ crossOrigin?: string;
5
+ srcSet?: string;
6
+ sizes?: string;
7
+ loading?: 'lazy' | 'eager';
8
+ }
9
+ export declare const useImage: (props: UseImageProps) => {
10
+ imgSrc: string | null;
11
+ isLoading: boolean;
12
+ error: boolean;
13
+ };
14
+ export {};
@@ -0,0 +1,63 @@
1
+ 'use client';
2
+ import { useState, useEffect, useRef, useCallback } from 'react';
3
+ import useIsomorphicLayoutEffect from "../../internals/hooks/useIsomorphicLayoutEffect.js";
4
+ export var useImage = function useImage(props) {
5
+ var src = props.src,
6
+ fallbackSrc = props.fallbackSrc,
7
+ crossOrigin = props.crossOrigin,
8
+ srcSet = props.srcSet,
9
+ sizes = props.sizes,
10
+ loading = props.loading;
11
+ var _useState = useState(src || fallbackSrc || null),
12
+ imgSrc = _useState[0],
13
+ setImgSrc = _useState[1];
14
+ var _useState2 = useState(!!src),
15
+ isLoading = _useState2[0],
16
+ setIsLoading = _useState2[1];
17
+ var _useState3 = useState(false),
18
+ error = _useState3[0],
19
+ setError = _useState3[1];
20
+ var imageRef = useRef(null);
21
+ useEffect(function () {
22
+ setIsLoading(!!src); // true if src exists, false otherwise
23
+ }, [src]);
24
+ var flush = function flush() {
25
+ if (imageRef.current) {
26
+ imageRef.current.onload = null;
27
+ imageRef.current.onerror = null;
28
+ }
29
+ };
30
+ var loadImage = useCallback(function () {
31
+ if (!src) return;
32
+ flush();
33
+ var image = new Image();
34
+ image.src = src;
35
+ if (crossOrigin) image.crossOrigin = crossOrigin;
36
+ if (srcSet) image.srcset = srcSet;
37
+ if (sizes) image.sizes = sizes;
38
+ if (loading) image.loading = loading;
39
+ image.onload = function () {
40
+ flush();
41
+ setImgSrc(src);
42
+ setIsLoading(false);
43
+ };
44
+ image.onerror = function () {
45
+ flush();
46
+ setError(true);
47
+ setImgSrc(fallbackSrc || null);
48
+ setIsLoading(false);
49
+ };
50
+ imageRef.current = image;
51
+ }, [crossOrigin, fallbackSrc, loading, sizes, src, srcSet]);
52
+ useIsomorphicLayoutEffect(function () {
53
+ loadImage();
54
+ return function () {
55
+ flush();
56
+ };
57
+ }, [loadImage]);
58
+ return {
59
+ imgSrc: imgSrc,
60
+ isLoading: isLoading,
61
+ error: error
62
+ };
63
+ };
@@ -0,0 +1,3 @@
1
+ import Image from './Image';
2
+ export type { ImageProps } from './Image';
3
+ export default Image;
@@ -0,0 +1,3 @@
1
+ 'use client';
2
+ import Image from "./Image.js";
3
+ export default Image;
package/esm/index.d.ts CHANGED
@@ -47,6 +47,8 @@ export { default as Avatar } from './Avatar';
47
47
  export type { AvatarProps } from './Avatar';
48
48
  export { default as AvatarGroup } from './AvatarGroup';
49
49
  export type { AvatarGroupProps } from './AvatarGroup';
50
+ export { default as Image } from './Image';
51
+ export type { ImageProps } from './Image';
50
52
  export { default as Nav } from './Nav';
51
53
  export type { NavProps, NavItemProps } from './Nav';
52
54
  export { default as Navbar } from './Navbar';
package/esm/index.js CHANGED
@@ -34,6 +34,7 @@ export { default as Progress } from "./Progress/index.js";
34
34
  // --------------------------------------------------------
35
35
  export { default as Avatar } from "./Avatar/index.js";
36
36
  export { default as AvatarGroup } from "./AvatarGroup/index.js";
37
+ export { default as Image } from "./Image/index.js";
37
38
  // Nav
38
39
  // --------------------------------------------------------
39
40
  export { default as Nav } from "./Nav/index.js";
@@ -2,8 +2,9 @@
2
2
  import ReactDOM from 'react-dom';
3
3
  function safeFindDOMNode(componentOrElement) {
4
4
  if (componentOrElement && 'setState' in componentOrElement) {
5
+ var _ReactDOM$findDOMNode;
5
6
  // eslint-disable-next-line react/no-find-dom-node
6
- return ReactDOM.findDOMNode(componentOrElement);
7
+ return (_ReactDOM$findDOMNode = ReactDOM.findDOMNode) === null || _ReactDOM$findDOMNode === void 0 ? void 0 : _ReactDOM$findDOMNode.call(ReactDOM, componentOrElement);
7
8
  }
8
9
  return componentOrElement !== null && componentOrElement !== void 0 ? componentOrElement : null;
9
10
  }
@@ -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: 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;
@@ -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", "callback"],
5
+ var _excluded = ["as", "className", "classPrefix", "placement"],
5
6
  _excluded2 = ["className"],
6
7
  _excluded3 = ["container"];
7
- import React, { useState, useImperativeHandle, useRef, useCallback } from 'react';
8
- import { createPortal } from 'react-dom';
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, render } from "../internals/utils/index.js";
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
- container = item.container;
116
- var toastWithTransition = /*#__PURE__*/React.createElement(Transition, {
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 (props) {
154
- var container = props.container,
155
- rest = _objectWithoutPropertiesLoose(props, _excluded3);
156
- var containerRef = /*#__PURE__*/React.createRef();
157
- var containerElement = (typeof container === 'function' ? container() : container) || document.body;
158
- return new Promise(function (resolve) {
159
- var renderCallback = function renderCallback() {
160
- resolve([containerRef, unmount]);
161
- };
162
- var _render = render(/*#__PURE__*/React.createElement(ToastContainer, _extends({}, rest, {
163
- ref: containerRef,
164
- callback: renderCallback
165
- })), containerElement),
166
- unmount = _render.unmount;
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,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,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
+ }