Skip to content

Commit 115a58f

Browse files
committed
updates and amends
1 parent e0ff3e3 commit 115a58f

File tree

7 files changed

+73
-42
lines changed

7 files changed

+73
-42
lines changed

lib/react-image-zooom.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import { JSX } from "react";
22
interface ImageZoomProps {
33
zoom?: string | number;
44
fullWidth?: boolean;
@@ -9,8 +9,8 @@ interface ImageZoomProps {
99
id?: string;
1010
className?: string;
1111
onError?: (error: ErrorEvent) => void;
12-
errorContent?: React.ReactNode;
12+
errorContent?: JSX.Element;
1313
}
14-
declare function ImageZoom({ zoom, fullWidth, alt, width, height, src, id, className, onError, errorContent, }: ImageZoomProps): import("react/jsx-runtime").JSX.Element;
14+
declare function ImageZoom({ zoom, fullWidth, alt, width, height, src, id, className, onError, errorContent, }: ImageZoomProps): JSX.Element;
1515
export default ImageZoom;
1616
export type { ImageZoomProps };

lib/react-image-zooom.js

Lines changed: 36 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-image-zooom.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": {
55
"name": "Mario Duarte"
66
},
7-
"version": "1.5.0",
7+
"version": "1.5.4",
88
"main": "./lib/react-image-zooom.js",
99
"types": "./lib/react-image-zooom.d.ts",
1010
"module": "./lib/react-image-zooom.js",
@@ -50,5 +50,12 @@
5050
"typescript": "^4.9.5",
5151
"webpack": "^5.97.1",
5252
"webpack-cli": "^6.0.1"
53-
}
53+
},
54+
"exports": {
55+
".": {
56+
"import": "./lib/react-image-zooom.js",
57+
"require": "./lib/react-image-zooom.js",
58+
"types": "./lib/react-image-zooom.d.ts"
59+
}
60+
}
5461
}

react-image-zooom-1.5.4.tgz

83.8 KB
Binary file not shown.

src/react-image-zooom.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import React, {
55
MouseEvent,
66
TouchEvent,
77
useRef,
8+
JSX,
9+
isValidElement,
810
} from "react";
911
import styled, { keyframes } from "styled-components";
1012
import usePreventBodyScroll from "./hooks/usePreventBodyScroll";
@@ -94,7 +96,7 @@ interface ImageZoomProps {
9496
id?: string;
9597
className?: string;
9698
onError?: (error: ErrorEvent) => void;
97-
errorContent?: React.ReactNode;
99+
errorContent?: JSX.Element;
98100
}
99101

100102
function ImageZoom({
@@ -107,8 +109,8 @@ function ImageZoom({
107109
id,
108110
className,
109111
onError,
110-
errorContent = <ErrorText>There was a problem loading your image</ErrorText>,
111-
}: ImageZoomProps) {
112+
errorContent,
113+
}: ImageZoomProps): JSX.Element {
112114
const [isZoomed, setIsZoomed] = useState<boolean>(false);
113115
const [position, setPosition] = useState<string>("50% 50%");
114116
const figureRef = useRef<HTMLElement | null>(null);
@@ -219,13 +221,24 @@ function ImageZoom({
219221
[isZoomed, imgData, calculateZoom, position]
220222
);
221223

222-
if (error) return <>{errorContent}</>;
224+
if (error)
225+
return (
226+
<>
227+
{isValidElement(errorContent) ? (
228+
errorContent
229+
) : (
230+
<ErrorText>There was a problem loading your image</ErrorText>
231+
)}
232+
</>
233+
);
223234

224235
const figureClasses = [
225-
imgData ? 'loaded' : 'loading',
226-
isZoomed ? 'zoomed' : 'fullView',
227-
className
228-
].filter(Boolean).join(' ');
236+
imgData ? "loaded" : "loading",
237+
isZoomed ? "zoomed" : "fullView",
238+
className,
239+
]
240+
.filter(Boolean)
241+
.join(" ");
229242

230243
return (
231244
<Figure

webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ module.exports = {
66
output: {
77
path: path.resolve("lib"),
88
filename: "react-image-zooom.js",
9-
libraryTarget: "commonjs2",
9+
library: "ReactImageZooom",
10+
libraryTarget: "umd",
11+
globalObject: "this",
1012
},
1113
optimization: {
1214
minimize: false,
@@ -24,7 +26,6 @@ module.exports = {
2426
options: {
2527
presets: ["@babel/preset-react", "@babel/preset-env"],
2628
plugins: [
27-
["babel-plugin-react-compiler", { target: "19" }],
2829
"@babel/plugin-transform-react-jsx",
2930
],
3031
},

0 commit comments

Comments
 (0)