rsuite 5.75.0 → 5.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/Image/package.json +7 -0
- package/Image/styles/index.css +33 -0
- package/Image/styles/index.less +34 -0
- package/cjs/Carousel/Carousel.js +1 -0
- package/cjs/CustomProvider/types.d.ts +2 -0
- package/cjs/Image/Image.d.ts +42 -0
- package/cjs/Image/Image.js +102 -0
- package/cjs/Image/ImageWrapper.d.ts +1 -0
- package/cjs/Image/ImageWrapper.js +10 -0
- package/cjs/Image/hooks/useImage.d.ts +14 -0
- package/cjs/Image/hooks/useImage.js +68 -0
- package/cjs/Image/index.d.ts +3 -0
- package/cjs/Image/index.js +8 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +4 -2
- package/cjs/internals/utils/getDOMNode.js +2 -1
- package/dist/rsuite-no-reset-rtl.css +34 -0
- package/dist/rsuite-no-reset-rtl.min.css +1 -1
- package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
- package/dist/rsuite-no-reset.css +34 -0
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite-no-reset.min.css.map +1 -1
- package/dist/rsuite-rtl.css +34 -0
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +34 -0
- package/dist/rsuite.js +49 -5
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Carousel/Carousel.js +1 -0
- package/esm/CustomProvider/types.d.ts +2 -0
- package/esm/Image/Image.d.ts +42 -0
- package/esm/Image/Image.js +97 -0
- package/esm/Image/ImageWrapper.d.ts +1 -0
- package/esm/Image/ImageWrapper.js +6 -0
- package/esm/Image/hooks/useImage.d.ts +14 -0
- package/esm/Image/hooks/useImage.js +63 -0
- package/esm/Image/index.d.ts +3 -0
- package/esm/Image/index.js +3 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/internals/utils/getDOMNode.js +2 -1
- package/package.json +1 -1
- package/styles/index.less +1 -0
package/esm/Carousel/Carousel.js
CHANGED
|
@@ -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
|
|
@@ -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,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
|
+
};
|
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
|
}
|
package/package.json
CHANGED
package/styles/index.less
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
@import '../Header/styles/index';
|
|
41
41
|
@import '../FormHelpText/styles/index';
|
|
42
42
|
@import '../IconButton/styles/index';
|
|
43
|
+
@import '../Image/styles/index';
|
|
43
44
|
@import '../Input/styles/index';
|
|
44
45
|
@import '../InputGroup/styles/index';
|
|
45
46
|
@import '../InputNumber/styles/index';
|