-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
23 changed files
with
353 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ToggleMode } from "./toggle-mode"; | ||
import { Logo } from "./logo"; | ||
|
||
const Header = () => { | ||
return ( | ||
<header className="h-14 w-full fixed top-0 bg-secondary/10 backdrop-blur-lg border-b border-secondary/25 shadow-sm px-4 lg:px-0"> | ||
<nav className="max-w-screen-lg mx-auto h-full flex-between"> | ||
<Logo /> | ||
<ToggleMode /> | ||
</nav> | ||
</header> | ||
); | ||
}; | ||
|
||
export { Header }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Link } from "react-router-dom"; | ||
|
||
import { AppRoutes } from "@/constants/routes"; | ||
import { KEY } from "@/constants/assets"; | ||
|
||
const Logo = () => { | ||
return ( | ||
<h1 className="transition-all ease-in-out duration-200 drop-shadow-lg hover:drop-shadow-secondary-glow hover:scale-95"> | ||
<Link to={AppRoutes.Root} className="flex items-center gap-x-2"> | ||
<img src={KEY} alt="Key Logo" className="w-8 h-8" loading="lazy" /> | ||
<div className="flex flex-col"> | ||
<span className="text-lg font-bold leading-none text-secondary"> | ||
Go | ||
</span> | ||
<span className="font-semibold leading-none">React Auth</span> | ||
</div> | ||
</Link> | ||
</h1> | ||
); | ||
}; | ||
|
||
export { Logo }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Moon, Sun } from "lucide-react"; | ||
|
||
import { Theme, useTheme } from "@/lib/hooks/use-theme"; | ||
|
||
const ToggleMode = () => { | ||
const { theme, setTheme } = useTheme(); | ||
|
||
const onClick = () => { | ||
if (theme === Theme.Light) { | ||
setTheme(Theme.Dark); | ||
} else { | ||
setTheme(Theme.Light); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
className="w-10 h-10 rounded-full flex-center transition-colors bg-accent/40 hover:bg-accent" | ||
onClick={onClick} | ||
> | ||
{theme === Theme.Light ? <Sun size={22} /> : <Moon size={22} />} | ||
</button> | ||
); | ||
}; | ||
|
||
export { ToggleMode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import key from "@/assets/key.svg"; | ||
|
||
export const KEY = key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum AppRoutes { | ||
Root = "/", | ||
SignUp = "/sign-up", | ||
SignIn = "/sign-in", | ||
ForgotPassword = "/forgot-password", | ||
ResetPassword = "/reset-password", | ||
VerifyEmail = "/verify-email", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useContext } from "react"; | ||
|
||
import { ThemeProviderContext } from "@/lib/providers/theme-provider"; | ||
|
||
export enum Theme { | ||
System = "system", | ||
Light = "light", | ||
Dark = "dark", | ||
} | ||
|
||
const useTheme = () => { | ||
const context = useContext(ThemeProviderContext); | ||
|
||
if (context === undefined) { | ||
throw new Error("useTheme must be used within a ThemeProvider"); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export { useTheme }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { createContext, useEffect, useState } from "react"; | ||
|
||
type Theme = "dark" | "light" | "system"; | ||
|
||
type ThemeProviderProps = { | ||
children: React.ReactNode; | ||
defaultTheme?: Theme; | ||
storageKey?: string; | ||
}; | ||
|
||
type ThemeProviderState = { | ||
theme: Theme; | ||
setTheme: (theme: Theme) => void; | ||
}; | ||
|
||
const initialState: ThemeProviderState = { | ||
theme: "system", | ||
setTheme: () => null, | ||
}; | ||
|
||
const ThemeProviderContext = createContext<ThemeProviderState>(initialState); | ||
|
||
const ThemeProvider = ({ | ||
children, | ||
defaultTheme = "system", | ||
storageKey = "vite-ui-theme", | ||
...props | ||
}: ThemeProviderProps) => { | ||
const [theme, setTheme] = | ||
useState<Theme>(() => localStorage.getItem(storageKey) as Theme) || | ||
defaultTheme; | ||
|
||
useEffect(() => { | ||
const root = window.document.documentElement; | ||
|
||
root.classList.remove("light", "dark"); | ||
|
||
if (theme === "system") { | ||
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)") | ||
.matches | ||
? "dark" | ||
: "light"; | ||
|
||
root.classList.add(systemTheme); | ||
|
||
setTheme(systemTheme); | ||
|
||
return; | ||
} | ||
|
||
root.classList.add(theme); | ||
}, [theme, setTheme]); | ||
|
||
const value = { | ||
theme, | ||
setTheme: (theme: Theme) => { | ||
localStorage.setItem(storageKey, theme); | ||
setTheme(theme); | ||
}, | ||
}; | ||
|
||
return ( | ||
<ThemeProviderContext.Provider {...props} value={value}> | ||
{children} | ||
</ThemeProviderContext.Provider> | ||
); | ||
}; | ||
|
||
export { ThemeProvider, ThemeProviderContext }; |
Oops, something went wrong.