Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Hero): create multiple hero components for new DS #11132

Merged
merged 27 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5dcfcdc
feat(Hero): create multiple hero components for new DS
TylerAPfledderer Jul 20, 2023
0b4f4e9
Merge remote-tracking branch 'origin/dev' into feat/hero-new-ds
TylerAPfledderer Sep 12, 2023
feba0e4
fix(Hero/utils): set optional tuple element for buttons
TylerAPfledderer Sep 18, 2023
25c443b
feat(pages/learn): implement `HubHero`
TylerAPfledderer Sep 18, 2023
8e83d10
Merge remote-tracking branch 'origin/dev' into feat/hero-new-ds
TylerAPfledderer Sep 20, 2023
cbe229b
refactor(Hero): use custom globalized `GatsbyImage`
TylerAPfledderer Sep 20, 2023
53286dd
fix(ContentHero): return empty for undefined button in iterative
TylerAPfledderer Sep 20, 2023
1e92f6e
refactor(Hero): create central import entry
TylerAPfledderer Sep 20, 2023
5344f14
refactor(ContentHero): allow entire `Breadcrumbs` prop object to be p…
TylerAPfledderer Sep 23, 2023
3a14aaf
refactor(ContentHero): render heading as `h1`
TylerAPfledderer Sep 23, 2023
1357ecd
chore(MdxHero): change `heroTitle` prop to `title`
TylerAPfledderer Sep 23, 2023
256fffc
chore(CallToAction): remove double import
TylerAPfledderer Sep 23, 2023
d1ebcc5
chore(CallToAction): add `content` as an omitted prop from `ButtonProps`
TylerAPfledderer Sep 24, 2023
1cb49e6
refactor(Hero): add `title` to `CommonHeroProps`
TylerAPfledderer Sep 24, 2023
7d388ec
refactor(CallToAction): change type signature for `index` prop
TylerAPfledderer Sep 24, 2023
f250f3c
fix(Hero): update prop names used in stories
TylerAPfledderer Sep 24, 2023
07619e5
style(MdxHero): remove margin from breadcrumbs and add TODO reminder
TylerAPfledderer Sep 24, 2023
051f51e
Merge branch 'dev' into feat/hero-new-ds
pettinarip Sep 26, 2023
7e4793e
fix(Hero): update imports from `Buttons`
TylerAPfledderer Sep 27, 2023
700bb5b
Merge remote-tracking branch 'origin/dev' into feat/hero-new-ds
TylerAPfledderer Oct 3, 2023
136ccde
style(Hero): remove unneeded spacing override for breadcrumbs
TylerAPfledderer Oct 3, 2023
879e611
Merge remote-tracking branch 'origin/dev' into feat/hero-new-ds
TylerAPfledderer Oct 18, 2023
e2556af
feat(pages/learn): use new image for learn hub hero
TylerAPfledderer Oct 18, 2023
888b973
fix(pages/learn): add spacing beneath the hero on mobile
TylerAPfledderer Oct 18, 2023
36a722b
chore(learn-hub-hero): supply higher-quality image
TylerAPfledderer Oct 19, 2023
9b35261
style(Morpher): update color to `body.medium`
TylerAPfledderer Oct 24, 2023
21ca922
refactor(pages/index): apply new home hero
TylerAPfledderer Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .storybook/i18next.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import i18n, { Resource } from "i18next"
import { initReactI18next } from "gatsby-plugin-react-i18next"
import fs from "fs"

