Skip to content

Add dark mode support #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,42 @@ import { UserTypeSelector } from './components/UserTypeSelecctor';
import { UserTypeSelectorLogin } from './components/UserTypeSelecctorLogin';
import AddProducts from './components/AddProducts';


function App() {
const dispatch =useDispatch()
const dispatch = useDispatch();
const [darkMode, setDarkMode] = useState(false);

useEffect(() => {
dispatch(setUser(JSON.parse(localStorage.getItem('user'))));
}, []);

useEffect(()=>{
const toggleDarkMode = () => {
setDarkMode(!darkMode);
};

dispatch(setUser(JSON.parse(localStorage.getItem('user'))))

},[])
return (

<BrowserRouter basename='E-commerce-page'>
<div className="mx-auto">
<Header />
<Routes >
<Route path="/" element={<Home />} />

<Route path="/Login" element={<UserTypeSelectorLogin />} />
<Route path="/SignUp" element={<UserTypeSelector />} />
<Route path="/Profile" element={<Profile />} />
<Route path="/Products" element={<Products/>} >
<Route path="/Products/AllProducts" element={<AllProducts/>} />
<BrowserRouter basename='E-commerce-page'>
<div className={`mx-auto ${darkMode ? 'dark' : ''}`}>
<Header />
<button onClick={toggleDarkMode} className="fixed top-[74px] right-2 p-2 bg-gray-800 text-white rounded ">
Dark Mode
</button>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/Login" element={<UserTypeSelectorLogin />} />
<Route path="/SignUp" element={<UserTypeSelector />} />
<Route path="/Profile" element={<Profile />} />
<Route path="/Products" element={<Products />}>
<Route path="/Products/AllProducts" element={<AllProducts />} />
<Route path="/Products/Men" element={<Men />} />
<Route path="/Products/Women" element={<Women />} />
<Route path="/Products/Jewelery" element={<Jewelery />} />
<Route path="/Products/Electronics" element={<Electronics />} />
</Route>
<Route path="/cart" element={<Cart />} />
<Route path="/AddProducts" element={<AddProducts />} />

</Routes>
</div>
</BrowserRouter>

</Route>
<Route path="/cart" element={<Cart />} />
<Route path="/AddProducts" element={<AddProducts />} />
</Routes>
</div>
</BrowserRouter>
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Footer() {
const today = new Date();
return (
<footer>
<div id="section5" className="flex justify-around text-center flex-wrap gap-[20px] bg-[#dfdddd] items-center p-[50px] font-medium pt-[100px]">
<div id="section5" className="flex justify-around text-center flex-wrap gap-[20px] bg-[#dfdddd] dark:bg-gray-800 items-center p-[50px] font-medium pt-[100px]">
<div className="flex flex-col">
<h2>Let's Connect</h2>
<Link to={"#"}>
Expand Down Expand Up @@ -36,7 +36,7 @@ function Footer() {
</h2>
</div>
</div>
<div className="flex flex-col items-center justify-center h-[50px] bg-[#aaa9a9] font-medium">
<div className="flex flex-col items-center justify-center h-[50px] bg-[#aaa9a9] dark:bg-gray-700 font-medium">
<h2>Made with heart by BP</h2>
<h2>Copyright &copy; {today.getFullYear()} </h2>
</div>
Expand Down
26 changes: 13 additions & 13 deletions src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@


import Navbar from "./navbar";
import Loginbtn from "./Loginbtn";
import ResponsiveNav from "./ResponsiveNav";
import { Link, useLocation } from "react-router-dom";




function Header() {
const location = useLocation();

const location = useLocation();



return (
<header className="w-[100%] bg-[#0055E9] text-white flex items-center justify-between fixed top-[0px] border-b-[2px] border-solid border-white z-10 p-[20px]">
{location.pathname=='/'?<div><ResponsiveNav/>
<Navbar /></div>: <Link to={'/'}><div>home</div></Link> }
<Loginbtn/>
<header className="w-[100%] bg-[#0055E9] dark:bg-gray-800 text-white flex items-center justify-between fixed top-[0px] border-b-[2px] border-solid border-white z-10 p-[20px]">
{location.pathname == '/' ? (
<div>
<ResponsiveNav />
<Navbar />
</div>
) : (
<Link to={'/'}>
<div>home</div>
</Link>
)}
<Loginbtn />
</header>
);
}
Expand Down
12 changes: 9 additions & 3 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap');


@tailwind base;
@tailwind components;
@tailwind utilities;
Expand All @@ -9,5 +8,12 @@
font-family: 'Poppins', sans-serif;
margin: 0px;
padding: 0px;

}
}

body {
@apply bg-white text-black;
}

.dark body {
@apply bg-gray-900 text-white;
}
4 changes: 2 additions & 2 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @type {import('tailwindcss').Config}
// @type {import('tailwindcss').Config}

export default {
darkMode: 'class',
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
Expand All @@ -25,4 +26,3 @@ export default {
},
plugins: [],
}