|
| 1 | +import { useMemo } from "react"; |
| 2 | +import { Trans } from "react-i18next"; |
| 3 | +import { Box, Link } from "@mui/material"; |
| 4 | +import { ArrowDownward } from "@mui/icons-material"; |
| 5 | + |
| 6 | +import { Button, Typography } from "@atoms"; |
| 7 | +import { IMAGES } from "@consts"; |
| 8 | +import { useScreenDimension, useTranslation } from "@hooks"; |
| 9 | +import { openInNewTab } from "@utils"; |
| 10 | + |
| 11 | +export const Hero = () => { |
| 12 | + const { isMobile, screenWidth } = useScreenDimension(); |
| 13 | + const { t } = useTranslation(); |
| 14 | + const IMAGE_SIZE = screenWidth < 640 ? 300 : screenWidth < 860 ? 400 : 600; |
| 15 | + |
| 16 | + const paddingHorizontal = useMemo(() => { |
| 17 | + if (screenWidth < 640) return 3; |
| 18 | + if (screenWidth < 1512) return 9.375; |
| 19 | + if (screenWidth < 1728) return 14; |
| 20 | + if (screenWidth < 1920) return 27.375; |
| 21 | + if (screenWidth < 2560) return 39.375; |
| 22 | + return 49.25; |
| 23 | + }, [screenWidth]); |
| 24 | + |
| 25 | + const imageRightMargin = useMemo(() => { |
| 26 | + if (screenWidth <= 860) return -(IMAGE_SIZE / 4); |
| 27 | + if (screenWidth <= 1440) return -(IMAGE_SIZE / 15); |
| 28 | + if (screenWidth <= 1728) return screenWidth / 20; |
| 29 | + return screenWidth / 11; |
| 30 | + }, [screenWidth]); |
| 31 | + |
| 32 | + const onClickVotingPower = () => |
| 33 | + openInNewTab("https://docs.cardano.org/about-cardano/governance-overview"); |
| 34 | + |
| 35 | + return ( |
| 36 | + <Box |
| 37 | + alignItems="center" |
| 38 | + display="flex" |
| 39 | + flex={1} |
| 40 | + marginTop={16} |
| 41 | + flexDirection="row" |
| 42 | + overflow="visible" |
| 43 | + position="relative" |
| 44 | + px={paddingHorizontal} |
| 45 | + > |
| 46 | + <Box alignItems="center" flex={1} height="min-content"> |
| 47 | + <Typography |
| 48 | + variant={screenWidth < 860 ? "headline2" : "headline1"} |
| 49 | + sx={{ whiteSpace: "pre-line" }} |
| 50 | + {...(screenWidth < 430 && { fontSize: 50 })} |
| 51 | + > |
| 52 | + {t("hero.headline")} |
| 53 | + </Typography> |
| 54 | + <Typography |
| 55 | + fontWeight={400} |
| 56 | + sx={{ |
| 57 | + maxWidth: 725, |
| 58 | + my: 4, |
| 59 | + whiteSpace: "pre-line", |
| 60 | + }} |
| 61 | + variant="title2" |
| 62 | + > |
| 63 | + <Trans |
| 64 | + i18nKey="hero.description" |
| 65 | + components={[ |
| 66 | + <Link |
| 67 | + data-testid="voting-power-link" |
| 68 | + onClick={onClickVotingPower} |
| 69 | + sx={{ |
| 70 | + cursor: "pointer", |
| 71 | + }} |
| 72 | + />, |
| 73 | + ]} |
| 74 | + /> |
| 75 | + </Typography> |
| 76 | + <Button |
| 77 | + data-testid="hero-connect-wallet-button" |
| 78 | + onClick={() => { |
| 79 | + const homeCards = |
| 80 | + window.document.getElementsByClassName("home-cards")[0]; |
| 81 | + |
| 82 | + homeCards.scrollIntoView({ |
| 83 | + behavior: "smooth", |
| 84 | + block: "nearest", |
| 85 | + }); |
| 86 | + }} |
| 87 | + endIcon={<ArrowDownward />} |
| 88 | + size={isMobile ? "medium" : "extraLarge"} |
| 89 | + > |
| 90 | + {t("hero.connectWallet")} |
| 91 | + </Button> |
| 92 | + </Box> |
| 93 | + <Box |
| 94 | + flex={1} |
| 95 | + position="absolute" |
| 96 | + right={imageRightMargin} |
| 97 | + top={-80} |
| 98 | + zIndex={-1} |
| 99 | + > |
| 100 | + <img |
| 101 | + alt="hero" |
| 102 | + src={IMAGES.heroImage} |
| 103 | + width={IMAGE_SIZE} |
| 104 | + height={IMAGE_SIZE} |
| 105 | + /> |
| 106 | + </Box> |
| 107 | + </Box> |
| 108 | + ); |
| 109 | +}; |
0 commit comments