export const baseLocales = {
en: { title: "English", left: "En" },
Expand All @@ -15,6 +14,7 @@ const ns = [
"glossary",
"page-about",
"page-index",
"page-learn",
"page-upgrades",
"page-developers-index",
]
Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config: StorybookConfig = {
"@chakra-ui/storybook-addon",
"storybook-react-i18next",
],
staticDirs: ["../static"],
staticDirs: ["../static", "../src/assets"],
babel: async () => ({
...babelConfig,
}),
Expand Down
8 changes: 4 additions & 4 deletions docs/ds-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Follow the new component directory structure:
```markdown
src/
└── components/
└── ComponentA/
├── index.tsx
├── ComponentA.stories.tsx
└── // Any other files as applicable (utils, child components, useHook, etc.)
└── ComponentA/
├── index.tsx
├── ComponentA.stories.tsx
└── // Any other files as applicable (utils, child components, useHook, etc.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this autoformat was triggered when dev was merged to update the branch. Lets revert this changes as this format is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pettinarip Darnit. Every time I try to save the changes locally, it wants to fix the formatting. -_-

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think is because it is coming as a new/modified file when you update the branch with dev (that is caught by prettier). Shouldn't happen in the upcoming PRs you make.

```

## Components creation/modification from the DS
Expand Down
Binary file added src/assets/ethereum-eth2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/mainnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions src/components/Hero/CallToAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from "react"
import Button, { IProps as ButtonProps } from "../Button"
import { MatomoEventOptions, trackCustomEvent } from "../../utils/matomo"
import { ReactNode } from "react"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import order


type CallToActionProps = Omit<ButtonProps, "children"> & {
content: ReactNode
matomo: MatomoEventOptions
index: React.Key
}

export function CallToAction(props: CallToActionProps) {
const { content, matomo, index, ...rest } = props

const handleClick = () => trackCustomEvent(matomo)

const buttonProps: ButtonProps = {
variant: index === 0 ? "solid" : "outline",
isSecondary: index !== 0,
flex: { base: 1, md: "initial" },
}

return (
<Button onClick={handleClick} {...buttonProps} {...rest}>
{content}
</Button>
)
}

/**
* Props to be passed to through the hero component. `index` prop not used here.
*/
export type CTAParentProps = Omit<CallToActionProps, "index">
79 changes: 79 additions & 0 deletions src/components/Hero/ContentHero/ContentHero.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as React from "react"
import { Meta, StoryObj } from "@storybook/react"
import ContentHeroComponent, { ContentHeroProps } from "."
import { IGatsbyImageData } from "gatsby-plugin-image"
import { useTranslation } from "gatsby-plugin-react-i18next"

type ContentHeroType = typeof ContentHeroComponent

const meta = {
title: "Organisms / Layouts / Hero",
component: ContentHeroComponent,
parameters: {
layout: "none",
},
argTypes: {
heroImgSrc: {
table: {
disable: true,
},
},
},
} satisfies Meta<ContentHeroType>

export default meta

// Comes from the original compiled querying
const mockGatsbyImgData: IGatsbyImageData = {
layout: "constrained",
images: {
fallback: {
src: "/mainnet.png",
sizes: "100vw",
},
sources: [
{
srcSet: "/mainnet.png",
type: "image/webp",
sizes: "100vw",
},
],
},
width: 1,
height: 1,
}

export const ContentHero: StoryObj = {
render: () => {
const { t } = useTranslation()

const buttons: ContentHeroProps["buttons"] = [
{
content: t("hero-button-lets-get-started"),
toId: "what-is-crypto-ethereum",
matomo: {
eventCategory: "learn hub hero buttons",
eventAction: "click",
eventName: "lets get started",
},
},
{
content: "Button",
matomo: {
eventCategory: "learn hub hero buttons",
eventAction: "click",
eventName: "lets get started",
},
},
]
return (
<ContentHeroComponent
breadcrumbSlug="/en/run-a-node/"
heroImgSrc={mockGatsbyImgData}
header={t("hero-header")}
description={t("hero-subtitle")}
buttons={buttons}
/>
)
},
}
59 changes: 59 additions & 0 deletions src/components/Hero/ContentHero/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as React from "react"
import { Box, Heading, HStack, SimpleGrid, Stack, Text } from "@chakra-ui/react"
import Breadcrumbs, { IProps as BreadcrumbsProps } from "../../Breadcrumbs"
import { GatsbyImage } from "../GatsbyImage"
import { CallToAction } from "../CallToAction"
import { CommonHeroProps } from "../utils"

export interface ContentHeroProps extends CommonHeroProps {
breadcrumbSlug: BreadcrumbsProps["slug"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the MdxHero api, I'd call this breadcrumb and accept any breadcrumb prop.

// and then just
<Breadcrumbs {...breadcrumbs} />

}

const ContentHero = (props: ContentHeroProps) => {
const { breadcrumbSlug, heroImgSrc, buttons, header, description } = props
return (
<Box bgImg="bgMainGradient">
<SimpleGrid columns={{ base: 1, lg: 2 }} maxW="1536px" mx="auto" gap="4">
<Box
height={{ base: "300px", md: "400px", lg: "full" }}
order={{ lg: 1 }}
>
<GatsbyImage
alt=""
image={heroImgSrc}
loading="eager"
objectFit="contain"
boxSize="full"
/>
</Box>
<Stack p={{ base: "8", lg: "16" }} spacing="9" justify="center">
{/* TODO:
* Recommend the Breadcrumbs component
* not have a spacing style (`mb`) and
* let the parent handle the spacing.
*
* This change would be done when the component is applied
* to prod.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd work this out in a separate PR, of course 😅

*/}
<Breadcrumbs slug={breadcrumbSlug} mb="0" />
<Stack spacing="6">
<Heading size="2xl">{header}</Heading>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be an h1 as there is no other heading in this hero.

<Text fontSize="lg">{description}</Text>
<HStack spacing="4">
{buttons
? buttons.map((button, idx) => (
<CallToAction key={idx} index={idx} {...button} />
))
: null}
</HStack>
</Stack>
{/* TODO:
* Add conditional Big Stat box here
*/}
</Stack>
</SimpleGrid>
</Box>
)
}

export default ContentHero
20 changes: 20 additions & 0 deletions src/components/Hero/GatsbyImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
GatsbyImage as Image,
type GatsbyImageProps,
} from "gatsby-plugin-image"
import { chakra, ChakraComponent } from "@chakra-ui/react"

/**
* The `GatsbyImage` component optimized for Chakra.
*
* @deprecated
* To be deprecated in favor of a global component version.
*/
export const GatsbyImage: ChakraComponent<"img", GatsbyImageProps> = chakra(
Image,
{
shouldForwardProp: (prop) => {
return ["image", "loading", "objectFit", "alt"].includes(prop)
},
}
)
50 changes: 50 additions & 0 deletions src/components/Hero/HomeHero/HomeHero.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as React from "react"
import { Meta, StoryObj } from "@storybook/react"
import HomeHeroComponent from "."
import { IGatsbyImageData } from "gatsby-plugin-image"

type HomeHeroType = typeof HomeHeroComponent

const meta = {
title: "Organisms / Layouts / Hero",
component: HomeHeroComponent,
parameters: {
layout: "none",
},
argTypes: {
heroImgSrc: {
table: {
disable: true,
},
},
},
} satisfies Meta<HomeHeroType>

export default meta

// Comes from the original compiled querying
const mockGatsbyImgData: IGatsbyImageData = {
layout: "fullWidth",
images: {
fallback: {
src: "/home/hero.png",
sizes: "100vw",
},
sources: [
{
srcSet: "/home/hero.png",
type: "image/webp",
sizes: "100vw",
},
],
},
width: 1,
height: 1,
}

export const HomeHero: StoryObj<typeof meta> = {
args: {
heroImgSrc: mockGatsbyImgData,
},
render: (args) => <HomeHeroComponent {...args} />,
}
49 changes: 49 additions & 0 deletions src/components/Hero/HomeHero/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from "react"
import { useTranslation } from "react-i18next"
import { Box, Heading, Stack, Text, VStack } from "@chakra-ui/react"
import ButtonLink from "../../ButtonLink"
import Morpher from "../../Morpher"
import Translation from "../../Translation"
import { GatsbyImage } from "../GatsbyImage"
import { CommonHeroProps } from "../utils"

interface HomeHeroProps extends Pick<CommonHeroProps, "heroImgSrc"> {}

const HomeHero = ({ heroImgSrc }: HomeHeroProps) => {
const { t } = useTranslation()
return (
<Box>
<GatsbyImage
image={heroImgSrc}
alt={t("page-index-hero-image-alt")}
loading="eager"
w="full"
height={{ base: "300px", sm: "350px", md: "380px", lg: "440px" }}
/>
<VStack>
<Stack
spacing={{ base: "4", lg: "7" }}
textAlign="center"
mx="4"
py="8"
maxW="2xl"
>
<Morpher />
<VStack spacing="6">
<Heading as="h1" size="2xl">
<Translation id="page-index-title" />
</Heading>
<Text size="xl">
<Translation id="page-index-description" />
</Text>
<ButtonLink to="/learn/">
<Translation id="page-index-title-button" />
</ButtonLink>
</VStack>
</Stack>
</VStack>
</Box>
)
}

export default HomeHero
Loading