Skip to content

Commit 052962d

Browse files
committed
chore: update storybook config to use TS
1 parent 2180d17 commit 052962d

File tree

2 files changed

+27
-56
lines changed

2 files changed

+27
-56
lines changed
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import turbosnap from "vite-plugin-turbosnap";
1+
import type { StorybookConfig } from "@storybook/react-vite";
22

3-
module.exports = {
3+
const config: StorybookConfig = {
44
stories: ["../src/**/*.stories.tsx"],
55

66
addons: [
@@ -18,16 +18,13 @@ module.exports = {
1818
options: {},
1919
},
2020

21-
async viteFinal(config, { configType }) {
22-
config.plugins = config.plugins || [];
23-
if (configType === "PRODUCTION") {
24-
config.plugins.push(
25-
turbosnap({
26-
rootDir: config.root || "",
27-
}),
28-
);
21+
async viteFinal(config) {
22+
if (config.server) {
23+
config.server.allowedHosts = [".coder"];
2924
}
30-
config.server.allowedHosts = [".coder"];
25+
3126
return config;
3227
},
3328
};
29+
30+
export default config;

site/.storybook/preview.jsx renamed to site/.storybook/preview.tsx

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
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-
*/
191
import "../src/index.css";
202
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
213
import CssBaseline from "@mui/material/CssBaseline";
224
import {
235
ThemeProvider as MuiThemeProvider,
246
StyledEngineProvider,
25-
// biome-ignore lint/nursery/noRestrictedImports: we extend the MUI theme
267
} from "@mui/material/styles";
278
import { DecoratorHelpers } from "@storybook/addon-themes";
289
import isChromatic from "chromatic/isChromatic";
@@ -32,14 +13,11 @@ import { QueryClient, QueryClientProvider } from "react-query";
3213
import { withRouter } from "storybook-addon-remix-react-router";
3314
import "theme/globalFonts";
3415
import themes from "../src/theme";
16+
import type { Decorator, Loader, Parameters } from "@storybook/react-vite";
3517

3618
DecoratorHelpers.initializeThemeState(Object.keys(themes), "dark");
3719

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 = {
4321
options: {
4422
storySort: {
4523
method: "alphabetical",
@@ -83,26 +61,15 @@ export const parameters = {
8361
},
8462
};
8563

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) => {
9765
return (
98-
<SafeHelmetProvider>
66+
<HelmetProvider>
9967
<Story />
100-
</SafeHelmetProvider>
68+
</HelmetProvider>
10169
);
102-
}
70+
};
10371

104-
/** @type {Decorator} */
105-
function withQuery(Story, { parameters }) {
72+
const withQuery: Decorator = (Story, { parameters }) => {
10673
const queryClient = new QueryClient({
10774
defaultOptions: {
10875
queries: {
@@ -123,10 +90,9 @@ function withQuery(Story, { parameters }) {
12390
<Story />
12491
</QueryClientProvider>
12592
);
126-
}
93+
};
12794

128-
/** @type {Decorator} */
129-
function withTheme(Story, context) {
95+
const withTheme: Decorator = (Story, context) => {
13096
const selectedTheme = DecoratorHelpers.pluckThemeFromContext(context);
13197
const { themeOverride } = DecoratorHelpers.useThemeParameters();
13298
const selected = themeOverride || selectedTheme || "dark";
@@ -149,12 +115,20 @@ function withTheme(Story, context) {
149115
</StyledEngineProvider>
150116
</StrictMode>
151117
);
152-
}
118+
};
119+
120+
export const decorators: Decorator[] = [
121+
withRouter,
122+
withQuery,
123+
withHelmet,
124+
withTheme,
125+
];
153126

154127
// Try to fix storybook rendering fonts inconsistently
155128
// https://www.chromatic.com/docs/font-loading/#solution-c-check-fonts-have-loaded-in-a-loader
156129
const fontLoader = async () => ({
157130
fonts: await document.fonts.ready,
158131
});
159132

160-
export const loaders = isChromatic() && document.fonts ? [fontLoader] : [];
133+
export const loaders: Loader[] =
134+
isChromatic() && document.fonts ? [fontLoader] : [];

0 commit comments

Comments
 (0)