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>
This commit is contained in:
Jaayden Halko
2024-11-07 20:56:42 -05:00
committed by GitHub
co-authored by Spike Curtis BrunoQuaresma
parent cb9991a9bf
commit de2f42eedd
2 changed files with 8 additions and 1 deletions
+7
View File
@@ -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 {
@@ -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>
+1 -1
View File
@@ -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"],