-
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.
- Loading branch information
rxyhn
committed
Sep 16, 2024
1 parent
61bd031
commit 1a85452
Showing
8 changed files
with
127 additions
and
152 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
import { Icon } from "astro-icon/components"; | ||
import { cn } from "@/lib/utils"; | ||
--- | ||
|
||
<button | ||
id="drawer_toggle" | ||
aria-label={`Toggle drawer open and closed`} | ||
class={cn( | ||
"flex md:hidden", | ||
"size-9 rounded-full p-2 items-center justify-center", | ||
"bg-transparent hover:bg-black/20 dark:hover:bg-white/20", | ||
"stroke-current hover:stroke-black hover:dark:stroke-white", | ||
"border border-black/25 dark:border-white/25", | ||
"transition-colors duration-300 ease-in-out" | ||
)} | ||
> | ||
<Icon id="drawer-open" name="menu" class="size-full" /> | ||
<Icon id="drawer-close" name="close" class="size-full" /> | ||
</button> | ||
|
||
<style> | ||
#drawer_toggle > #drawer-open { | ||
@apply block; | ||
} | ||
|
||
#drawer_toggle > #drawer-close { | ||
@apply hidden; | ||
} | ||
|
||
#drawer_toggle.open > #drawer-open { | ||
@apply hidden; | ||
} | ||
|
||
#drawer_toggle.open > #drawer-close { | ||
@apply block; | ||
} | ||
</style> | ||
|
||
<script is:inline> | ||
function toggleDrawer() { | ||
const drawer = document.getElementById("drawer"); | ||
const drawerButton = document.getElementById("drawer_toggle"); | ||
drawer?.classList.toggle("open"); | ||
drawerButton?.classList.toggle("open"); | ||
} | ||
|
||
function initializeDrawerButton() { | ||
const drawerButton = document.getElementById("drawer_toggle"); | ||
drawerButton?.addEventListener("click", toggleDrawer); | ||
} | ||
|
||
document.addEventListener("astro:after-swap", initializeDrawerButton); | ||
initializeDrawerButton(); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
import { Icon } from "astro-icon/components"; | ||
import { cn } from "@/lib/utils"; | ||
--- | ||
|
||
<button | ||
id="theme_toggle" | ||
aria-label={`Toggle light and dark theme`} | ||
class={cn( | ||
"flex", | ||
"size-9 rounded-full p-2 items-center justify-center", | ||
"bg-transparent hover:bg-black/20 dark:hover:bg-white/20", | ||
"stroke-current hover:stroke-black hover:dark:stroke-white", | ||
"border border-black/25 dark:border-white/25", | ||
"transition-colors duration-300 ease-in-out" | ||
)} | ||
> | ||
<Icon name="sun" class="block size-full dark:hidden" /> | ||
<Icon name="moon" class="hidden size-full dark:block" /> | ||
</button> | ||
|
||
<style> | ||
html { | ||
color-scheme: light; | ||
background-color: white; | ||
} | ||
|
||
html.dark { | ||
color-scheme: dark; | ||
background-color: black; | ||
} | ||
</style> | ||
|
||
<script is:inline> | ||
const theme = (() => { | ||
if (typeof localStorage !== "undefined" && localStorage.getItem("theme")) { | ||
return localStorage.getItem("theme"); | ||
} | ||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
return "dark"; | ||
} | ||
return "light"; | ||
})(); | ||
|
||
if (theme === "light") { | ||
document.documentElement.classList.remove("dark"); | ||
} else { | ||
document.documentElement.classList.add("dark"); | ||
} | ||
|
||
window.localStorage.setItem("theme", theme); | ||
|
||
const handleToggleClick = () => { | ||
const element = document.documentElement; | ||
element.classList.toggle("dark"); | ||
|
||
const isDark = element.classList.contains("dark"); | ||
localStorage.setItem("theme", isDark ? "dark" : "light"); | ||
}; | ||
|
||
document | ||
.getElementById("theme_toggle") | ||
.addEventListener("click", handleToggleClick); | ||
</script> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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