Skip to content

Commit de2f42e

Browse files
jaaydenhspikecurtisBrunoQuaresma
authored
fix: enable Tailwind with storybook (#15418)
This adds index.css to the storybook preview file and references to #storybook-root element in the tailwind config --------- Co-authored-by: Spike Curtis <spike@coder.com> Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
1 parent cb9991a commit de2f42e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

site/.storybook/preview.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Storybook decorator function used to inject baseline data dependencies into
1717
* our React components during testing.
1818
*/
19+
import "../src/index.css";
1920
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
2021
import CssBaseline from "@mui/material/CssBaseline";
2122
import {
@@ -134,6 +135,12 @@ function withTheme(Story, context) {
134135
const { themeOverride } = DecoratorHelpers.useThemeParameters();
135136
const selected = themeOverride || selectedTheme || "dark";
136137

138+
// Ensure the correct theme is applied to Tailwind CSS classes by adding the
139+
// theme to the HTML class list. This approach is necessary because Tailwind
140+
// CSS relies on class names to apply styles, and dynamically changing themes
141+
// requires updating the class list accordingly.
142+
document.querySelector("html")?.setAttribute("class", selected);
143+
137144
return (
138145
<StrictMode>
139146
<StyledEngineProvider injectFirst>

site/tailwind.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
},
66
darkMode: ["selector"],
77
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
8-
important: "#root",
8+
important: ["#root", "#storybook-root"],
99
theme: {
1010
fontSize: {
1111
"2xs": ["0.626rem","0.875rem"],

0 commit comments

Comments
 (0)