parent
801a200664
commit
d296fe2d7b
@ -1,27 +1,81 @@ |
||||
import React from "react"; |
||||
import React, { useState } from "react"; |
||||
import { Image } from "./Image"; |
||||
import useWindowDimensions from "../hooks/useWindowDimension"; |
||||
import styles from "./TeamMemberCard.module.css"; |
||||
|
||||
interface TeamMemberCardProps { |
||||
export interface TeamMemberCardProps { |
||||
name: string; |
||||
role: string; |
||||
image?: string; // path to image of person, relative to public directory
|
||||
children: React.ReactNode; |
||||
} |
||||
|
||||
export function TeamMemberCard(props: TeamMemberCardProps) { |
||||
export function TeamMemberCard({ |
||||
name, |
||||
image, |
||||
role, |
||||
children, |
||||
}: TeamMemberCardProps) { |
||||
const { width } = useWindowDimensions(); |
||||
const [isOpen, setIsOpen] = useState(false); |
||||
const handleClick = () => { |
||||
if (width <= 768) { |
||||
setIsOpen(!isOpen); |
||||
} |
||||
}; |
||||
return ( |
||||
<article className={styles.card}> |
||||
<div className={styles.picture}> |
||||
<Image |
||||
className={styles.image} |
||||
src={props.image ?? "/images/team-member-placeholder.svg"} |
||||
alt={`Picture of ${props.name}`} |
||||
/> |
||||
<> |
||||
<article className={styles.card} onClick={handleClick}> |
||||
<div className={styles.picture}> |
||||
<Image |
||||
className={styles.image} |
||||
src={image ?? "/images/team/team-member-placeholder.png"} |
||||
alt={`Picture of ${name}`} |
||||
/> |
||||
</div> |
||||
<h1 className={styles.name}>{name}</h1> |
||||
<h2 className={styles.role}>{role}</h2> |
||||
<div className={styles.description}>{children}</div> |
||||
</article> |
||||
{isOpen && ( |
||||
<ExecPopup |
||||
name={name} |
||||
role={role} |
||||
image={image} |
||||
handleClick={handleClick} |
||||
> |
||||
{children} |
||||
</ExecPopup> |
||||
)} |
||||
</> |
||||
); |
||||
} |
||||
|
||||
interface Propup extends TeamMemberCardProps { |
||||
handleClick: () => void; |
||||
} |
||||
|
||||
function ExecPopup({ name, image, role, children, handleClick }: Propup) { |
||||
return ( |
||||
<> |
||||
<div className={styles.popup_background} onClick={handleClick} /> |
||||
<div className={styles.popup_container}> |
||||
<button className={styles.close_btn} onClick={handleClick}> |
||||
<Image src="images/team/popup-close.svg" /> |
||||
</button> |
||||
<div className={styles.popup_content}> |
||||
<div className={styles.picture}> |
||||
<Image |
||||
className={styles.popup_image} |
||||
src={image ?? "/images/team/team-member-placeholder.png"} |
||||
alt={`Picture of ${name}`} |
||||
/> |
||||
</div> |
||||
<h1 className={styles.popup_name}>{name}</h1> |
||||
<h2 className={styles.popup_role}>{role}</h2> |
||||
<div className={styles.popup_description}>{children}</div> |
||||
</div> |
||||
</div> |
||||
<h1 className={styles.name}>{props.name}</h1> |
||||
<h2 className={styles.role}>{props.role}</h2> |
||||
<div className={styles.description}>{props.children}</div> |
||||
</article> |
||||
</> |
||||
); |
||||
} |
||||
|
@ -1,7 +1,7 @@ |
||||
--- |
||||
name: Nakul Vijhani |
||||
role: Assistant Vice President |
||||
image: /images/team/team-member-placeholder.svg |
||||
image: |
||||
--- |
||||
|
||||
words words words codey words words words words codey words words words words codey words words words words codey words words words words codey words words words words words codey words words words words codey words words words words codey words words words words codey words words words |
@ -0,0 +1,39 @@ |
||||
import { useEffect, useState } from "react"; |
||||
|
||||
interface WindowDimension { |
||||
width: number; |
||||
height: number; |
||||
} |
||||
|
||||
function getWindowDimension() { |
||||
const { innerWidth: width, innerHeight: height } = window; |
||||
return { |
||||
width, |
||||
height, |
||||
}; |
||||
} |
||||
|
||||
function useWindowDimension(): WindowDimension { |
||||
const [windowSize, setWindowDimension] = useState<WindowDimension>({ |
||||
width: 0, |
||||
height: 0, |
||||
}); |
||||
|
||||
useEffect(() => { |
||||
const handleResize = () => { |
||||
setWindowDimension(getWindowDimension()); |
||||
}; |
||||
|
||||
// Set size at the first client-side load
|
||||
handleResize(); |
||||
window.addEventListener("resize", handleResize); |
||||
|
||||
return () => { |
||||
window.removeEventListener("resize", handleResize); |
||||
}; |
||||
}, []); |
||||
|
||||
return windowSize; |
||||
} |
||||
|
||||
export default useWindowDimension; |
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 173 KiB |
Loading…
Reference in new issue