-
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.
Add light/dark mode and styling consistency.
- Loading branch information
1 parent
8ad8957
commit 65f67b8
Showing
9 changed files
with
202 additions
and
94 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
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,14 @@ | ||
--- | ||
import Theme from "./Theme.astro"; | ||
--- | ||
|
||
<div class="flex gap-1 items-start"> | ||
<a | ||
href="/" | ||
class="hover:cursor-pointer hover:bg-blue-400/30 text-blue-500 visited:text-purple-500 py-2" | ||
>[ Home ]</a | ||
> | ||
<div class="ml-auto py-1.5"> | ||
<Theme /> | ||
</div> | ||
</div> |
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,83 @@ | ||
--- | ||
--- | ||
|
||
<div class="hover:cursor-pointer" id="themeToggle"> | ||
<svg height="24px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<path | ||
class="fill-textBlack dark:fill-transparent weeb:fill-transparent" | ||
fill-rule="evenodd" | ||
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z" | ||
></path> | ||
<path | ||
class="fill-transparent dark:fill-backgroundWhite weeb:fill-backgroundWhite" | ||
fill-rule="evenodd" | ||
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z" | ||
></path> | ||
</svg> | ||
</div> | ||
|
||
<script is:inline> | ||
const theme = (() => { | ||
if (typeof localStorage !== "undefined" && localStorage.getItem("theme")) { | ||
return localStorage.getItem("theme") ?? "light"; | ||
} | ||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
return "dark"; | ||
} | ||
return "light"; | ||
})(); | ||
|
||
document.documentElement.classList.toggle("dark", theme === "dark"); | ||
document.documentElement.classList.toggle("weeb", theme === "weeb"); | ||
window.localStorage.setItem("theme", theme); | ||
|
||
let longPressTimeout; | ||
let isLongPress = false; | ||
|
||
const handleToggleClick = () => { | ||
if (isLongPress) { | ||
isLongPress = false; | ||
return; | ||
} | ||
|
||
const element = document.documentElement; | ||
|
||
if (element.classList.contains("weeb")) { | ||
element.classList.remove("weeb"); | ||
element.classList.add("dark"); | ||
localStorage.setItem("theme", "dark"); | ||
} else if (element.classList.contains("dark")) { | ||
element.classList.remove("dark"); | ||
localStorage.setItem("theme", "light"); | ||
} else { | ||
element.classList.add("dark"); | ||
localStorage.setItem("theme", "dark"); | ||
} | ||
}; | ||
|
||
const handleLongPress = () => { | ||
const element = document.documentElement; | ||
if (element.classList.contains("dark")) { | ||
element.classList.remove("dark"); | ||
element.classList.add("weeb"); | ||
localStorage.setItem("theme", "weeb"); | ||
isLongPress = true; | ||
} | ||
}; | ||
|
||
const handleMouseDown = () => { | ||
longPressTimeout = setTimeout(handleLongPress, 500); | ||
}; | ||
|
||
const handleMouseUp = () => { | ||
clearTimeout(longPressTimeout); | ||
}; | ||
|
||
const themeToggleElement = document.getElementById("themeToggle"); | ||
themeToggleElement?.addEventListener("click", handleToggleClick); | ||
|
||
themeToggleElement?.addEventListener("mousedown", handleMouseDown); | ||
themeToggleElement?.addEventListener("mouseup", handleMouseUp); | ||
themeToggleElement?.addEventListener("mouseleave", handleMouseUp); | ||
</script> |
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
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
Oops, something went wrong.