Toggle Dark Mode #384
-
Morning, @calebporzio and team. Could you share the code you use on https://fluxui.dev for the Toggle Dark Mode function? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@jeffchown One way is to add this to your tailwind conf: After adding this, you can toggle a "dark" class on your html or body tag with Alpine. For local dev, you could just add / remove "dark" to your html/body tags to switch between themes. |
Beta Was this translation helpful? Give feedback.
@jeffchown One way is to add this to your tailwind conf:
module.exports = { darkMode: 'selector', ... }
See: https://fluxui.dev/docs/installation#using-dark-mode
After adding this, you can toggle a "dark" class on your html or body tag with Alpine.
At the FluxUI website they store a boolean with javascript in "darkMode" ("x-on:click="$store.darkMode.toggle()"). But you can do the same storing a session or cookie and retrieving this in your app layout file
For local dev, you could just add / remove "dark" to your html/body tags to switch between themes.