Skip to content

Commit 6dcc2cf

Browse files
authored
Merge pull request #52 from the-collab-lab/jo-dark-light-login
Consistent dark and light theme throughout app
2 parents 83c0428 + 71e6303 commit 6dcc2cf

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

src/Context.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { useState } from 'react';
2+
3+
export const Context = React.createContext();
4+
export const ContextProvider = ({ children }) => {
5+
const [darkMode, setDarkMode] = useState(false);
6+
7+
return (
8+
<Context.Provider value={{ darkMode, setDarkMode }}>
9+
{children}
10+
</Context.Provider>
11+
);
12+
};

src/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { StrictMode } from 'react';
22
import { createRoot } from 'react-dom/client';
33
import { App } from './App';
4-
4+
import { ContextProvider } from './Context';
55
import './index.css';
66

77
const root = createRoot(document.getElementById('root'));
88
root.render(
9-
<StrictMode>
9+
<ContextProvider>
1010
<App />
11-
</StrictMode>,
11+
</ContextProvider>,
1212
);

src/views/Layout.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable jsx-a11y/anchor-is-valid */
2-
import { useState } from 'react';
2+
import { useContext } from 'react';
33
import { Outlet } from 'react-router-dom';
4-
import './Layout.css';
54
import { Toaster } from 'react-hot-toast';
65
import { NavBar } from '@/components/NavBar';
6+
import { Context } from '../Context';
7+
import './Layout.css';
78

89
/**
910
* TODO: The links defined in this file don't work!
@@ -14,7 +15,7 @@ import { NavBar } from '@/components/NavBar';
1415
*/
1516

1617
export function Layout() {
17-
const [darkMode, setDarkMode] = useState(false);
18+
const { darkMode, setDarkMode } = useContext(Context);
1819

1920
const toggleDarkMode = () => {
2021
setDarkMode(!darkMode);

src/views/Login.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.dark {
2+
background-color: #1f1e26;
3+
color: #ffffff;
4+
}
5+
6+
.false {
7+
background-color: #ffffff;
8+
color: #1f1e26;
9+
}

src/views/Login.jsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { useAuth } from '../api/useAuth';
2-
import { useEffect } from 'react';
2+
import { useEffect, useContext } from 'react';
33
import { useNavigate } from 'react-router-dom';
4+
import { Button } from '@/components/ui/button';
5+
import { Eclipse, Sun } from 'lucide-react';
6+
import { Context } from '../Context';
7+
import './Login.css';
48

59
function Login() {
10+
const { darkMode, setDarkMode } = useContext(Context);
611
const { user, signIn } = useAuth();
712
const navigate = useNavigate();
813

@@ -12,11 +17,21 @@ function Login() {
1217
}
1318
}, [user]);
1419

20+
const toggleDarkMode = () => {
21+
setDarkMode(!darkMode);
22+
};
23+
1524
return (
16-
<div className="flex justify-center items-center h-screen">
17-
<div className="bg-black text-white rounded-xl w-11/12 max-w-lg p-8 shadow-xl">
25+
<div
26+
className={`${darkMode && 'dark'} flex justify-center items-center h-screen`}
27+
>
28+
<div className="bg-transparent text-white w-11/12 max-w-lg p-8 ">
1829
<div className="flex justify-center items-center mb-6">
19-
<img src="grocerease-light.png" alt="Shopping app logo" />
30+
{darkMode ? (
31+
<img src="grocerease-light.png" alt="Shopping app logo" />
32+
) : (
33+
<img src="grocerease.png" alt="Shopping app logo" />
34+
)}
2035
</div>
2136
<div className="flex justify-center items-center h-2/5">
2237
<div className="flex justify-center items-center bg-pink-500 hover:bg-pink-500 hover:bg-opacity-80 w-2/4 h-1/4 rounded-xl p-2">
@@ -26,6 +41,18 @@ function Login() {
2641
</div>
2742
</div>
2843
</div>
44+
<Button
45+
onClick={toggleDarkMode}
46+
className="fixed w-16 bottom-16 right-16 p-2 rounded-full text-primary-pink hover:text-primary-pink hover:text-opacity-60 font-semibold"
47+
>
48+
<abbr title={darkMode ? 'Switch to light mode' : 'Switch to dark mode'}>
49+
<button
50+
className={`${darkMode && 'dark'} rounded-full text-primary-pink hover:text-opacity-60`}
51+
>
52+
{darkMode ? <Eclipse /> : <Sun />}
53+
</button>
54+
</abbr>
55+
</Button>
2956
</div>
3057
);
3158
}

0 commit comments

Comments
 (0)