Skip to content

fix: enable Tailwind with storybook #15418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions site/.storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Storybook decorator function used to inject baseline data dependencies into
* our React components during testing.
*/
import "../src/index.css";
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
import CssBaseline from "@mui/material/CssBaseline";
import {
Expand Down Expand Up @@ -134,6 +135,12 @@ function withTheme(Story, context) {
const { themeOverride } = DecoratorHelpers.useThemeParameters();
const selected = themeOverride || selectedTheme || "dark";

// Ensure the correct theme is applied to Tailwind CSS classes by adding the
// theme to the HTML class list. This approach is necessary because Tailwind
// CSS relies on class names to apply styles, and dynamically changing themes
// requires updating the class list accordingly.
document.querySelector("html")?.setAttribute("class", selected);

return (
<StrictMode>
<StyledEngineProvider injectFirst>
Expand Down
2 changes: 1 addition & 1 deletion site/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
},
darkMode: ["selector"],
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
important: "#root",
important: ["#root", "#storybook-root"],
theme: {
fontSize: {
"2xs": ["0.626rem","0.875rem"],
Expand Down
Loading