Install the following npm module:
npm i --save-dev storybook-tailwind-dark-theme-toggle
or with yarn:
yarn add -D storybook-tailwind-dark-theme-toggle
Then, add following content to .storybook/main.js
module.exports = {
addons: ['storybook-tailwind-dark-theme-toggle'],
};
module.exports = {
darkMode: 'class',
// ...
}
To set dark mode as default, Add the following lines of code to your preview.js file
const preview = {
globalTypes: {
darkMode: {
defaultValue: true, // Enable dark mode by default on all stories
},
// Optional (Default: 'dark')
className: {
defaultValue: 'custom-classname', // Set your custom dark mode class name
},
// Optional
selector: {
defaultValue: "html"
}
},
};