@soul-refiner/design-system 1.7.10 → 1.7.11
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,11 +7,73 @@ import { TimeAgo } from '../../atoms/time_ago/time_ago';
|
|
|
7
7
|
import { Button } from '../../actions/button';
|
|
8
8
|
import { Avatar } from '../../iconography/avatar';
|
|
9
9
|
import { Lock } from '../../../icons';
|
|
10
|
+
import { Modal } from '../modal';
|
|
11
|
+
import { ChevronLeft, ChevronRight } from '../../../icons/arrow';
|
|
10
12
|
export const Post = ({ actions, author, authorActive, authorHref, authorImage, avatarTooltipContent, avatarTooltipSx, children, content, createdDate, dropdown, hasComments, id, images, isPaywalled = false, onJoin, }) => {
|
|
11
13
|
const componentId = React.useId();
|
|
14
|
+
const [curr, setCurr] = React.useState(-1);
|
|
15
|
+
const [modalContentSize, setModalContentSize] = React.useState({
|
|
16
|
+
x: '30vw',
|
|
17
|
+
y: '30vh',
|
|
18
|
+
});
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
const handleKeyEvent = (event) => {
|
|
21
|
+
if (event.key === 'ArrowLeft') {
|
|
22
|
+
handleDecrement();
|
|
23
|
+
}
|
|
24
|
+
else if (event.key === 'ArrowRight') {
|
|
25
|
+
handleIncrement();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
if (typeof document !== 'undefined') {
|
|
29
|
+
document.addEventListener('keydown', handleKeyEvent);
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
document.removeEventListener('keydown', handleKeyEvent);
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
12
35
|
const _actions = React.Children.toArray(actions);
|
|
13
36
|
const _comments = React.Children.toArray(children);
|
|
37
|
+
const handleImageLoad = (event) => {
|
|
38
|
+
const { naturalHeight, naturalWidth } = event.target;
|
|
39
|
+
setModalContentSize({
|
|
40
|
+
x: `${naturalWidth}px`,
|
|
41
|
+
y: `${naturalHeight}px`,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const handleIncrement = () => {
|
|
45
|
+
setCurr((prev) => {
|
|
46
|
+
if (images?.length && prev !== images.length - 1) {
|
|
47
|
+
return prev + 1;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return prev;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const handleDecrement = () => {
|
|
55
|
+
setCurr((prev) => {
|
|
56
|
+
if (images?.length && prev !== 0) {
|
|
57
|
+
return prev - 1;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return prev;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
14
64
|
return (React.createElement(Wrapper, { id: id },
|
|
65
|
+
curr > -1 && !!images?.[curr] && (React.createElement(Modal, { controlledOpen: true, onChange: (open) => !open && setCurr(-1) },
|
|
66
|
+
React.createElement(Modal.Content, { sx: `
|
|
67
|
+
position: relative;
|
|
68
|
+
height: ${modalContentSize.y};
|
|
69
|
+
width: ${modalContentSize.x};
|
|
70
|
+
margin: 0 auto;
|
|
71
|
+
` },
|
|
72
|
+
React.createElement(NavArrow, { "$side": "left", "$visible": curr !== 0, onClick: handleDecrement },
|
|
73
|
+
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' } }),
|
|
75
|
+
React.createElement(NavArrow, { "$side": "right", "$visible": curr !== images.length - 1, onClick: handleIncrement },
|
|
76
|
+
React.createElement(ChevronRight, { color: "white", size: 48 }))))),
|
|
15
77
|
React.createElement(Header, null,
|
|
16
78
|
React.createElement(Avatar, { href: authorHref, image: authorImage, size: 64, status: authorActive ? 'online' : undefined, subtitle: React.createElement(P, { as: "span", sx: "vertical-align: top;", "$fontSize": 14, "$lineHeight": 20 },
|
|
17
79
|
React.createElement(TimeAgo, { date: new Date(createdDate) })), title: React.createElement(H, { as: "span", "$bold": true, "$fontSize": 18, "$lineHeight": 26 }, author), textPosition: "right", tooltipContent: avatarTooltipContent, tooltipSx: avatarTooltipSx }),
|
|
@@ -20,7 +82,7 @@ export const Post = ({ actions, author, authorActive, authorHref, authorImage, a
|
|
|
20
82
|
React.createElement(P, { "$textClampLines": isPaywalled ? 2 : undefined }, content))),
|
|
21
83
|
!!images?.length && (React.createElement(ImagesWrapper, { "$numImages": images.length, "$isPaywalled": isPaywalled },
|
|
22
84
|
images.slice(0, 4).map((url, i) => (React.createElement(ImageWrapper, { key: `${componentId}${url.slice(0, 15)}${i}` },
|
|
23
|
-
React.createElement(Image, { alt: "", fill: true, quality: 100, src: url })))),
|
|
85
|
+
React.createElement(Image, { alt: "", fill: true, onClick: () => setCurr(i), quality: 100, src: url, style: { cursor: 'pointer' } })))),
|
|
24
86
|
images.length > 4 && (React.createElement(H, { as: "p", className: "more-than", "$color": "grey-10", "$fontSize": 28, "$lineHeight": 36, "$semiBold": true },
|
|
25
87
|
"+",
|
|
26
88
|
images.length - 4)))),
|
|
@@ -127,3 +189,22 @@ const CommentWrapper = styled.div `
|
|
|
127
189
|
flex-flow: column nowrap;
|
|
128
190
|
gap: 24px;
|
|
129
191
|
`;
|
|
192
|
+
const NavArrow = styled.button `
|
|
193
|
+
width: 48px;
|
|
194
|
+
height: 150px;
|
|
195
|
+
display: flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
justify-content: center;
|
|
198
|
+
position: fixed;
|
|
199
|
+
z-index: 100;
|
|
200
|
+
top: calc(50vh - 75px);
|
|
201
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
202
|
+
${({ $side }) => $side}: 0;
|
|
203
|
+
border-radius: ${({ $side }) => $side === 'left' ? '0 12px 12px 0' : '12px 0 0 12px'};
|
|
204
|
+
${({ $visible }) => $visible
|
|
205
|
+
? 'visibility: visible; cursor: pointer;'
|
|
206
|
+
: 'visibility: hidden; pointer-events: none;'}
|
|
207
|
+
&:hover {
|
|
208
|
+
background-color: rgba(0, 0, 0, 0.2);
|
|
209
|
+
}
|
|
210
|
+
`;
|