@redocly/theme 0.49.1 → 0.50.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.
@@ -7,6 +7,7 @@ export type ImageProps = {
7
7
  width?: string | number;
8
8
  height?: string | number;
9
9
  border?: string;
10
+ withLightbox?: boolean;
10
11
  style?: React.CSSProperties | string;
11
12
  };
12
13
  export declare function Image(props: ImageProps): JSX.Element;
@@ -8,16 +8,51 @@ const react_1 = __importDefault(require("react"));
8
8
  const styled_components_1 = __importDefault(require("styled-components"));
9
9
  const utils_1 = require("../../core/utils");
10
10
  function Image(props) {
11
- const { src, srcSet, alt, className, width, height, border, style } = props;
11
+ const { src, srcSet, alt, className, width, height, border, style, withLightbox } = props;
12
+ const [lightboxImage, setLightboxImage] = react_1.default.useState(undefined);
12
13
  const parsedSourceSetMap = react_1.default.useMemo(() => {
13
14
  return srcSet ? (0, utils_1.parseSrcSet)(srcSet) : new Map();
14
15
  }, [srcSet]);
15
- const combinedStyle = Object.assign(Object.assign({}, (border && { border })), (typeof style === 'string' ? { cssText: style } : style));
16
- return (react_1.default.createElement(react_1.default.Fragment, null, src ? (react_1.default.createElement("img", { src: src, alt: alt, className: className, width: width, height: height, style: combinedStyle })) : (Array.from(parsedSourceSetMap).map(([key, value]) => (react_1.default.createElement(ColorModeAwareImage, { key: key, colorMode: key, src: value, alt: alt, className: className, width: width, height: height, style: combinedStyle }))))));
16
+ const handleImageClick = (src) => {
17
+ if (!withLightbox || lightboxImage) {
18
+ return;
19
+ }
20
+ setLightboxImage(src);
21
+ };
22
+ const handleCloseLightbox = () => {
23
+ setLightboxImage(undefined);
24
+ };
25
+ const combinedStyles = Object.assign(Object.assign(Object.assign({}, (withLightbox && { cursor: 'pointer' })), (border && { border })), (typeof style === 'string' ? { cssText: style } : style));
26
+ return (react_1.default.createElement(react_1.default.Fragment, null,
27
+ lightboxImage ? (react_1.default.createElement(LightboxContainer, { onClick: handleCloseLightbox },
28
+ react_1.default.createElement(Image, { src: lightboxImage, alt: alt }))) : null,
29
+ src ? (react_1.default.createElement("img", { src: src, alt: alt, className: className, width: width, height: height, style: combinedStyles, onClick: () => handleImageClick(src) })) : (Array.from(parsedSourceSetMap).map(([key, value]) => (react_1.default.createElement(ColorModeAwareImage, { key: key, colorMode: key, src: value, alt: alt, className: className, width: width, height: height, "$withLightbox": withLightbox, style: combinedStyles, onClick: () => handleImageClick(value) }))))));
17
30
  }
18
31
  const ColorModeAwareImage = styled_components_1.default.img `
19
32
  html:not(.${(props) => props.colorMode}) && {
20
33
  display: none;
21
34
  }
35
+ ${({ $withLightbox }) => $withLightbox &&
36
+ `
37
+ cursor: pointer;
38
+ `}
39
+ `;
40
+ const LightboxContainer = styled_components_1.default.div `
41
+ position: fixed;
42
+ top: 0;
43
+ left: 0;
44
+ width: 100%;
45
+ height: 100%;
46
+ background-color: var(--bg-color-modal-overlay);
47
+ z-index: var(--z-index-overlay);
48
+ display: flex;
49
+ justify-content: center;
50
+ align-items: center;
51
+
52
+ img {
53
+ cursor: pointer;
54
+ max-width: 90%;
55
+ max-height: 90%;
56
+ }
22
57
  `;
23
58
  //# sourceMappingURL=Image.js.map
