1
- // @ts -check
2
- /**
3
- * @file Defines the main configuration file for all of our Storybook tests.
4
- * This file must be a JSX/JS file, but we can at least add some type safety via
5
- * the ts-check directive.
6
- * @see {@link https://storybook.js.org/docs/configure#configure-story-rendering }
7
- *
8
- * @typedef {import("react").ReactElement } ReactElement
9
- * @typedef {import("react").PropsWithChildren } PropsWithChildren
10
- * @typedef {import("react").FC<PropsWithChildren> } FC
11
- *
12
- * @typedef {import("@storybook/react-vite").StoryContext } StoryContext
13
- * @typedef {import("@storybook/react-vite").Preview } Preview
14
- *
15
- * @typedef {(Story: FC, Context: StoryContext) => React.JSX.Element } Decorator A
16
- * Storybook decorator function used to inject baseline data dependencies into
17
- * our React components during testing.
18
- */
19
1
import "../src/index.css" ;
20
2
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react" ;
21
3
import CssBaseline from "@mui/material/CssBaseline" ;
22
4
import {
23
5
ThemeProvider as MuiThemeProvider ,
24
6
StyledEngineProvider ,
25
- // biome-ignore lint/nursery/noRestrictedImports: we extend the MUI theme
26
7
} from "@mui/material/styles" ;
27
8
import { DecoratorHelpers } from "@storybook/addon-themes" ;
28
9
import isChromatic from "chromatic/isChromatic" ;
@@ -32,14 +13,11 @@ import { QueryClient, QueryClientProvider } from "react-query";
32
13
import { withRouter } from "storybook-addon-remix-react-router" ;
33
14
import "theme/globalFonts" ;
34
15
import themes from "../src/theme" ;
16
+ import type { Decorator , Loader , Parameters } from "@storybook/react-vite" ;
35
17
36
18
DecoratorHelpers . initializeThemeState ( Object . keys ( themes ) , "dark" ) ;
37
19
38
- /** @type {readonly Decorator[] } */
39
- export const decorators = [ withRouter , withQuery , withHelmet , withTheme ] ;
40
-
41
- /** @type {Preview["parameters"] } */
42
- export const parameters = {
20
+ export const parameters : Parameters = {
43
21
options : {
44
22
storySort : {
45
23
method : "alphabetical" ,
@@ -83,26 +61,15 @@ export const parameters = {
83
61
} ,
84
62
} ;
85
63
86
- /**
87
- * There's a mismatch on the React Helmet return type that causes issues when
88
- * mounting the component in JS files only. Have to do type assertion, which is
89
- * especially ugly in JSDoc
90
- */
91
- const SafeHelmetProvider = /** @type {FC } */ (
92
- /** @type {unknown } */ ( HelmetProvider )
93
- ) ;
94
-
95
- /** @type {Decorator } */
96
- function withHelmet ( Story ) {
64
+ const withHelmet : Decorator = ( Story ) => {
97
65
return (
98
- < SafeHelmetProvider >
66
+ < HelmetProvider >
99
67
< Story />
100
- </ SafeHelmetProvider >
68
+ </ HelmetProvider >
101
69
) ;
102
- }
70
+ } ;
103
71
104
- /** @type {Decorator } */
105
- function withQuery ( Story , { parameters } ) {
72
+ const withQuery : Decorator = ( Story , { parameters } ) => {
106
73
const queryClient = new QueryClient ( {
107
74
defaultOptions : {
108
75
queries : {
@@ -123,10 +90,9 @@ function withQuery(Story, { parameters }) {
123
90
< Story />
124
91
</ QueryClientProvider >
125
92
) ;
126
- }
93
+ } ;
127
94
128
- /** @type {Decorator } */
129
- function withTheme ( Story , context ) {
95
+ const withTheme : Decorator = ( Story , context ) => {
130
96
const selectedTheme = DecoratorHelpers . pluckThemeFromContext ( context ) ;
131
97
const { themeOverride } = DecoratorHelpers . useThemeParameters ( ) ;
132
98
const selected = themeOverride || selectedTheme || "dark" ;
@@ -149,12 +115,20 @@ function withTheme(Story, context) {
149
115
</ StyledEngineProvider >
150
116
</ StrictMode >
151
117
) ;
152
- }
118
+ } ;
119
+
120
+ export const decorators : Decorator [ ] = [
121
+ withRouter ,
122
+ withQuery ,
123
+ withHelmet ,
124
+ withTheme ,
125
+ ] ;
153
126
154
127
// Try to fix storybook rendering fonts inconsistently
155
128
// https://www.chromatic.com/docs/font-loading/#solution-c-check-fonts-have-loaded-in-a-loader
156
129
const fontLoader = async ( ) => ( {
157
130
fonts : await document . fonts . ready ,
158
131
} ) ;
159
132
160
- export const loaders = isChromatic ( ) && document . fonts ? [ fontLoader ] : [ ] ;
133
+ export const loaders : Loader [ ] =
134
+ isChromatic ( ) && document . fonts ? [ fontLoader ] : [ ] ;
0 commit comments