Skip to content

Commit 455bae8

Browse files
PhilzenTobbe
andauthored
[Storybook] Improve typing, add doc links & remove redundant JSDoc in preview.tsx (#11745)
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
1 parent ec9da01 commit 455bae8

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

.changesets/11745.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- [Storybook] Improve typing, add doc links & remove redundant JSDoc in preview.tsx (#11745) by @Philzen
2+
3+
Better types for storybook preview config
4+
Better IntelliSense hints for storybook

packages/cli/src/commands/setup/i18n/templates/storybook.preview.tsx.template

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from 'react'
2-
import { I18nextProvider } from 'react-i18next'
2+
33
import type { GlobalTypes } from '@storybook/csf'
4-
import type { StoryFn, StoryContext } from '@storybook/react'
4+
import type { Preview, StoryContext, StoryFn } from '@storybook/react'
5+
import { I18nextProvider } from 'react-i18next'
56
import i18n from 'web/src/i18n'
67

7-
/** @type { import("@storybook/csf").GlobalTypes } */
8+
/** @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#global-types-and-the-toolbar-annotation | Global types and the toolbar annotation} */
89
export const globalTypes: GlobalTypes = {
910
locale: {
1011
name: 'Locale',
@@ -25,12 +26,12 @@ export const globalTypes: GlobalTypes = {
2526
* https://github.com/storybookjs/addon-kit/blob/main/src/withGlobals.ts
2627
* Unfortunately that will make eslint complain, so we have to disable it when
2728
* using a hook below
28-
* @param { import("@storybook/react").StoryFn} StoryFn
29-
* @param { import("@storybook/react").StoryContext} context
29+
*
30+
* @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#create-a-decorator | Create a decorator}
3031
*/
3132
const withI18n = (StoryFn: StoryFn, context: StoryContext) => {
3233
// eslint-disable-next-line react-hooks/rules-of-hooks
33-
React.useEffect(() => {
34+
useEffect(() => {
3435
i18n.changeLanguage(context.globals.locale)
3536
}, [context.globals.locale])
3637

@@ -41,4 +42,8 @@ const withI18n = (StoryFn: StoryFn, context: StoryContext) => {
4142
)
4243
}
4344

44-
export const decorators = [withI18n]
45+
const preview: Preview = {
46+
decorators: [withI18n]
47+
}
48+
49+
export default preview
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import * as React from 'react'
22

33
import { ChakraProvider, extendTheme } from '@chakra-ui/react'
4-
import type { StoryFn } from '@storybook/react'
4+
import type { Preview, StoryFn } from '@storybook/react'
55
import theme from 'config/chakra.config'
66

77
const extendedTheme = extendTheme(theme)
88

9-
/**
10-
* @param { import("@storybook/react").StoryFn} StoryFn
11-
*/
12-
const withChakra = (StoryFn: StoryFn) => {
13-
return (
14-
<ChakraProvider theme={extendedTheme}>
15-
<StoryFn />
16-
</ChakraProvider>
17-
)
9+
/** @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#create-a-decorator | Create a decorator} */
10+
const withChakra = (Story: StoryFn) => (
11+
<ChakraProvider theme={extendedTheme}>
12+
<Story />
13+
</ChakraProvider>
14+
)
15+
16+
const preview: Preview = {
17+
decorators: [withChakra]
1818
}
1919

20-
export const decorators = [withChakra]
20+
export default preview
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import * as React from 'react'
22

33
import { MantineProvider } from '@mantine/core'
4-
import type { StoryFn } from '@storybook/react'
4+
import type { Preview, StoryFn } from '@storybook/react'
55
import theme from 'config/mantine.config'
66

77
import '@mantine/core/styles.css'
88

9-
/**
10-
* @param { import("@storybook/react").StoryFn} StoryFn
11-
*/
12-
const withMantine = (StoryFn: StoryFn) => {
13-
return (
14-
<MantineProvider theme={theme}>
15-
<StoryFn />
16-
</MantineProvider>
17-
)
18-
}
9+
/** @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#create-a-decorator | Create a decorator} */
10+
const withMantine = (Story: StoryFn) => (
11+
<MantineProvider theme={theme}>
12+
<Story />
13+
</MantineProvider>
14+
)
1915

20-
export const decorators = [withMantine]
16+
const preview: Preview = {
17+
decorators: [withMantine]
18+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import * as React from 'react'
22

33
import type { GlobalTypes } from '@storybook/csf'
4-
import type { StoryFn, StoryContext } from '@storybook/react'
4+
import type { Preview, StoryContext, StoryFn } from '@storybook/react'
55

6-
/** @type { import("@storybook/csf").GlobalTypes } */
6+
/** @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#global-types-and-the-toolbar-annotation | Global types and the toolbar annotation} */
77
export const globalTypes: GlobalTypes = {}
88

99
/**
1010
* An example, no-op storybook decorator. Use a function like this to create decorators.
11-
* @param { import("@storybook/react").StoryFn} StoryFn
12-
* @param { import("@storybook/react").StoryContext} context
13-
*/
14-
const _exampleDecorator = (StoryFn: StoryFn, _context: StoryContext) => {
15-
return <StoryFn />
11+
* @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#create-a-decorator | Create a decorator}
12+
*/
13+
const _exampleDecorator = (StoryFn: StoryFn, _context: StoryContext) => (
14+
<StoryFn />
15+
)
16+
17+
const preview: Preview = {
18+
decorators: [],
1619
}
1720

18-
export const decorators = []
21+
export default preview

0 commit comments

Comments
 (0)