|
1 | 1 | import styles from "./styles.module.css"; |
2 | | -import Popup from "reactjs-popup"; |
3 | | -import SocialMediaContacts from "./SocialMediaContacts"; |
4 | | -import { useRef, useState } from "react"; |
5 | | -import LargePortraitCard from "./LargePortraitCard"; |
| 2 | +import { useHistory } from "@docusaurus/router"; |
6 | 3 | import Avatar from "./Avatar"; |
7 | 4 |
|
8 | | -const contentStyle = { |
9 | | - background: "white", |
10 | | - borderRadius: "10px", |
11 | | -}; |
| 5 | +export function SmallPortraitCard({ person }) { |
| 6 | + const history = useHistory(); |
12 | 7 |
|
13 | | -const overlayStyle = { |
14 | | - backgroundColor: "var(--ifm-background-color-popup-overlay)", |
15 | | - opacity: "0.4", |
16 | | - width: "100%", |
17 | | - height: "100%", |
18 | | -}; |
19 | | - |
20 | | -function getCenterOfViewport() { |
21 | | - let horizontalCenter = Math.floor(window.innerWidth / 2); |
22 | | - let verticalCenter = Math.floor(window.innerHeight / 2); |
23 | | - return [horizontalCenter, verticalCenter]; |
24 | | -} |
25 | | - |
26 | | -function calculateOffsets(elementRef) { |
27 | | - const rect = elementRef.current.getBoundingClientRect(); |
28 | | - const [xViewportCenter, yViewportCenter] = getCenterOfViewport(); |
29 | | - const [xCardCenter, yCardCenter] = [ |
30 | | - rect.left + rect.width / 2, |
31 | | - rect.top + rect.height / 2, |
32 | | - ]; |
33 | | - const offsets = [ |
34 | | - xViewportCenter - xCardCenter, |
35 | | - yViewportCenter - yCardCenter, |
36 | | - ]; |
37 | | - return offsets; |
38 | | -} |
39 | | - |
40 | | -export function SmallPortraitCard({ person, setOffsets }) { |
41 | | - const elementRef = useRef(null); |
| 8 | + function openDialog() { |
| 9 | + const completeName = person.completeName.replace(/\s+/g, ''); |
| 10 | + const completeNameWithoutAccents = completeName |
| 11 | + .normalize("NFD") |
| 12 | + .replace(/[\u0300-\u036f]/g, ''); |
| 13 | + history.push({ |
| 14 | + pathname: `/about/${completeNameWithoutAccents}`, |
| 15 | + state: { fromAbout: true, scrollY: window.scrollY, }, |
| 16 | + }); |
| 17 | + } |
42 | 18 |
|
43 | 19 | return ( |
44 | | - <div |
45 | | - ref={elementRef} |
46 | | - className={"card" + " " + styles.small_portrait_card} |
47 | | - id={person.firstName} |
48 | | - onClick={() => { |
49 | | - setOffsets(calculateOffsets(elementRef)); |
50 | | - }} |
51 | | - > |
52 | | - <div className="card__header"> |
53 | | - <Avatar person={person} /> |
54 | | - <div |
55 | | - className={ |
56 | | - "flex-full-centered" + " " + styles.small_card_complete_name |
57 | | - } |
58 | | - > |
59 | | - {person.completeName} |
60 | | - </div> |
61 | | - </div> |
62 | | - <div className="card__body"> |
63 | | - <div |
64 | | - className={"flex-full-centered" + " " + styles.small_card_position} |
65 | | - > |
66 | | - {person.position} |
67 | | - </div> |
68 | | - <div style={{ marginTop: "var(--ifm-spacing-xl)" }}> |
69 | | - <SocialMediaContacts person={person}></SocialMediaContacts> |
| 20 | + <div onClick={openDialog}> |
| 21 | + <div className={"card" + " " + styles.small_portrait_card}> |
| 22 | + <div className="card__header"> |
| 23 | + <Avatar person={person} /> |
| 24 | + <div |
| 25 | + className={ |
| 26 | + "flex-full-centered" + " " + styles.small_card_complete_name |
| 27 | + } |
| 28 | + > |
| 29 | + {person.completeName} |
| 30 | + </div> |
70 | 31 | </div> |
71 | | - </div> |
72 | | - </div> |
73 | | - ); |
74 | | -} |
75 | | -export default function PopupPortrait({ person }) { |
76 | | - const [offsets, setOffsets] = useState([0, 0]); |
77 | | - let [isPopupOpen, setIsPopupOpen] = useState(false); |
78 | | - |
79 | | - return ( |
80 | | - <div> |
81 | | - <Popup |
82 | | - open={isPopupOpen} |
83 | | - closeOnEscape={true} |
84 | | - closeOnDocumentClick={true} |
85 | | - onClose={() => setIsPopupOpen(false)} |
86 | | - trigger={ |
87 | | - <div> |
88 | | - <SmallPortraitCard person={person} setOffsets={setOffsets} /> |
| 32 | + <div className="card__body"> |
| 33 | + <div |
| 34 | + className={"flex-full-centered" + " " + styles.small_card_position} |
| 35 | + > |
| 36 | + {person.position} |
89 | 37 | </div> |
90 | | - } |
91 | | - onOpen={() => { |
92 | | - setIsPopupOpen(true); |
93 | | - }} |
94 | | - contentStyle={contentStyle} |
95 | | - overlayStyle={overlayStyle} |
96 | | - position={"center center"} |
97 | | - offsetX={offsets[0]} |
98 | | - offsetY={offsets[1]} |
99 | | - > |
100 | | - <div> |
101 | | - <button |
102 | | - className="close-button" |
103 | | - style={{ position: "absolute", right: "0px" }} |
104 | | - onClick={() => { |
105 | | - setIsPopupOpen(false); |
106 | | - }} |
107 | | - ></button> |
108 | | - <LargePortraitCard person={person}></LargePortraitCard> |
109 | 38 | </div> |
110 | | - </Popup> |
| 39 | + </div> |
111 | 40 | </div> |
112 | 41 | ); |
113 | 42 | } |
0 commit comments