Skip to content

Commit 1a2319f

Browse files
refactor(Hero): redefine declaration of hero prop types
1 parent e168f0b commit 1a2319f

File tree

7 files changed

+54
-22
lines changed

7 files changed

+54
-22
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import ContentHeroComponent, { ContentHeroProps } from "."
55

66
type ContentHeroType = typeof ContentHeroComponent
77

8-
import contentHeroImg from "../../../../public/mainnet.png"
9-
108
const meta = {
119
title: "Organisms / Layouts / Hero",
1210
component: ContentHeroComponent,
@@ -51,7 +49,7 @@ export const ContentHero: StoryObj = {
5149
return (
5250
<ContentHeroComponent
5351
breadcrumbs={{ slug: "/en/run-a-node/" }}
54-
heroImg={contentHeroImg}
52+
heroImg="/mainnet.png"
5553
title={t("hero-header")}
5654
description={t("hero-subtitle")}
5755
buttons={buttons}

src/components/Hero/ContentHero/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
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) => {
1513
const { breadcrumbs, heroImg, buttons, title, description } = props

src/components/Hero/HomeHero/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { StaticImageData } from "next/image"
12
import { useTranslation } from "next-i18next"
23
import { Box, Heading, Stack, Text, VStack } from "@chakra-ui/react"
34

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

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

6-
import HubHeroComponent from "./"
6+
import HubHeroComponent, { type HubHeroProps } from "./"
77

88
type HubHeroType = typeof HubHeroComponent
99

@@ -24,8 +24,6 @@ const meta = {
2424

2525
export default meta
2626

27-
import { CommonHeroProps } from "@/lib/types"
28-
2927
import learnHubHeroImg from "../../../../public/heroes/learn-hub-hero.png"
3028

3129
export const HubHero: StoryObj<typeof meta> = {
@@ -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",

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">
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/lib/types.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
UseCasesFrontmatter,
1717
} from "@/lib/interfaces"
1818

19+
import type { BreadcrumbsProps } from "@/components/Breadcrumbs"
1920
import type { CallToActionProps } from "@/components/Hero/CallToAction"
2021
import { SimulatorNav } from "@/components/Simulator/interfaces"
2122

@@ -371,12 +372,48 @@ export type IRemarkTocOptions = {
371372
callback: (toc: TocNodeType) => void
372373
}
373374

374-
export type CommonHeroProps = {
375-
heroImg: StaticImageData
376-
header: string
375+
/**
376+
* General props to be picked or omitted for any of the hero components
377+
*
378+
* The generic prop type `HeroImg` is assigned to the `heroImg` prop
379+
* to be able to declare either defining the prop as a static image object
380+
* or a string. (defaults to `StaticImageData`)
381+
*/
382+
export type CommonHeroProps<
383+
HeroImg extends StaticImageData | string = StaticImageData
384+
> = {
385+
/**
386+
* Decorative image displayed as the full background or an aside to
387+
* the text content
388+
*
389+
* Note: It is either required as a static image data object or the
390+
* relative path of the image file, depending on the setup of the image component
391+
* for the given hero component.
392+
*/
393+
heroImg: HeroImg
394+
/**
395+
* Object of props to render the `Breadcrumbs` component.
396+
*/
397+
breadcrumbs: BreadcrumbsProps
398+
/**
399+
* An array of content to render call-to-action buttons that leads the user to a section or sections of the
400+
* given page from the hero.
401+
*
402+
* The hero can render no buttons or up to and no more than two.
403+
*/
404+
buttons?: [CallToActionProps, CallToActionProps?]
405+
/**
406+
* The primary title of the page
407+
*/
377408
title: string
409+
/**
410+
* A tag name for the page
411+
*/
412+
header: string
413+
/**
414+
* Preface text about the content in the given page
415+
*/
378416
description: string
379-
buttons?: [CallToActionProps, CallToActionProps?]
380417
}
381418

382419
// Learning Tools

0 commit comments

Comments
 (0)