Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c590edb

Browse files
committed
chore: fix storybook fonts
Summary: Configures storybook with MUI themes as according to their documentation. We were previously not aligned with their example. See: https://storybook.js.org/addons/@react-theming/storybook-addon Details: - declare the themeing add-on in .storybook/main.js addons - configure a providerFn for MUI with CssBaseline. We were previously missing the CssBaseline implementation, causing the inconsistency. Impact: Resolves inconsistency between Storybook and production. I had tested the Tabpanel in production vs Storybook. In storybook, the font had fallen back to Times New Roman, whereas in production it had fallen back to Inter. This was because of CssBaseline being configured as a child of ThemeProvider. Resolves: #914
1 parent ce49966 commit c590edb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

site/.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
// addons are official and community plugins to extend Storybook.
1515
//
1616
// SEE: https://storybook.js.org/addons
17-
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
17+
addons: ["@storybook/addon-links", "@storybook/addon-essentials", "@react-theming/storybook-addon"],
1818

1919
// Storybook uses babel under the hood, while we currently use ts-loader.
2020
// Sometimes, you may encounter an error in a Storybook that contains syntax

site/.storybook/preview.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CssBaseline } from "@material-ui/core"
2+
import { createMuiTheme } from "@material-ui/core/styles"
13
import ThemeProvider from "@material-ui/styles/ThemeProvider"
24
import { withThemes } from "@react-theming/storybook-addon"
35
import { createMemoryHistory } from "history"
@@ -6,7 +8,17 @@ import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom"
68
import { dark, light } from "../src/theme"
79
import "../src/theme/global-fonts"
810

9-
addDecorator(withThemes(ThemeProvider, [light, dark]))
11+
const providerFn = ({ theme, children }) => {
12+
const muiTheme = createMuiTheme(theme)
13+
return (
14+
<ThemeProvider theme={muiTheme}>
15+
<CssBaseline />
16+
{children}
17+
</ThemeProvider>
18+
)
19+
}
20+
21+
addDecorator(withThemes(null, [light, dark], { providerFn }))
1022

1123
const history = createMemoryHistory()
1224

0 commit comments

Comments
 (0)