Skip to content

Commit bae037f

Browse files
authored
Merge pull request #12668 from TylerAPfledderer/feat/chromatic-story-modes
feat(storybook): build story modes
2 parents 7bce095 + 3429349 commit bae037f

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

.storybook/modes.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { baseLocales } from "./i18next"
2+
import { chakraBreakpointArray } from "./preview"
3+
4+
export const viewportModes = chakraBreakpointArray.reduce<{
5+
[mode: string]: { viewport: string }
6+
}>((arr, [token]) => {
7+
return {
8+
...arr,
9+
[token]: {
10+
viewport: token,
11+
},
12+
}
13+
}, {})
14+
15+
export const langModes = Object.keys(baseLocales).reduce<{
16+
[locale: string]: { locale: string }
17+
}>((arr, curr) => {
18+
return {
19+
...arr,
20+
[curr]: {
21+
locale: curr,
22+
},
23+
}
24+
}, {})
25+
26+
type LangViewModeObj = {
27+
[key: string]: { viewport: string; locale: string }
28+
}
29+
30+
export const langViewportModes = Object.entries(
31+
viewportModes
32+
).reduce<LangViewModeObj>((arr, curr) => {
33+
const [viewKey, viewVal] = curr
34+
35+
const currLangViewObj = {} as LangViewModeObj
36+
37+
Object.entries(langModes).forEach(([langKey, langVal]) => {
38+
currLangViewObj[`${langKey}-${viewKey}`] = {
39+
viewport: viewVal.viewport,
40+
locale: langVal.locale,
41+
}
42+
})
43+
44+
return {
45+
...arr,
46+
...currLangViewObj,
47+
}
48+
}, {})

.storybook/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { MotionGlobalConfig } from "framer-motion"
1111

1212
MotionGlobalConfig.skipAnimations = isChromatic()
1313

14-
const chakraBreakpointArray = Object.entries(theme.breakpoints) as [
14+
export const chakraBreakpointArray = Object.entries(theme.breakpoints) as [
1515
string,
1616
string
1717
][]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useTranslation } from "next-i18next"
22
import { Meta, StoryObj } from "@storybook/react"
33

4+
import { langViewportModes } from "../../../../.storybook/modes"
5+
46
import ContentHeroComponent, { ContentHeroProps } from "."
57

68
type ContentHeroType = typeof ContentHeroComponent
@@ -10,6 +12,11 @@ const meta = {
1012
component: ContentHeroComponent,
1113
parameters: {
1214
layout: "none",
15+
chromatic: {
16+
modes: {
17+
...langViewportModes,
18+
},
19+
},
1320
},
1421
argTypes: {
1522
heroImg: {

src/components/Hero/HomeHero/HomeHero.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from "react"
22
import { Meta, StoryObj } from "@storybook/react"
33

4+
import { langViewportModes } from "../../../../.storybook/modes"
5+
46
import HomeHeroComponent from "."
57

68
type HomeHeroType = typeof HomeHeroComponent
@@ -10,6 +12,11 @@ const meta = {
1012
component: HomeHeroComponent,
1113
parameters: {
1214
layout: "none",
15+
chromatic: {
16+
modes: {
17+
...langViewportModes,
18+
},
19+
},
1320
},
1421
argTypes: {
1522
heroImg: {

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

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

6+
import { langViewportModes } from "../../../../.storybook/modes"
7+
68
import HubHeroComponent, { type HubHeroProps } from "./"
79

810
import learnHubHeroImg from "@/public/heroes/learn-hub-hero.png"
@@ -14,6 +16,11 @@ const meta = {
1416
component: HubHeroComponent,
1517
parameters: {
1618
layout: "none",
19+
chromatic: {
20+
modes: {
21+
...langViewportModes,
22+
},
23+
},
1724
},
1825
decorators: [
1926
(Story) => (

src/components/Hero/MdxHero/MdxHero.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { HStack } from "@chakra-ui/react"
22
import { Meta, StoryObj } from "@storybook/react"
33

4+
import { langViewportModes } from "../../../../.storybook/modes"
5+
46
import MdxHeroComponent from "./"
57

68
type MdxHeroType = typeof MdxHeroComponent
@@ -9,6 +11,11 @@ const meta = {
911
title: "Organisms / Layouts / Hero",
1012
parameters: {
1113
layout: "none",
14+
chromatic: {
15+
modes: {
16+
...langViewportModes,
17+
},
18+
},
1219
},
1320
decorators: [
1421
(Story) => (

0 commit comments

Comments
 (0)