I have styled my app for both dark and light mode, and the user can change the theme mode from UI. My code looks somethings like this
import React, { useState } from 'react';
const App = () => {
const [themeMode, setThemeMode] = useState('dark');
return (
<main className={` ${themeMode}`}>
{/* This works fine light and for dark mode */}
<p className="bg-white text-black dark:bg-black dark:text-white">
hello world</p>
{/* rest of my apps components */}
</main>
);
};
export default App;
This worked for me on every component i styled with tailwind css.
But it didnt worked for me when i tried to style my modals
P.S: The modals i used are from headlessui
import { useState } from 'react'
import { Dialog } from '@headlessui/react'
function MyDialog() {
let [isOpen, setIsOpen] = useState(true)
return (
<Dialog open={isOpen} onClose={() => setIsOpen(false)}>
<Dialog.Panel>
<Dialog.Title>Deactivate account</Dialog.Title>
<Dialog.Description>
This will permanently deactivate your account
</Dialog.Description>
{/* This dont work for dark mode */}
<p className="bg-white text-black dark:bg-black dark:text-white">
Are you sure you want to deactivate your account? All of your data
will be permanently removed. This action cannot be undone.
</p>
<button onClick={() => setIsOpen(false)}>Deactivate</button>
<button onClick={() => setIsOpen(false)}>Cancel</button>
</Dialog.Panel>
</Dialog>
)
}