Skip to content

Commit 4c5efcf

Browse files
authored
Merge pull request #12639 from TylerAPfledderer/refactor/ContentHero-content-adjustments
refactor(ContentHero): update and apply component usage
2 parents 5960b11 + 9e46d04 commit 4c5efcf

File tree

10 files changed

+118
-157
lines changed

10 files changed

+118
-157
lines changed

src/components/Hero/ContentHero/ContentHero.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { Meta, StoryObj } from "@storybook/react"
33

44
import ContentHeroComponent, { ContentHeroProps } from "."
55

6-
import contentHeroImg from "@/public/mainnet.png"
7-
86
type ContentHeroType = typeof ContentHeroComponent
97

108
const meta = {
@@ -51,7 +49,9 @@ export const ContentHero: StoryObj = {
5149
return (
5250
<ContentHeroComponent
5351
breadcrumbs={{ slug: "/en/run-a-node/" }}
54-
heroImg={contentHeroImg}
52+
heroImg="/upgrades/merge.png"
53+
// Can not properly hardcode this URL. So it's left blank
54+
blurDataURL=""
5555
title={t("hero-header")}
5656
description={t("hero-subtitle")}
5757
buttons={buttons}

src/components/Hero/ContentHero/index.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
import { Box, Heading, HStack, SimpleGrid, Stack, Text } from "@chakra-ui/react"
22

3-
import { CommonHeroProps } from "@/lib/types"
3+
import type { CommonHeroProps } from "@/lib/types"
44

5-
import Breadcrumbs, { BreadcrumbsProps } from "@/components/Breadcrumbs"
5+
import Breadcrumbs from "@/components/Breadcrumbs"
66
import { Image } from "@/components/Image"
77

88
import { CallToAction } from "../CallToAction"
99

10-
export interface ContentHeroProps extends Omit<CommonHeroProps, "header"> {
11-
breadcrumbs: BreadcrumbsProps
12-
}
10+
export type ContentHeroProps = Omit<CommonHeroProps<string>, "header">
1311

1412
const ContentHero = (props: ContentHeroProps) => {
15-
const { breadcrumbs, heroImg, buttons, title, description } = props
13+
const { breadcrumbs, heroImg, buttons, title, description, blurDataURL } =
14+
props
1615
return (
1716
<Box bgImg="bgMainGradient">
18-
<SimpleGrid columns={{ base: 1, lg: 2 }} maxW="1536px" mx="auto" gap="4">
17+
<SimpleGrid columns={{ base: 1, lg: 2 }} maxW="1536px" mx="auto">
1918
<Box
20-
height={{ base: "300px", md: "400px", lg: "full" }}
2119
order={{ lg: 1 }}
20+
height={{ base: "300px", md: "400px", lg: "full" }}
2221
>
2322
<Image
2423
src={heroImg}
2524
alt=""
2625
priority
27-
style={{ objectFit: "contain" }}
26+
blurDataURL={blurDataURL}
27+
width={760}
28+
height={451}
29+
sizes="(max-width: 992px) 100vw, 50vw"
2830
boxSize="full"
31+
style={{ objectFit: "contain" }}
32+
flex={{ base: "1 1 100%", md: "none" }}
2933
/>
3034
</Box>
3135
<Stack p={{ base: "8", lg: "16" }} spacing="9" justify="center">
@@ -34,13 +38,19 @@ const ContentHero = (props: ContentHeroProps) => {
3438
<Heading as="h1" size="2xl">
3539
{title}
3640
</Heading>
37-
<Text fontSize="lg">{description}</Text>
38-
<HStack spacing="4">
39-
{buttons!.map((button, idx) => {
40-
if (!button) return
41-
return <CallToAction key={idx} index={idx} {...button} />
42-
})}
43-
</HStack>
41+
{typeof description === "string" ? (
42+
<Text fontSize="lg">{description}</Text>
43+
) : (
44+
description
45+
)}
46+
{buttons && (
47+
<HStack spacing="4">
48+
{buttons.map((button, idx) => {
49+
if (!button) return
50+
return <CallToAction key={idx} index={idx} {...button} />
51+
})}
52+
</HStack>
53+
)}
4454
</Stack>
4555
{/* TODO:
4656
* Add conditional Big Stat box here

src/components/Hero/HubHero/HubHero.stories.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { useTranslation } from "next-i18next"
33
import { Box } from "@chakra-ui/react"
44
import { Meta, StoryObj } from "@storybook/react"
55

6-
import { CommonHeroProps } from "@/lib/types"
7-
8-
import HubHeroComponent from "./"
6+
import HubHeroComponent, { type HubHeroProps } from "./"
97

108
import learnHubHeroImg from "@/public/heroes/learn-hub-hero.png"
119

@@ -40,7 +38,7 @@ export const HubHero: StoryObj<typeof meta> = {
4038
// eslint-disable-next-line react-hooks/rules-of-hooks
4139
const { t } = useTranslation()
4240

43-
const buttons: CommonHeroProps["buttons"] = [
41+
const buttons: HubHeroProps["buttons"] = [
4442
{
4543
content: t("page-learn:hero-button-lets-get-started"),
4644
toId: "what-is-crypto-ethereum",
@@ -64,7 +62,7 @@ export const HubHero: StoryObj<typeof meta> = {
6462
<HubHeroComponent
6563
title={t(title)}
6664
header={t(header)}
67-
description={t(description)}
65+
description={t(description as string)}
6866
buttons={buttons}
6967
{...props}
7068
/>

src/components/Hero/HubHero/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import type { CommonHeroProps } from "@/lib/types"
55
import { CallToAction } from "@/components/Hero/CallToAction"
66
import { Image } from "@/components/Image"
77

8+
export type HubHeroProps = Omit<CommonHeroProps, "breadcrumbs" | "blurDataURL">
9+
810
const HubHero = ({
911
heroImg,
1012
title,
1113
header,
1214
description,
1315
buttons,
14-
}: CommonHeroProps) => {
16+
}: HubHeroProps) => {
1517
if (buttons && buttons.length > 2) {
1618
throw new Error(
1719
"Can not have more than two call-to-action buttons in this hero component."

src/components/Hero/MdxHero/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Heading, Stack } from "@chakra-ui/react"
22

3-
import { CommonHeroProps } from "@/lib/types"
3+
import type { CommonHeroProps } from "@/lib/types"
44

5-
import Breadcrumbs, { type BreadcrumbsProps } from "@/components/Breadcrumbs"
5+
import Breadcrumbs from "@/components/Breadcrumbs"
66

7-
export type MdxHeroProps = Pick<CommonHeroProps, "title"> & {
8-
breadcrumbs: BreadcrumbsProps
9-
}
7+
export type MdxHeroProps = Pick<CommonHeroProps, "breadcrumbs" | "title">
108

119
const MdxHero = ({ breadcrumbs, title }: MdxHeroProps) => (
1210
<Stack py="8" px="6" spacing="6" w="full">

src/layouts/Upgrade.tsx

Lines changed: 25 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { useRouter } from "next/router"
22
import { useTranslation } from "next-i18next"
3-
import { MdExpandMore } from "react-icons/md"
43
import {
54
Box,
65
type BoxProps,
7-
Flex,
86
type FlexProps,
9-
Icon,
107
List,
118
ListItem,
129
Text,
@@ -17,12 +14,10 @@ import type { ChildOnlyProp, Lang } from "@/lib/types"
1714
import type { MdPageContent, UpgradeFrontmatter } from "@/lib/interfaces"
1815

1916
import BeaconChainActions from "@/components/BeaconChainActions"
20-
import Breadcrumbs from "@/components/Breadcrumbs"
2117
import type { List as ButtonDropdownList } from "@/components/ButtonDropdown"
2218
import FeedbackCard from "@/components/FeedbackCard"
23-
import { Image } from "@/components/Image"
19+
import { ContentHero } from "@/components/Hero"
2420
import LeftNavBar from "@/components/LeftNavBar"
25-
import { BaseLink } from "@/components/Link"
2621
import {
2722
ContentContainer,
2823
MobileButton,
@@ -31,92 +26,27 @@ import {
3126
} from "@/components/MdComponents"
3227
import MergeArticleList from "@/components/MergeArticleList"
3328
import MergeInfographic from "@/components/MergeInfographic"
34-
import OldHeading from "@/components/OldHeading"
3529
import UpgradeStatus from "@/components/UpgradeStatus"
3630

3731
import { getSummaryPoints } from "@/lib/utils/getSummaryPoints"
3832
import { getLocaleTimestamp } from "@/lib/utils/time"
3933

40-
import { MAIN_CONTENT_ID } from "@/lib/constants"
41-
4234
const Page = (props: FlexProps) => <MdPage sx={{}} {...props} />
4335

44-
const Title = (props: ChildOnlyProp) => (
45-
<OldHeading
46-
as="h1"
47-
fontSize="2.5rem"
48-
fontWeight="bold"
49-
lineHeight={1.4}
50-
mt={0}
51-
{...props}
52-
/>
53-
)
54-
5536
type ContainerProps = Pick<BoxProps, "children" | "dir">
5637

5738
const Container = (props: ContainerProps) => (
5839
<Box position="relative" {...props} />
5940
)
6041

61-
const HeroContainer = (props: ChildOnlyProp) => (
62-
<Flex
63-
justify="flex-end"
64-
direction={{ base: "column-reverse", lg: "row" }}
65-
bg="cardGradient"
66-
boxShadow="inset 0px -1px 0px rgba(0, 0, 0, 0.1)"
67-
minH="608px"
68-
maxH={{ base: "full", lg: "608px" }}
69-
w="full"
70-
{...props}
71-
/>
72-
)
73-
74-
const MoreContent = (props: ChildOnlyProp & { to: string }) => (
75-
<Flex
76-
hideBelow="lg"
77-
as={BaseLink}
78-
bg="ednBackground"
79-
justify="center"
80-
p={4}
81-
w="full"
82-
_hover={{
83-
bg: "background.base",
84-
}}
85-
{...props}
86-
/>
87-
)
88-
89-
const TitleCard = (props: ChildOnlyProp) => {
90-
const cardBoxShadow = useToken("colors", "cardBoxShadow")
91-
92-
return (
93-
<Flex
94-
direction="column"
95-
justify="flex-start"
96-
position={{ base: "relative", lg: "absolute" }}
97-
bg={{ base: "ednBackground", lg: "background.base" }}
98-
border="1px"
99-
borderColor="border"
100-
borderRadius="sm"
101-
boxShadow={{ lg: cardBoxShadow }}
102-
maxW={{ base: "full", lg: "640px" }}
103-
p={8}
104-
top={{ lg: 24 }}
105-
insetInlineStart={{ lg: 24 }}
106-
zIndex={10}
107-
{...props}
108-
/>
109-
)
110-
}
111-
11242
const LastUpdated = (props: ChildOnlyProp) => (
11343
<Text
11444
color="text200"
11545
fontStyle="italic"
11646
pt={4}
11747
mb={0}
11848
borderTop="1px"
119-
borderColor="border"
49+
borderColor="body.dark"
12050
{...props}
12151
/>
12252
)
@@ -178,41 +108,29 @@ export const UpgradeLayout = ({
178108

179109
return (
180110
<Container dir={contentNotTranslated ? "ltr" : "unset"}>
181-
<HeroContainer>
182-
<TitleCard>
183-
<Breadcrumbs slug={slug} startDepth={1} mt={2} mb="8" />
184-
<Title>{frontmatter.title}</Title>
185-
<Box>
186-
<List listStyleType="disc">
187-
{summaryPoints.map((point, idx) => (
188-
<ListItem key={idx}>{point}</ListItem>
189-
))}
190-
</List>
191-
</Box>
192-
{lastUpdatedDate && (
193-
<LastUpdated>
194-
{t("common:page-last-updated")}:{" "}
195-
{getLocaleTimestamp(locale as Lang, lastUpdatedDate)}
196-
</LastUpdated>
197-
)}
198-
</TitleCard>
199-
{frontmatter.image && (
200-
<Image
201-
src={frontmatter.image}
202-
blurDataURL={frontmatter.blurDataURL}
203-
alt={frontmatter.alt}
204-
width={816}
205-
height={525}
206-
style={{ objectFit: "cover" }}
207-
priority
208-
flex={{ base: "1 1 100%", md: "none" }}
209-
alignSelf={{ base: "center", md: "flex-end" }}
210-
/>
211-
)}
212-
</HeroContainer>
213-
<MoreContent to={"#" + MAIN_CONTENT_ID}>
214-
<Icon as={MdExpandMore} fontSize="2xl" color="secondary" />
215-
</MoreContent>
111+
<ContentHero
112+
breadcrumbs={{ slug, startDepth: 1 }}
113+
title={frontmatter.title}
114+
description={
115+
<>
116+
<Box>
117+
<List listStyleType="disc">
118+
{summaryPoints.map((point, idx) => (
119+
<ListItem key={idx}>{point}</ListItem>
120+
))}
121+
</List>
122+
</Box>
123+
{lastUpdatedDate && (
124+
<LastUpdated>
125+
{t("common:page-last-updated")}:{" "}
126+
{getLocaleTimestamp(locale as Lang, lastUpdatedDate)}
127+
</LastUpdated>
128+
)}
129+
</>
130+
}
131+
heroImg={frontmatter.image}
132+
blurDataURL={frontmatter.blurDataURL}
133+
/>
216134
<Page>
217135
{/* TODO: Switch to `above="lg"` after completion of Chakra Migration */}
218136
<LeftNavBar

0 commit comments

Comments
 (0)