-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extracts ProjectTitle into own component
- creates ProjectTitle component with simplified code - extracts VerifiedBadge (popover) code to separate component - moves specific component styles - from global styles (donations.scss) - moves mui theme based styles to theme - separates logic to show project info from render statement - gives a min width to popover (refer #408) - removes code duplication of popover code (ref #408) - aligns verified icon and project title (ref #408)
- Loading branch information
Showing
6 changed files
with
144 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ReactElement } from "react"; | ||
import { | ||
FetchedProjectDetails, | ||
PlanetCashSignupDetails, | ||
} from "src/Common/Types"; | ||
import VerifiedBadge from "./VerifiedBadge"; | ||
import styles from "./LeftPanel.module.scss"; | ||
|
||
interface Props { | ||
projectDetails: FetchedProjectDetails | PlanetCashSignupDetails; | ||
isMobile: boolean; | ||
} | ||
|
||
const ProjectTitle = ({ projectDetails, isMobile }: Props): ReactElement => { | ||
const isLinked = | ||
projectDetails.purpose === "trees" || | ||
projectDetails.purpose === "conservation"; | ||
|
||
return ( | ||
<div className={`${styles["project-title"]} title-text`}> | ||
{isLinked ? ( | ||
<a | ||
rel="noreferrer" | ||
target="_blank" | ||
href={`https://www.trilliontreecampaign.org/${projectDetails.id}`} | ||
> | ||
<h1>{projectDetails.name}</h1> | ||
</a> | ||
) : ( | ||
<h1>{projectDetails.name}</h1> | ||
)} | ||
{projectDetails.name && projectDetails?.isApproved && ( | ||
<VerifiedBadge isMobile={isMobile} /> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProjectTitle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ReactElement, useState, MouseEvent } from "react"; | ||
import { useTranslation } from "next-i18next"; | ||
import VerifiedIcon from "@mui/icons-material/Verified"; | ||
import { Typography, Popover } from "@mui/material"; | ||
import styles from "./LeftPanel.module.scss"; | ||
|
||
interface Props { | ||
isMobile: boolean; | ||
} | ||
|
||
const VerifiedBadge = ({ isMobile }: Props): ReactElement => { | ||
const { t } = useTranslation("common"); | ||
|
||
const [anchorElement, setAnchorElement] = useState<HTMLElement | null>(null); | ||
const isPopoverOpen = anchorElement !== null; | ||
|
||
const handlePopoverOpen = (event: MouseEvent<HTMLElement>) => { | ||
setAnchorElement(event.currentTarget); | ||
}; | ||
|
||
const handlePopoverClose = () => { | ||
setAnchorElement(null); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div | ||
aria-owns={isPopoverOpen ? "mouse-over-popover" : undefined} | ||
aria-haspopup="true" | ||
onMouseEnter={handlePopoverOpen} | ||
onMouseLeave={handlePopoverClose} | ||
className={styles["verified-badge"]} | ||
> | ||
<VerifiedIcon sx={{ color: "#fff" }} /> | ||
</div> | ||
<Popover | ||
id="mouse-over-popover" | ||
className={styles["verified-badge-popup"]} | ||
open={isPopoverOpen} | ||
anchorEl={anchorElement} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "left", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: isMobile ? "center" : "left", | ||
}} | ||
onClose={handlePopoverClose} | ||
disableRestoreFocus | ||
marginThreshold={0} | ||
> | ||
<Typography>{t("verifiedIconInfo")}</Typography> | ||
</Popover> | ||
</> | ||
); | ||
}; | ||
|
||
export default VerifiedBadge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters