Skip to content

Commit 8db5636

Browse files
authored
Merge pull request #13567 from Baystef/feat/bannergridcomponents-story
Create story tests for BannerGrid components [#13046]
2 parents 0868763 + 91c209d commit 8db5636

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import { MdInfoOutline } from "react-icons/md"
2+
import { Meta, StoryObj } from "@storybook/react"
3+
4+
import { ChildOnlyProp } from "@/lib/types"
5+
6+
import { TwImage } from "@/components/Image"
7+
import InlineLink from "@/components/Link"
8+
import Tooltip from "@/components/Tooltip"
9+
10+
import { getTranslation } from "@/storybook-utils"
11+
12+
import { langViewportModes } from "../../../.storybook/modes"
13+
import { ContentContainer } from "../MdComponents"
14+
15+
import {
16+
Banner as BannerComponent,
17+
BannerBody as BannerBodyComponent,
18+
BannerGrid as BannerGridComponent,
19+
BannerGridCell as BannerGridCellComponent,
20+
BannerImage as BannerImageComponent,
21+
} from "."
22+
23+
import stats from "@/public/images/upgrades/newrings.png"
24+
25+
const meta = {
26+
title: "Molecules / Display Content / Banner Grid",
27+
component: BannerComponent,
28+
parameters: {
29+
layout: "fullscreen",
30+
chromatic: {
31+
modes: {
32+
...langViewportModes,
33+
},
34+
},
35+
},
36+
decorators: [
37+
(Story) => (
38+
<div className="relative w-full">
39+
<ContentContainer>
40+
<Story />
41+
</ContentContainer>
42+
</div>
43+
),
44+
],
45+
} satisfies Meta<typeof BannerComponent>
46+
47+
export default meta
48+
49+
type Story = StoryObj<typeof meta>
50+
51+
const PAGE_WHAT_IS_ETH = "page-what-is-ethereum"
52+
53+
const tooltipContent = ({ apiUrl, apiProvider, ariaLabel }) => (
54+
<div>
55+
{getTranslation("data-provided-by", "common")}{" "}
56+
<InlineLink href={apiUrl} aria-label={ariaLabel}>
57+
{apiProvider}
58+
</InlineLink>
59+
</div>
60+
)
61+
62+
const StatPrimary = (props: ChildOnlyProp) => (
63+
<div className="mb-4 text-5xl leading-none" {...props} />
64+
)
65+
66+
const StatDescription = (props: ChildOnlyProp) => (
67+
<div className="text-md text-[#666] dark:text-[#b2b2b2]" {...props} />
68+
)
69+
70+
export const Banner: Story = {
71+
render: () => {
72+
return (
73+
<BannerComponent>
74+
<div className="text-md text-[#666] dark:text-[#b2b2b2]">Banner</div>
75+
</BannerComponent>
76+
)
77+
},
78+
}
79+
80+
export const BannerBody: Story = {
81+
render: () => {
82+
return (
83+
<BannerComponent>
84+
<BannerBodyComponent>
85+
<div className="text-md text-[#666] dark:text-[#b2b2b2]">
86+
Banner Body
87+
</div>
88+
</BannerBodyComponent>
89+
</BannerComponent>
90+
)
91+
},
92+
}
93+
94+
export const BannerImage: Story = {
95+
render: () => {
96+
return (
97+
<BannerComponent>
98+
<BannerImageComponent>
99+
<TwImage src={stats} alt="" width={400} />
100+
</BannerImageComponent>
101+
</BannerComponent>
102+
)
103+
},
104+
}
105+
106+
export const BannerGridCell: Story = {
107+
render: () => {
108+
return (
109+
<BannerComponent>
110+
<BannerBodyComponent>
111+
<BannerGridCellComponent>
112+
<StatPrimary>4k+</StatPrimary>
113+
<StatDescription>
114+
{getTranslation(
115+
"page-what-is-ethereum-ethereum-in-numbers-stat-1-desc",
116+
PAGE_WHAT_IS_ETH
117+
)}
118+
<span className="whitespace-nowrap">
119+
&nbsp;
120+
<Tooltip
121+
content={tooltipContent({
122+
apiUrl: "https://dappradar.com/rankings/protocol/ethereum",
123+
apiProvider: "State of the dapps",
124+
ariaLabel: "Read more about Ethereum projects stats",
125+
})}
126+
>
127+
<span>
128+
<MdInfoOutline className="inline-block align-middle" />
129+
</span>
130+
</Tooltip>
131+
</span>
132+
</StatDescription>
133+
</BannerGridCellComponent>
134+
</BannerBodyComponent>
135+
</BannerComponent>
136+
)
137+
},
138+
}
139+
140+
export const BannerGrid: Story = {
141+
render: () => {
142+
return (
143+
<BannerComponent>
144+
<BannerBodyComponent>
145+
<BannerGridComponent>
146+
{Array.from({ length: 6 }, (_, i) => i + 1).map((item) => (
147+
<BannerGridCellComponent key={item}>
148+
<StatPrimary>{item}k+</StatPrimary>
149+
<StatDescription>
150+
{getTranslation(
151+
"page-what-is-ethereum-ethereum-in-numbers-stat-1-desc",
152+
PAGE_WHAT_IS_ETH
153+
)}
154+
<span className="whitespace-nowrap">
155+
&nbsp;
156+
<Tooltip
157+
content={tooltipContent({
158+
apiUrl:
159+
"https://dappradar.com/rankings/protocol/ethereum",
160+
apiProvider: "State of the dapps",
161+
ariaLabel: "Read more about Ethereum projects stats",
162+
})}
163+
>
164+
<span>
165+
<MdInfoOutline className="inline-block align-middle" />
166+
</span>
167+
</Tooltip>
168+
</span>
169+
</StatDescription>
170+
</BannerGridCellComponent>
171+
))}
172+
</BannerGridComponent>
173+
</BannerBodyComponent>
174+
<BannerImageComponent>
175+
<TwImage src={stats} alt="" width={400} />
176+
</BannerImageComponent>
177+
</BannerComponent>
178+
)
179+
},
180+
}

0 commit comments

Comments
 (0)