@@ -16,6 +16,10 @@ exports.img = {
16
16
  alt: {
17
17
  type: String,
18
18
  },
19
+ withLightbox: {
20
+ type: Boolean,
21
+ default: false,
22
+ },
19
23
  className: {
20
24
  type: String,
21
25
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.49.1",
3
+ "version": "0.50.0",
4
4
  "description": "Shared UI components lib",
5
5
  "keywords": [
6
6
  "theme",
@@ -11,23 +11,42 @@ export type ImageProps = {
11
11
  width?: string | number;
12
12
  height?: string | number;
13
13
  border?: string;
14
+ withLightbox?: boolean;
14
15
  style?: React.CSSProperties | string;
15
16
  };
16
17
 
17
18
  export function Image(props: ImageProps): JSX.Element {
18
- const { src, srcSet, alt, className, width, height, border, style } = props;
19
+ const { src, srcSet, alt, className, width, height, border, style, withLightbox } = props;
19
20
 
21
+ const [lightboxImage, setLightboxImage] = React.useState<string | undefined>(undefined);
20
22
  const parsedSourceSetMap = React.useMemo(() => {
21
23
  return srcSet ? parseSrcSet(srcSet) : new Map();
22
24
  }, [srcSet]);
23
25
 
24
- const combinedStyle: React.CSSProperties = {
26
+ const handleImageClick = (src: string) => {
27
+ if (!withLightbox || lightboxImage) {
28
+ return;
29
+ }
30
+ setLightboxImage(src);
31
+ };
32
+
33
+ const handleCloseLightbox = () => {
34
+ setLightboxImage(undefined);
35
+ };
36
+
37
+ const combinedStyles: React.CSSProperties = {
38
+ ...(withLightbox && { cursor: 'pointer' }),
25
39
  ...(border && { border }),
26
40
  ...(typeof style === 'string' ? { cssText: style } : style),
27
41
  };
28
42
 
29
43
  return (
30
44
  <>
45
+ {lightboxImage ? (
46
+ <LightboxContainer onClick={handleCloseLightbox}>
47
+ <Image src={lightboxImage} alt={alt} />
48
+ </LightboxContainer>
49
+ ) : null}
31
50
  {src ? (
32
51
  <img
33
52
  src={src}
@@ -35,7 +54,8 @@ export function Image(props: ImageProps): JSX.Element {
35
54
  className={className}
36
55
  width={width}
37
56
  height={height}
38
- style={combinedStyle}
57
+ style={combinedStyles}
58
+ onClick={() => handleImageClick(src)}
39
59
  />
40
60
  ) : (
41
61
  Array.from(parsedSourceSetMap).map(([key, value]) => (
@@ -47,7 +67,9 @@ export function Image(props: ImageProps): JSX.Element {
47
67
  className={className}
48
68
  width={width}
49
69
  height={height}
50
- style={combinedStyle}
70
+ $withLightbox={withLightbox}
71
+ style={combinedStyles}
72
+ onClick={() => handleImageClick(value)}
51
73
  />
52
74
  ))
53
75
  )}
@@ -55,8 +77,32 @@ export function Image(props: ImageProps): JSX.Element {
55
77
  );
56
78
  }
57
79
 
58
- const ColorModeAwareImage = styled.img<{ colorMode: string }>`
80
+ const ColorModeAwareImage = styled.img<{ colorMode: string; $withLightbox?: boolean }>`
59
81
  html:not(.${(props) => props.colorMode}) && {
60
82
  display: none;
61
83
  }
84
+ ${({ $withLightbox }) =>
85
+ $withLightbox &&
86
+ `
87
+ cursor: pointer;
88
+ `}
89
+ `;
90
+
91
+ const LightboxContainer = styled.div`
92
+ position: fixed;
93
+ top: 0;
94
+ left: 0;
95
+ width: 100%;
96
+ height: 100%;
97
+ background-color: var(--bg-color-modal-overlay);
98
+ z-index: var(--z-index-overlay);
99
+ display: flex;
100
+ justify-content: center;
101
+ align-items: center;
102
+
103
+ img {
104
+ cursor: pointer;
105
+ max-width: 90%;
106
+ max-height: 90%;
107
+ }
62
108
  `;
@@ -15,6 +15,10 @@ export const img: MarkdocSchemaWrapper = {
15
15
  alt: {
16
16
  type: String,
17
17
  },
18
+ withLightbox: {
19
+ type: Boolean,
20
+ default: false,
21
+ },
18
22
  className: {
19
23
  type: String,
20
24
  },