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" ;
@@ -31,15 +13,12 @@ import { HelmetProvider } from "react-helmet-async";
31
13
import { QueryClient , QueryClientProvider } from "react-query" ;
32
14
import { withRouter } from "storybook-addon-remix-react-router" ;
33
15
import "theme/globalFonts" ;
16
+ import type { Decorator , Loader , Parameters } from "@storybook/react-vite" ;
34
17
import themes from "../src/theme" ;
35
18
36
19
DecoratorHelpers . initializeThemeState ( Object . keys ( themes ) , "dark" ) ;
37
20
38
- /** @type {readonly Decorator[] } */
39
- export const decorators = [ withRouter , withQuery , withHelmet , withTheme ] ;
40
-
41
- /** @type {Preview["parameters"] } */
42
- export const parameters = {
21
+ export const parameters : Parameters = {
43
22
options : {
44
23
storySort : {
45
24
method : "alphabetical" ,
@@ -83,33 +62,15 @@ export const parameters = {
83
62
} ,
84
63
} ;
85
64
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 ) {
65
+ const withHelmet : Decorator = ( Story ) => {
97
66
return (
98
- < SafeHelmetProvider >
67
+ < HelmetProvider >
99
68
< Story />
100
- </ SafeHelmetProvider >
69
+ </ HelmetProvider >
101
70
) ;
102
- }
103
-
104
- /**
105
- * This JSX file isn't part of the main project, so it doesn't get to use the
106
- * ambient types defined in `storybook.d.ts` to provide extra type-safety.
107
- * Extracting main key to avoid typos.
108
- */
109
- const queryParametersKey = "queries" ;
71
+ } ;
110
72
111
- /** @type {Decorator } */
112
- function withQuery ( Story , { parameters } ) {
73
+ const withQuery : Decorator = ( Story , { parameters } ) => {
113
74
const queryClient = new QueryClient ( {
114
75
defaultOptions : {
115
76
queries : {
@@ -119,8 +80,8 @@ function withQuery(Story, { parameters }) {
119
80
} ,
120
81
} ) ;
121
82
122
- if ( parameters [ queryParametersKey ] ) {
123
- for ( const query of parameters [ queryParametersKey ] ) {
83
+ if ( parameters . queries ) {
84
+ for ( const query of parameters . queries ) {
124
85
queryClient . setQueryData ( query . key , query . data ) ;
125
86
}
126
87
}
@@ -130,10 +91,9 @@ function withQuery(Story, { parameters }) {
130
91
< Story />
131
92
</ QueryClientProvider >
132
93
) ;
133
- }
94
+ } ;
134
95
135
- /** @type {Decorator } */
136
- function withTheme ( Story , context ) {
96
+ const withTheme : Decorator = ( Story , context ) => {
137
97
const selectedTheme = DecoratorHelpers . pluckThemeFromContext ( context ) ;
138
98
const { themeOverride } = DecoratorHelpers . useThemeParameters ( ) ;
139
99
const selected = themeOverride || selectedTheme || "dark" ;
@@ -156,12 +116,20 @@ function withTheme(Story, context) {
156
116
</ StyledEngineProvider >
157
117
</ StrictMode >
158
118
) ;
159
- }
119
+ } ;
120
+
121
+ export const decorators : Decorator [ ] = [
122
+ withRouter ,
123
+ withQuery ,
124
+ withHelmet ,
125
+ withTheme ,
126
+ ] ;
160
127
161
128
// Try to fix storybook rendering fonts inconsistently
162
129
// https://www.chromatic.com/docs/font-loading/#solution-c-check-fonts-have-loaded-in-a-loader
163
130
const fontLoader = async ( ) => ( {
164
131
fonts : await document . fonts . ready ,
165
132
} ) ;
166
133
167
- export const loaders = isChromatic ( ) && document . fonts ? [ fontLoader ] : [ ] ;
134
+ export const loaders : Loader [ ] =
135
+ isChromatic ( ) && document . fonts ? [ fontLoader ] : [ ] ;
0 commit comments