Skip to content

Commit

Permalink
Merge pull request #52 from the-collab-lab/jo-dark-light-login
Browse files Browse the repository at this point in the history
Consistent dark and light theme throughout app
  • Loading branch information
joriordan332 authored Oct 13, 2024
2 parents 83c0428 + 71e6303 commit 6dcc2cf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/Context.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { useState } from 'react';

export const Context = React.createContext();
export const ContextProvider = ({ children }) => {
const [darkMode, setDarkMode] = useState(false);

return (
<Context.Provider value={{ darkMode, setDarkMode }}>
{children}
</Context.Provider>
);
};
6 changes: 3 additions & 3 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';

import { ContextProvider } from './Context';
import './index.css';

const root = createRoot(document.getElementById('root'));
root.render(
<StrictMode>
<ContextProvider>
<App />
</StrictMode>,
</ContextProvider>,
);
7 changes: 4 additions & 3 deletions src/views/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import { useState } from 'react';
import { useContext } from 'react';
import { Outlet } from 'react-router-dom';
import './Layout.css';
import { Toaster } from 'react-hot-toast';
import { NavBar } from '@/components/NavBar';
import { Context } from '../Context';
import './Layout.css';

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

export function Layout() {
const [darkMode, setDarkMode] = useState(false);
const { darkMode, setDarkMode } = useContext(Context);

const toggleDarkMode = () => {
setDarkMode(!darkMode);
Expand Down
9 changes: 9 additions & 0 deletions src/views/Login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.dark {
background-color: #1f1e26;
color: #ffffff;
}

.false {
background-color: #ffffff;
color: #1f1e26;
}
35 changes: 31 additions & 4 deletions src/views/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { useAuth } from '../api/useAuth';
import { useEffect } from 'react';
import { useEffect, useContext } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button } from '@/components/ui/button';
import { Eclipse, Sun } from 'lucide-react';
import { Context } from '../Context';
import './Login.css';

function Login() {
const { darkMode, setDarkMode } = useContext(Context);
const { user, signIn } = useAuth();
const navigate = useNavigate();

Expand All @@ -12,11 +17,21 @@ function Login() {
}
}, [user]);

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

return (
<div className="flex justify-center items-center h-screen">
<div className="bg-black text-white rounded-xl w-11/12 max-w-lg p-8 shadow-xl">
<div
className={`${darkMode && 'dark'} flex justify-center items-center h-screen`}
>
<div className="bg-transparent text-white w-11/12 max-w-lg p-8 ">
<div className="flex justify-center items-center mb-6">
<img src="grocerease-light.png" alt="Shopping app logo" />
{darkMode ? (
<img src="grocerease-light.png" alt="Shopping app logo" />
) : (
<img src="grocerease.png" alt="Shopping app logo" />
)}
</div>
<div className="flex justify-center items-center h-2/5">
<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">
Expand All @@ -26,6 +41,18 @@ function Login() {
</div>
</div>
</div>
<Button
onClick={toggleDarkMode}
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"
>
<abbr title={darkMode ? 'Switch to light mode' : 'Switch to dark mode'}>
<button
className={`${darkMode && 'dark'} rounded-full text-primary-pink hover:text-opacity-60`}
>
{darkMode ? <Eclipse /> : <Sun />}
</button>
</abbr>
</Button>
</div>
);
}
Expand Down

0 comments on commit 6dcc2cf

Please sign in to comment.