|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState } from "react"; |
| 4 | +import Image from "next/image"; |
| 5 | +import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; |
| 6 | +import type { ExcoMember, ExcoLink } from "@/lib/exco"; |
| 7 | +import { cn } from "@/lib/utils"; |
| 8 | +import { Mail, Globe } from "lucide-react"; |
| 9 | +import { SiGithub, SiInstagram } from "@icons-pack/react-simple-icons"; |
| 10 | +import { FaLinkedin } from "react-icons/fa"; |
| 11 | +import { FaXTwitter } from "react-icons/fa6"; |
| 12 | + |
| 13 | +function SocialIcon({ link }: { link: ExcoLink }) { |
| 14 | + const common = "h-4 w-4"; |
| 15 | + switch (link.type) { |
| 16 | + case "email": |
| 17 | + return <Mail className={common} />; |
| 18 | + case "github": |
| 19 | + return <SiGithub size={16} />; |
| 20 | + case "instagram": |
| 21 | + return <SiInstagram size={16} />; |
| 22 | + case "linkedin": |
| 23 | + return <FaLinkedin size={16} />; |
| 24 | + case "website": |
| 25 | + return <Globe className={common} />; |
| 26 | + case "x": |
| 27 | + return <FaXTwitter size={16} />; |
| 28 | + default: |
| 29 | + return null; |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +type ExcoCardProps = { |
| 34 | + member: ExcoMember; |
| 35 | + className?: string; |
| 36 | +}; |
| 37 | + |
| 38 | +export function ExcoCard({ member, className }: ExcoCardProps) { |
| 39 | + const hasPhoto = !!member.photoSrc; |
| 40 | + const containerHeightClass = hasPhoto ? "h-56" : "h-32"; |
| 41 | + const innerBase = "relative w-full transition-transform duration-500 [transform-style:preserve-3d]"; |
| 42 | + const innerHover = "group-hover:[transform:rotateY(180deg)]"; |
| 43 | + const [isFlipped, setIsFlipped] = useState(false); |
| 44 | + const flipActiveClass = isFlipped ? "[transform:rotateY(180deg)]" : ""; |
| 45 | + return ( |
| 46 | + <div |
| 47 | + className={cn("group cursor-pointer select-none", "[perspective:1000px]", className)} |
| 48 | + role="button" |
| 49 | + tabIndex={0} |
| 50 | + onClick={() => setIsFlipped((v) => !v)} |
| 51 | + onKeyDown={(e) => { |
| 52 | + if (e.key === "Enter" || e.key === " ") { |
| 53 | + e.preventDefault(); |
| 54 | + setIsFlipped((v) => !v); |
| 55 | + } |
| 56 | + }} |
| 57 | + > |
| 58 | + <div className={cn(innerBase, innerHover, flipActiveClass, containerHeightClass)}> |
| 59 | + <FrontFace member={member} /> |
| 60 | + <BackFace member={member} /> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + ); |
| 64 | +} |
| 65 | + |
| 66 | +function FrontFace({ member }: { member: ExcoMember }) { |
| 67 | + const hasPhoto = !!member.photoSrc; |
| 68 | + return ( |
| 69 | + <Card className="absolute inset-0 [backface-visibility:hidden]"> |
| 70 | + <div className="h-full w-full flex flex-col items-center justify-center text-center p-4"> |
| 71 | + {hasPhoto ? ( |
| 72 | + <div className="relative h-16 w-16 mx-auto rounded-full overflow-hidden ring-1 ring-border"> |
| 73 | + <Image |
| 74 | + src={member.photoSrc as string} |
| 75 | + alt={`${member.name} photo`} |
| 76 | + fill |
| 77 | + sizes="64px" |
| 78 | + className="object-cover" |
| 79 | + /> |
| 80 | + </div> |
| 81 | + ) : null} |
| 82 | + <CardTitle className="mt-1">{member.name}</CardTitle> |
| 83 | + <CardDescription>{member.position}</CardDescription> |
| 84 | + </div> |
| 85 | + </Card> |
| 86 | + ); |
| 87 | +} |
| 88 | + |
| 89 | +function BackFace({ member }: { member: ExcoMember }) { |
| 90 | + const hasBio = !!member.bio; |
| 91 | + const hasLinks = !!(member.links && member.links.length > 0); |
| 92 | + return ( |
| 93 | + <Card className="absolute inset-0 [transform:rotateY(180deg)] [backface-visibility:hidden]"> |
| 94 | + <div className="h-full flex flex-col items-center text-center ml-1 mr-1"> |
| 95 | + {!hasBio && !hasLinks ? ( |
| 96 | + <p className="m-auto text-muted-foreground">More info coming soon</p> |
| 97 | + ) : ( |
| 98 | + <> |
| 99 | + {hasBio ? ( |
| 100 | + <div className="w-full"> |
| 101 | + <CardHeader className="p-0"> |
| 102 | + <CardTitle>About</CardTitle> |
| 103 | + <CardDescription>{member.bio}</CardDescription> |
| 104 | + </CardHeader> |
| 105 | + </div> |
| 106 | + ) : null} |
| 107 | + {hasLinks ? ( |
| 108 | + <div className="flex items-center justify-center gap-3 pt-3"> |
| 109 | + {member.links!.map((link) => ( |
| 110 | + <a |
| 111 | + key={`${member.name}-${link.type}-${link.url}`} |
| 112 | + href={link.type === "email" ? `mailto:${link.url}` : link.url} |
| 113 | + target={link.type === "email" ? undefined : "_blank"} |
| 114 | + rel={link.type === "email" ? undefined : "noopener"} |
| 115 | + aria-label={link.type} |
| 116 | + className="text-muted-foreground hover:text-foreground" |
| 117 | + onClick={(e) => e.stopPropagation()} |
| 118 | + onTouchStart={(e) => e.stopPropagation()} |
| 119 | + > |
| 120 | + <SocialIcon link={link} /> |
| 121 | + </a> |
| 122 | + ))} |
| 123 | + </div> |
| 124 | + ) : null} |
| 125 | + </> |
| 126 | + )} |
| 127 | + </div> |
| 128 | + </Card> |
| 129 | + ); |
| 130 | +} |
0 commit comments