Skip to content

Commit ce9c56a

Browse files
authored
🤖 Merge PR DefinitelyTyped#71451 fix(react-modal-image): add onClose(), reorder typedef, modify jsdoc by @hkleungai
1 parent 683ec4a commit ce9c56a

File tree

2 files changed

+79
-56
lines changed

2 files changed

+79
-56
lines changed
Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,65 @@
11
import * as React from "react";
22

3-
export interface ModalImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
4-
/* The small image to display */
3+
export interface ModalImageProps {
4+
/** Optional. `class` for the small preview image. */
5+
className?: string | undefined;
6+
7+
/** Optional. `alt` for the small image and the heading text in Lightbox. */
8+
alt?: string | undefined;
9+
10+
/** `src` for the small preview image. */
511
small: string;
612

7-
/* The srcset attribute for the small image */
8-
smallSrcSet?: string;
13+
/** Optional. `srcSet` for the small preview image. */
14+
smallSrcSet?: string | undefined;
15+
16+
/** Optional if `large` is defined. Image shown when zoomed out in Lightbox. */
17+
medium?: string | undefined;
18+
19+
/** Optional if `medium` is defined. Image shown when zoomed in Lightbox. Downloadable. */
20+
large?: string | undefined;
21+
22+
/** Optional. Set to `true` to hide download-button from the Lightbox. */
23+
hideDownload?: boolean | undefined;
24+
25+
/** Optional. Set to `true` to hide zoom-button from the Lightbox. */
26+
hideZoom?: boolean | undefined;
27+
28+
/** Optional. Set to `true` to show rotate-button within the Lightbox. */
29+
showRotate?: boolean | undefined;
30+
31+
/** Optional. Background color of the image shown in Lightbox. Defaults to black. Handy for transparent images. */
32+
imageBackgroundColor?: string | undefined;
33+
}
934

10-
/* The medium image to display */
11-
medium?: string;
35+
export interface LightboxProps {
36+
/** Optional if `large` is defined. Image shown when zoomed out in Lightbox. */
37+
medium?: string | undefined;
1238

13-
/* The large image to display */
14-
large?: string;
39+
/** Optional if `medium` is defined. Image shown when zoomed in Lightbox. Downloadable. */
40+
large?: string | undefined;
1541

16-
/* The alt tag for the image */
17-
alt?: string;
42+
/** Optional. `alt` for the small image and the heading text in Lightbox. */
43+
alt?: string | undefined;
1844

19-
/* Should the download button be hidden? */
20-
hideDownload?: boolean;
45+
/** Will be invoked when the Lightbox requests to be closed. */
46+
onClose?: (() => void) | undefined;
2147

22-
/* Should the zoom button be hidden? */
23-
hideZoom?: boolean;
48+
/** Optional. Set to `true` to hide download-button from the Lightbox. */
49+
hideDownload?: boolean | undefined;
2450

25-
/* Should the rotate button be shown? */
26-
showRotate?: boolean;
51+
/** Optional. Set to `true` to hide zoom-button from the Lightbox. */
52+
hideZoom?: boolean | undefined;
2753

28-
/* The color to display in the background. */
29-
imageBackgroundColor?: string;
54+
/** Optional. Set to `true` to show rotate-button within the Lightbox. */
55+
showRotate?: boolean | undefined;
3056

31-
/* The class name for the modal */
32-
className?: string;
57+
/** Optional. Background color of the image shown in Lightbox. Defaults to black. Handy for transparent images. */
58+
imageBackgroundColor?: string | undefined;
3359
}
3460

3561
declare class ModalImage extends React.Component<ModalImageProps> {}
36-
declare class Lightbox extends React.Component<ModalImageProps> {}
62+
declare class Lightbox extends React.Component<LightboxProps> {}
3763

3864
export default ModalImage;
3965
export { Lightbox };
Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
import * as React from "react";
2-
import ModalImage, { Lightbox, ModalImageProps } from "react-modal-image";
3-
4-
const props: ModalImageProps = {
5-
/* The small image to display */
6-
small: "https://example.com/image-small.jpg",
7-
8-
/* The large image to display */
9-
large: "https://example.com/image-large.jpg",
10-
11-
/* The alt tag for the image */
12-
alt: "Example Image",
13-
14-
/* Should the download button be hidden? */
15-
hideDownload: true,
16-
17-
/* Should the zoom button be hidden? */
18-
hideZoom: true,
19-
20-
/* The color to display in the background. */
21-
imageBackgroundColor: "#000",
22-
23-
/* The class name for the modal */
24-
className: "example-class",
25-
};
26-
27-
class ReactModalImageTest extends React.Component {
28-
render() {
29-
return (
30-
<>
31-
<ModalImage {...props} />
32-
<Lightbox {...props} />
33-
</>
34-
);
35-
}
36-
}
2+
import ModalImage, { Lightbox, LightboxProps, ModalImageProps } from "react-modal-image";
3+
4+
// @ts-ignore - props.small is required.
5+
<ModalImage />;
6+
7+
<ModalImage small="image-small.jpg" />;
8+
9+
<ModalImage
10+
className="example-class"
11+
alt="Example Image"
12+
small="image-small.jpg"
13+
smallSrcSet="small-src-set"
14+
medium="image-medium.jpg"
15+
large="image-large.jpg"
16+
hideDownload={true}
17+
hideZoom={true}
18+
showRotate={true}
19+
imageBackgroundColor="#000"
20+
/>;
21+
22+
<Lightbox />;
23+
24+
<Lightbox
25+
medium="image-medium.jpg"
26+
large="image-large.jpg"
27+
alt="Example Image"
28+
onClose={() => {}}
29+
hideDownload={true}
30+
hideZoom={true}
31+
showRotate={true}
32+
imageBackgroundColor="#000"
33+
/>;

0 commit comments

Comments
 (0)