@soul-refiner/design-system 1.7.12 → 1.7.13

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.
@@ -24,22 +24,41 @@ export const Post = ({ actions, author, authorActive, authorHref, authorImage, a
24
24
  else if (event.key === 'ArrowRight') {
25
25
  handleIncrement();
26
26
  }
27
+ else if (event.key === 'Escape' || event.key === 'Enter') {
28
+ setCurr(-1);
29
+ }
27
30
  };
28
- if (typeof document !== 'undefined') {
31
+ if (typeof document !== 'undefined' && !!images?.length) {
29
32
  document.addEventListener('keydown', handleKeyEvent);
30
33
  }
31
34
  return () => {
32
- document.removeEventListener('keydown', handleKeyEvent);
35
+ images?.length &&
36
+ document.removeEventListener('keydown', handleKeyEvent);
33
37
  };
34
38
  }, []);
35
39
  const _actions = React.Children.toArray(actions);
36
40
  const _comments = React.Children.toArray(children);
37
41
  const handleImageLoad = (event) => {
38
42
  const { naturalHeight, naturalWidth } = event.target;
39
- setModalContentSize({
40
- x: `${naturalWidth}px`,
41
- y: `${naturalHeight}px`,
42
- });
43
+ let x = `${naturalWidth}px`;
44
+ let y = `${naturalHeight}px`;
45
+ // if natural size is smaller than window height and width
46
+ if (window?.innerHeight < naturalHeight &&
47
+ window?.innerWidth < naturalWidth) {
48
+ x = `${Math.floor((window.innerHeight * 0.95 * naturalWidth) / naturalHeight)}px`;
49
+ y = `${Math.round((window.innerWidth * 0.95 * naturalHeight) / naturalWidth)}px`;
50
+ // just smaller than height
51
+ }
52
+ else if (window?.innerHeight < naturalHeight) {
53
+ x = `${Math.floor((window.innerHeight * 0.95 * naturalWidth) / naturalHeight)}px`;
54
+ y = '95vh';
55
+ // just smaller than width
56
+ }
57
+ else if (window?.innerWidth < naturalWidth) {
58
+ x = '95vw';
59
+ y = `${Math.round((window.innerWidth * 0.95 * naturalHeight) / naturalWidth)}px`;
60
+ }
61
+ setModalContentSize({ x, y });
43
62
  };
44
63
  const handleIncrement = () => {
45
64
  setCurr((prev) => {
@@ -62,7 +81,7 @@ export const Post = ({ actions, author, authorActive, authorHref, authorImage, a
62
81
  });
63
82
  };
64
83
  return (React.createElement(Wrapper, { id: id },
65
- curr > -1 && !!images?.[curr] && (React.createElement(Modal, { controlledOpen: true, onChange: (open) => !open && setCurr(-1) },
84
+ curr > -1 && !!images?.[curr] && (React.createElement(Modal, { alwaysRender: false, controlledOpen: true, onChange: (open) => !open && setCurr(-1) },
66
85
  React.createElement(Modal.Content, { sx: `
67
86
  position: relative;
68
87
  height: ${modalContentSize.y};
@@ -71,7 +90,7 @@ export const Post = ({ actions, author, authorActive, authorHref, authorImage, a
71
90
  ` },
72
91
  React.createElement(NavArrow, { "$side": "left", "$visible": curr !== 0, onClick: handleDecrement },
73
92
  React.createElement(ChevronLeft, { color: "white", size: 48 })),
74
- React.createElement(Image, { alt: "", fill: true, quality: 100, onLoad: handleImageLoad, priority: true, sizes: "100vw", src: images[curr], style: { objectFit: 'contain' } }),
93
+ React.createElement(Image, { alt: "", fill: true, quality: 100, onLoad: handleImageLoad, priority: true, sizes: "100vw", src: images[curr], style: { objectFit: 'cover' } }),
75
94
  React.createElement(NavArrow, { "$side": "right", "$visible": curr !== images.length - 1, onClick: handleIncrement },
76
95
  React.createElement(ChevronRight, { color: "white", size: 48 }))))),
77
96
  React.createElement(Header, null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "1.7.12",
3
+ "version": "1.7.13",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {