Skip to content

Commit 6b04b0e

Browse files
authored
Merge pull request #12974 from TylerAPfledderer/refactor/update-existing-stories
refactor: sync existing stories with docs
2 parents bae037f + 0e82cce commit 6b04b0e

25 files changed

+185
-163
lines changed

.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
["^@/data"],
3131
// From the `constants` directory.
3232
["^@/lib/constants"],
33+
// From the `.storybook/utils` file
34+
["^@/storybook-utils"],
3335
// Parent imports. Put `..` last.
3436
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
3537
// Other relative imports. Put same-folder imports and `.` last.

.storybook/i18next.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const baseLocales = {
1010
}
1111

1212
// Only i18n files named in this array are being exposed to Storybook. Add filenames as necessary.
13-
const ns = [
13+
export const ns = [
1414
"common",
1515
"glossary",
1616
"learn-quizzes",
@@ -19,7 +19,7 @@ const ns = [
1919
"page-learn",
2020
"page-upgrades",
2121
"page-developers-index",
22-
]
22+
] as const
2323
const supportedLngs = Object.keys(baseLocales)
2424

2525
/**

.storybook/manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { addons } from "@storybook/manager-api"
22
import theme from "./theme"
3-
// @ts-ignore
43
import favicon from "../public/favicon.png"
54

65
addons.setConfig({

.storybook/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { getI18n } from "react-i18next"
2+
import { ns as exposedNs } from "./i18next"
3+
4+
/**
5+
* Get translations using the `getI18n` method.
6+
*
7+
* Only requires the key and optionally the namespace.
8+
*
9+
* Used for Stories where it is invalid to use the `useTranslation` hook in
10+
* the `render` function.
11+
*
12+
* The `ns` param is also typed with the namespaces that are exposed in
13+
* storybook.
14+
*
15+
* @param key - The key to translate.
16+
* @param ns - The exposed namespace.
17+
* @returns The translated string.
18+
*/
19+
export const getTranslation = (
20+
key: string,
21+
ns?: (typeof exposedNs)[number]
22+
) => {
23+
const { t } = getI18n()
24+
return t(key, { ns })
25+
}

src/components/Alert/Alert.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const STATUSES = ["error", "success", "warning", "info"] as const
2727
export const StatusVariants: Story = {
2828
args: {
2929
description: DEMO_DESC,
30+
// To show the close button
3031
onClose: () => {},
3132
},
3233
render: (args) => (
@@ -54,6 +55,7 @@ export const ContentVariants: Story = {
5455
export const StyleVariants: Story = {
5556
args: {
5657
description: DEMO_DESC,
58+
// To show the close button
5759
onClose: () => {},
5860
},
5961
argTypes: {

src/components/BaseStories/Accordion.stories.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
} from "@chakra-ui/react"
99
import { Meta, StoryObj } from "@storybook/react"
1010

11-
type AccordionType = typeof Accordion
12-
13-
const meta: Meta<AccordionType> = {
11+
const meta = {
1412
title: "Molecules / Disclosure Content / Accordions",
1513
component: Accordion,
1614
decorators: [
@@ -20,11 +18,11 @@ const meta: Meta<AccordionType> = {
2018
</Box>
2119
),
2220
],
23-
} satisfies Meta<AccordionType>
21+
} satisfies Meta<typeof Accordion>
2422

2523
export default meta
2624

27-
type Story = StoryObj<AccordionType>
25+
type Story = StoryObj<typeof meta>
2826

2927
export const Basic: Story = {
3028
render: () => (

src/components/BaseStories/Checkbox.stories.tsx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as React from "react"
22
import {
33
Checkbox as CheckboxComponent,
44
CheckboxGroup,
5+
type CheckboxProps,
56
VStack,
67
} from "@chakra-ui/react"
7-
import { Meta } from "@storybook/react"
8+
import { Meta, type StoryObj } from "@storybook/react"
89

910
const meta = {
1011
title: "Atoms / Form / Checkbox",
@@ -21,26 +22,46 @@ export default meta
2122

2223
const DEFAULT_VAL = "checked"
2324

24-
export const Checkbox = {
25+
const checkboxDataSet: CheckboxProps[] = [
26+
{
27+
value: DEFAULT_VAL,
28+
children: "defaultValue",
29+
},
30+
{
31+
value: "disabled",
32+
isDisabled: true,
33+
children: "isDisabled",
34+
},
35+
{
36+
value: "focusable",
37+
isFocusable: true,
38+
isDisabled: true,
39+
children: "isFocusable",
40+
},
41+
{
42+
value: "read-only",
43+
isReadOnly: true,
44+
children: "isReadOnly",
45+
},
46+
{
47+
value: "required",
48+
isRequired: true,
49+
children: "isRequired",
50+
},
51+
{
52+
value: "invalid",
53+
isInvalid: true,
54+
children: "isInvalid",
55+
},
56+
]
57+
58+
export const Checkbox: StoryObj = {
2559
render: () => (
2660
<CheckboxGroup defaultValue={[DEFAULT_VAL]}>
2761
<VStack spacing={4} align="flex-start">
28-
<CheckboxComponent value={DEFAULT_VAL}>defaultValue</CheckboxComponent>
29-
<CheckboxComponent value="disabled" isDisabled>
30-
isDisabled
31-
</CheckboxComponent>
32-
<CheckboxComponent value="focusable" isFocusable isDisabled>
33-
isFocusable
34-
</CheckboxComponent>
35-
<CheckboxComponent value="read-only" isReadOnly>
36-
isReadOnly
37-
</CheckboxComponent>
38-
<CheckboxComponent value="required" isRequired>
39-
isRequired
40-
</CheckboxComponent>
41-
<CheckboxComponent value="invalid" isInvalid>
42-
isInvalid
43-
</CheckboxComponent>
62+
{checkboxDataSet.map((props) => (
63+
<CheckboxComponent key={props.value} {...props} />
64+
))}
4465
</VStack>
4566
</CheckboxGroup>
4667
),

src/components/BaseStories/Link.stories.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@ export default meta
2020

2121
type Story = StoryObj<typeof meta>
2222

23-
const MockParagraph = ({ to }: { to?: string }) => (
23+
const MockParagraph = ({ href }: { href: string }) => (
2424
<Text>
2525
Text body normal. Ethereum is open access to digital money and data-friendly
2626
services for everyone &ndash; no matter your background or location.
27-
It&apos;s a <Link to={to}>community-built</Link> technology behind the
27+
It&apos;s a <Link href={href}>community-built</Link> technology behind the
2828
cryptocurrency ether (ETH) and thousands of applications you can use today.
2929
</Text>
3030
)
3131

3232
export const InternalLink: Story = {
3333
args: {
34-
to: "#",
34+
href: "#",
3535
},
36-
render: (args) => <MockParagraph {...args} />,
36+
render: (args) => <MockParagraph href={args.href!} />,
3737
}
3838

3939
export const ExternalLink: Story = {
4040
args: {
41-
to: "https://example.com",
41+
href: "https://example.com",
4242
},
43-
render: (args) => <MockParagraph {...args} />,
43+
render: (args) => <MockParagraph href={args.href!} />,
4444
}
4545

46-
export const LinkList = {
46+
export const LinkList: Story = {
4747
render: () => (
4848
<Stack spacing="6">
4949
<Text>
@@ -57,7 +57,7 @@ export const LinkList = {
5757
{Array.from({ length: 9 }).map((_, idx) => (
5858
<ListItem key={idx + 1}>
5959
<Link
60-
to={idx % 2 === 0 ? "https://example.com" : "#"}
60+
href={idx % 2 === 0 ? "https://example.com" : "#"}
6161
>{`List Item ${idx % 2 === 0 ? "External" : "Internal"} ${
6262
idx + 1
6363
}`}</Link>

src/components/BaseStories/Switch.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react"
22
import { SimpleGrid, Switch as SwitchComponent } from "@chakra-ui/react"
3-
import { Meta } from "@storybook/react"
3+
import { Meta, type StoryObj } from "@storybook/react"
44

55
const meta = {
66
title: "Atoms / Form / Switch",
@@ -15,7 +15,7 @@ const meta = {
1515

1616
export default meta
1717

18-
export const Switch = {
18+
export const Switch: StoryObj = {
1919
render: () => (
2020
<SimpleGrid columns={{ base: 2, lg: 4 }} columnGap={1} alignItems="center">
2121
<span>isChecked:</span>

src/components/BaseStories/Text.stories.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import * as React from "react"
2-
import {
3-
Box,
4-
Center,
5-
Flex,
6-
Link as ChakraLink,
7-
Stack,
8-
Text,
9-
VStack,
10-
} from "@chakra-ui/react"
2+
import { Box, Center, Flex, Stack, Text, VStack } from "@chakra-ui/react"
113
import { Meta, StoryObj } from "@storybook/react"
124

135
import components from "@/@chakra-ui/components"
146

7+
import LinkComponent from "../Link"
158
import Translation from "../Translation"
169

17-
type TextType = typeof Text
18-
1910
const meta = {
2011
title: "Atoms / Typography / Text",
2112
component: Text,
@@ -41,7 +32,7 @@ const meta = {
4132
</Center>
4233
),
4334
],
44-
} satisfies Meta<TextType>
35+
} satisfies Meta<typeof Text>
4536

4637
export default meta
4738

@@ -130,7 +121,7 @@ export const Italic: Story = {
130121
},
131122
}
132123

133-
export const Link: StoryObj<typeof ChakraLink> = {
124+
export const Link: StoryObj<typeof LinkComponent> = {
134125
args: {
135126
children: SINGLE_TEXT_CHILD,
136127
},
@@ -147,7 +138,7 @@ export const Link: StoryObj<typeof ChakraLink> = {
147138
<Text size={key} flex="1" textAlign="end">
148139
{key}
149140
</Text>
150-
<ChakraLink size={key} href="#" flex="9" {...args} />
141+
<LinkComponent size={key} href="#" flex="9" {...args} />
151142
</Flex>
152143
))}
153144
</Stack>

0 commit comments

Comments
 (0)