darkMode: 'class'
doesn't appear to be honored by daisyUI
#640
-
I currently supply module.exports = {
content: ['./src/**/*.{html,js,svelte,ts}'],
plugins: [
require('@tailwindcss/typography'),
require('daisyui'),
],
daisyui: {
themes: [
{
light: {
...require('daisyui/src/colors/themes')['[data-theme=light]'],
primary: '#104060',
secondary: '#0a2440',
}
},
{
dark: {
...require('daisyui/src/colors/themes')['[data-theme=dark]'],
primary: '#104060',
secondary: '#0a2440',
}
},
],
},
} I was expecting I could apply the following (https://tailwindcss.com/docs/dark-mode#toggling-dark-mode-manually) and force daisyUI not to look at ...
darkMode: 'class',
daisyui: {
... However, it seems the Repro: https://play.tailwindcss.com/j0PXQiL4OD. I believe the light mode should be getting rendered with that Should daisyUI be respecting that |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 11 replies
-
This is a different approach. Tailwind's dark mode needs daisyUI is using another approach: Tailwind CSS If you don't want the daisyUI Or you can set the |
Beta Was this translation helpful? Give feedback.
-
Sorry to revive a closed discussion but I am unsure of how to implement a toggle-able dark mode button? Like I understand daisy-ui would apply themes based on media preference reported by the browser, but in the case where I have a client controlled toggle button, what then? The button wont sent the appropriate media preference... |
Beta Was this translation helpful? Give feedback.
-
I want to leave this here because I had a problem that required for me to use docs: https://tailwindcss.com/docs/dark-mode#customizing-the-class-name The module.exports = {
content: ['./src/**/*.{astro,html,svelte,vue,js,ts,jsx,tsx}'],
plugins: [require('daisyui')],
theme: { ... },
daisyui: {
themes: ['winter', 'night']
},
darkMode: ['class', '[data-theme="night"]']
} The most important thing here is using For the darkMode toggle component using the theme-change mentioned above you would have <label
class='btn btn-square btn-ghost swap swap-rotate'
data-toggle-theme='night'
data-act-class='swap-active'
>
...
</label> Look at the Then you use it like usual: <div class='dark:...'>
...
</div> and class after As @saadeghi said, for the simple theme toggling you don't need the |
Beta Was this translation helpful? Give feedback.
-
adding |
Beta Was this translation helpful? Give feedback.
-
Lets say i have 5 themes, 3 have a base of dark and 2 have a base of light. How can i have darkMode (dark/light) be applied to multiple themes? |
Beta Was this translation helpful? Give feedback.
-
@commandcenterio
You can add Example: https://play.tailwindcss.com/StVCXx6Hse?file=config |
Beta Was this translation helpful? Give feedback.
-
@saadeghi I understand that this may be a diff approach as per your response above - my qualm I suppose is that the option is supported but doesn't seem to be mentioned anywhere after I scoured the docs, so was a magical string when I stumbled upon this closed discussion!
Checked https://daisyui.com/docs/config/ and For the above quoted code. Cheers |
Beta Was this translation helpful? Give feedback.
-
@aleksa-codes Thank you so much for this. I don't understand what your problem with dark: is @saadeghi? As the creator of this plugin, you'd think that you would be supportive and helpful for such issues, instead you seem to be actively shutting down and dissing any use of If I wanted to use raw CSS, I wouldn't be using Tailwind would I? Not to mention, the countless components and plugins built in tailwind that get broken with DaisyUI without |
Beta Was this translation helpful? Give feedback.
This is a different approach.
Tailwind's dark mode needs
dark:
prefix and when your OS is using the dark mode (or you use class option and the add the dark class to HTML tag) all the class names withdark:
prefix gets activated.daisyUI is using another approach:
Your class names are the same. You don't need
dark:
prefix in all your elements and you don't need to set light / dark colors for all elements manually.You use one of these color names instead. This colors get their values from CSS variables.
This way we can have more than 2 themes or we can change a color in the entire app by change one variable value. This wouldn't be possible with the way Tailwind CSS darkmode config suggests.
…