Skip to content

Commit

Permalink
feat: add a profile card component; add hover & click effect; add a c…
Browse files Browse the repository at this point in the history
…losing tab on cards (#390)

* feat: add a profile card component;
add hover & click effect;
add closing tab on cards

* fix: rename profile card & prop; type for useState
  • Loading branch information
xinyue296 authored May 23, 2022
1 parent 7c6cd35 commit 626ceca
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 95 deletions.
100 changes: 5 additions & 95 deletions root/src/components/aboutUs/MeetOurTeam/MeetOurTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import styled from "styled-components";

import {
AlumniList,
CurrentList,
Members,
CurrentList
} from "@app/components/aboutUs/MeetOurTeam/memberList";

import { ProfileCard } from "@app/components/block/ProfileCard";

const Title = styled("h2")`
font-weight: bold;
text-align: center;
Expand All @@ -30,97 +31,6 @@ const CardArea = styled("div")`
justify-content: space-evenly;
`;

const Card = styled("div")`
display: flex;
flex-direction: column;
align-items: center;
width: 260px;
text-align: center;
`;

const SocialMediaArea = styled("div")`
text-align: center;
display: flex;
flex-direction: row;
align-items: center;
`;

const MediaIcon = styled("img")`
width: 100%;
width: 1.3em;
margin: 6px 8px 4px 0px;
text-align: center;
`;

const MemberCard = ({
image,
name,
positions,
socials,
profileText,
}: Members) => (
<Card className="m-2 md:m-3.5 xl:x-4">
<a className="block group" href="#">
{/* Card: pic + hidden card-body + Name */}
<div className="card w-auto bg-transparent group-hover:card-side group-hover:rounded-8xl group-hover:bg-gradient-to-r group-hover:from-light-card2 group-hover:via-light-card1 group-hover:to-transparent dark:group-hover:bg-gradient-to-r dark:group-hover:from-dark-card2 group-hover:drop-shadow-lg">
{/* Profile pic */}
<figure className="px-3 py-3 sm:px-5 sm:py-5">
{/* responsive for smaller screen: w/h - [100px] */}
<img
className="mask mask-squircle object-cover opacity-100 transition-opacity group-hover:drop-shadow-none w-[150px] h-[150px] sm:w-[200px] sm:h-[200px]"
src={image}
/>
</figure>
{/* Card Body */}
<div className="card-body items-left text-left w-[200px] sm:w-[260px] hidden group-hover:block transition ease-in-out delay-300ms transition-duration: 1500ms opacity-0 group-hover:opacity-100 p-[10px] sm:p-[20px]">
{/* Name */}
<p className="card-title font-bold text-3xl text-light-text1 dark:text-dark-text1 mt-6 mb-3 ml-1.5">
{name}
</p>
{/* Position */}
<div className="justify-start text-left inline-block drop-shadow-none my-1.5">
{positions &&
positions.map((position) => (
<div
className="badge w-auto h-auto sm:h-10 mr-1.5 mt-1.5 font-normal text-lg sm:text-xl border-transparent text-light-text2 bg-light-card3
dark:text-dark-text2 dark:bg-dark-card2"
>
{position}
</div>
))}

{/* Profile Text */}
<p className="justify-start mt-3 mb-2 pl-1.5 font-medium text-lg sm:text-xl leading-normal text-light-text2 dark:text-dark-text2">
{profileText}
</p>

{/* Socials */}
<div className="justify-start inline-block mx-1.5">
{socials && (
<SocialMediaArea>
{socials.map((social) => (
<a
href={social.link}
target="_blank"
rel="noopener noreferrer"
>
<MediaIcon src={social.platform} />
</a>
))}
</SocialMediaArea>
)}
</div>
</div>
</div>
</div>
{/* Name below the card*/}
<p className="text-center py-1.5 px-3 sm:px-5 group-hover:hidden font-bold text-2xl sm:text-3xl text-light-text1 dark:text-dark-text1">
{name}
</p>
</a>
</Card>
);

const MeetOurTeam = () => {
const { t } = useTranslation();

Expand All @@ -134,7 +44,7 @@ const MeetOurTeam = () => {
</SubTitle>
<CardArea>
{CurrentList.map((member) => (
<MemberCard
<ProfileCard
image={member.image}
name={member.name}
positions={member.positions}
Expand All @@ -149,7 +59,7 @@ const MeetOurTeam = () => {
</SubTitle>
<CardArea>
{AlumniList.map((member) => (
<MemberCard
<ProfileCard
image={member.image}
name={member.name}
positions={member.positions}
Expand Down
143 changes: 143 additions & 0 deletions root/src/components/block/ProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, { useState } from "react";
import styled from "styled-components";

const Card = styled("div")`
display: flex;
flex-direction: column;
align-items: center;
width: 260px;
text-align: center;
`;

const SocialMediaArea = styled("div")`
text-align: center;
display: flex;
flex-direction: row;
align-items: center;
`;

const MediaIcon = styled("img")`
width: 100%;
width: 1.3em;
margin: 6px 8px 4px 0px;
text-align: center;
`;

export interface ProfileCardProps {
image: string;
name: string;
positions: Array<string>;
socials?: Array<{ platform: string; link: string }>;
profileText?: string;
// mini?: boolean;
}

export const ProfileCard = ({
image,
name,
positions,
socials,
profileText,
}: // mini,
ProfileCardProps) => {
const [showCard, setShowCard] = useState<boolean>(false);
const handleClick = () => {
setShowCard(!showCard);
};

return (
<Card
className="block group cursor-pointer transition ease-in-out delay-300ms transition-duration:1500ms md:mx-8 md:my-6 lg:mx-10 lg:my-8"
onClick={handleClick}
>
{showCard ? (
<div
// Card: pic + hidden card-body + Name
className="card w-auto card-side rounded-8xl bg-gradient-to-r from-light-card2 to-light-card1 dark:bg-gradient-to-r dark:from-dark-card2 dark:to-dark-bgMain drop-shadow-lg translate-x-[5px] transition ease-in-out delay-200ms transition-duration:3000ms my-[9px] sm:my-[16px] z-20"
>
{/* Profile pic */}
<figure className="px-3 py-3 sm:px-5 sm:py-5">
{/* responsive for smaller screen: w/h - [100px] */}
<img
className="mask mask-squircle object-cover w-[150px] h-[150px] sm:w-[200px] sm:h-[200px]"
src={image}
/>
</figure>
{/* Card Body */}
<div className="card-body items-left text-left w-[200px] sm:w-[260px] block opacity-100 p-[10px] sm:p-[20px]">
{/* close button from daisyui */}
<div className="card-actions justify-end">
<button className="btn btn-square btn-sm border-transparent hover:border-transparent bg-light-card1 hover:bg-light-card2 focus:bg-light-card3 dark:bg-transparent dark:hover:bg-dark-card1 dark:focus:bg-dark-card2">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 stroke-light-darker dark:stroke-dark-main"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
{/* Name */}
<p className="card-title font-bold text-3xl text-light-text1 dark:text-dark-text1 mt-6 mb-3 ml-1.5">
{name}
</p>
{/* Position */}
<div className="justify-start text-left inline-block drop-shadow-none my-1.5">
{positions &&
positions.map((position) => (
<div
className="badge w-auto h-auto sm:h-10 mr-1.5 mt-1.5 font-normal text-lg sm:text-xl border-transparent text-light-text2 bg-light-card3
dark:text-dark-text2 dark:bg-dark-card2"
>
{position}
</div>
))}
{/* Profile Text */}
<p className="justify-start mt-3 mb-2 pl-1.5 font-medium text-lg sm:text-xl leading-normal text-light-text2 dark:text-dark-text2">
{profileText}
</p>
{/* Socials */}
<div className="justify-start inline-block mx-1.5">
{socials && (
<SocialMediaArea>
{socials.map((social) => (
<a
href={social.link}
target="_blank"
rel="noopener noreferrer"
>
<MediaIcon src={social.platform} />
</a>
))}
</SocialMediaArea>
)}
</div>
</div>
</div>
</div>
) : (
<div>
<div>
<p className="text-center text-lg sm:text-xl text-transparent font-bold group-hover:text-light-text2 dark:group-hover:text-dark-text1 translate-y-[85px] sm:translate-y-[110px] z-10">
Click to view the profile!
</p>
<img
className="mask mask-squircle object-cover opacity-100 w-[150px] h-[150px] sm:w-[200px] sm:h-[200px] m-2 z-0 group-hover:opacity-30"
src={image}
/>
</div>
{/* Name below the card*/}
<p className="text-center py-1.5 px-3 sm:px-5 font-bold text-2xl sm:text-3xl text-light-text1 dark:text-dark-text1">
{name}
</p>
</div>
)}
</Card>
);
};

0 comments on commit 626ceca

Please sign in to comment.