How do I make the canvas background color change, when a theme is selected? #25183
Replies: 4 comments 10 replies
-
Thanks for taking the time to reach out to us with your question. We appreciate it 🙏 ! So that you're aware, the styling addon you referred to is officially [deprecated}(https://storybook.js.org/addons/@storybook/addon-styling), and we're encouraging users to use one of the alternatives provided in the disclaimer (ie., Looking forward to hearing from you. Hope you have a great day. Stay safe |
Beta Was this translation helpful? Give feedback.
-
Using Tailwind with add on-theme, my preference is to use |
Beta Was this translation helpful? Give feedback.
-
There is actually a quite easy way to do this, with themes addon alone: export const decorators = [
withThemeByClassName({
themes: {
light: "light",
dark: "dark bg-neutral-900",
},
defaultTheme: "light",
}),
] Just add Tailwind background class as part of your themes css classes list. Be mindful that in Might be worth also disabling backgrounds in your preview config: const preview: Preview = {
parameters: {
backgrounds: { disable: true },
}
} as they will be conflicting with your theme classes. |
Beta Was this translation helpful? Give feedback.
-
For those in tailwindcss land I got it working with this from inspiration from everyone else! parameters: {
backgrounds: {
options: {
"light/dark": {
name: "light/dark",
value: "var(--light-dark)",
},
white: { name: "white", value: "#ffffff" },
"gray-50": { name: "gray-50", value: "#f7f7f7" },
"gray-950": { name: "gray-950", value: "#292929" },
},
},
},
initialGlobals: {
backgrounds: {
value: "light/dark",
},
},
decorators: [
withThemeByClassName({
themes: {
light: "light [--light-dark:#ffffff]", // gray-50
dark: "dark [--light-dark:#292929]", // gray-950
},
defaultTheme: "light",
}), As someone else mentioned- make sure your tailwind config is looking at this file! |
Beta Was this translation helpful? Give feedback.
-
Summary
I'm using Sveltekit and Tailwind, and followed the guide here to add the "theme" selector:
My question is, how can I make the background color of the canvas change to a dark tailwind class, when dark-mode is selected? Thanks 🙏
Additional information
No response
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions