-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e6cd2e4
commit 26bd485
Showing
4 changed files
with
77 additions
and
70 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 |
---|---|---|
@@ -1,32 +1,37 @@ | ||
--- | ||
import HeaderLink from './HeaderLink.astro'; | ||
import { SITE_TITLE } from '../consts'; | ||
import Toggle from './Toggle.astro' | ||
import Toggle from './Toggle.astro'; | ||
--- | ||
|
||
<script> | ||
const root = document.querySelector(':root') | ||
const themeToggle = document.getElementById('themeToggle') as HTMLInputElement | ||
const root = document.querySelector(':root'); | ||
const themeToggle = document.getElementById( | ||
'themeToggle', | ||
) as HTMLInputElement; | ||
|
||
const savedTheme = localStorage.getItem('darkTheme'); | ||
const savedTheme = localStorage.getItem('darkTheme'); | ||
|
||
// Set default theme | ||
themeToggle.checked = savedTheme ? savedTheme === 'true' : window.matchMedia('(prefers-color-scheme: dark)').matches | ||
themeToggle.checked = savedTheme | ||
? savedTheme === 'true' | ||
: window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
|
||
const updateTheme = () => { | ||
if (themeToggle.checked) { | ||
root?.classList.add('dark') | ||
localStorage.setItem('darkTheme', 'true') | ||
root?.classList.add('dark'); | ||
localStorage.setItem('darkTheme', 'true'); | ||
} else { | ||
root?.classList.remove('dark') | ||
localStorage.setItem('darkTheme', 'false') | ||
root?.classList.remove('dark'); | ||
localStorage.setItem('darkTheme', 'false'); | ||
} | ||
} | ||
}; | ||
|
||
// Set default toggle value | ||
updateTheme() | ||
updateTheme(); | ||
|
||
// Add togglable theme | ||
themeToggle?.addEventListener('change', updateTheme) | ||
themeToggle?.addEventListener('change', updateTheme); | ||
</script> | ||
|
||
<header> | ||
|
@@ -38,7 +43,7 @@ import Toggle from './Toggle.astro' | |
<HeaderLink href='/about'>About</HeaderLink> | ||
</div> | ||
<div class='social-links'> | ||
<Toggle id="themeToggle"/> | ||
<Toggle id='themeToggle' /> | ||
|
||
<a href='https://nfld.social/@devthedevel' target='_blank'> | ||
<span class='sr-only'>Follow [email protected] on Mastodon</span> | ||
|
@@ -98,7 +103,7 @@ import Toggle from './Toggle.astro' | |
align-items: center; | ||
} | ||
.social-links a:hover { | ||
color: var(--primary) | ||
color: var(--primary); | ||
} | ||
@media (max-width: 720px) { | ||
.social-links { | ||
|
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 |
---|---|---|
@@ -1,57 +1,57 @@ | ||
--- | ||
interface Props { | ||
id: string; | ||
name?: string; | ||
id: string; | ||
name?: string; | ||
} | ||
const { id, name } = Astro.props; | ||
--- | ||
|
||
<style> | ||
.toggleContainer { | ||
display: flex; | ||
align-items: center; | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
} | ||
|
||
.toggleBox { | ||
display: none; | ||
} | ||
.toggle { | ||
display: inline-block;; | ||
width: 40px; | ||
height: 20px; | ||
background-color: #ccc; | ||
border-radius: 10px; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.toggle::before { | ||
content: ""; | ||
position: absolute; | ||
top: 2px; | ||
left: 2px; | ||
width: 16px; | ||
height: 16px; | ||
background-color: white; | ||
border-radius: 50%; | ||
transition: transform 0.3s; | ||
} | ||
.toggleBox:checked + .toggle { | ||
background-color: var(--primary); | ||
} | ||
|
||
.toggleBox:checked + .toggle::before { | ||
transform: translateX(20px); | ||
} | ||
.toggleContainer { | ||
display: flex; | ||
align-items: center; | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
} | ||
|
||
.toggleBox { | ||
display: none; | ||
} | ||
|
||
.toggle { | ||
display: inline-block; | ||
width: 40px; | ||
height: 20px; | ||
background-color: #ccc; | ||
border-radius: 10px; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.toggle::before { | ||
content: ''; | ||
position: absolute; | ||
top: 2px; | ||
left: 2px; | ||
width: 16px; | ||
height: 16px; | ||
background-color: white; | ||
border-radius: 50%; | ||
transition: transform 0.3s; | ||
} | ||
|
||
.toggleBox:checked + .toggle { | ||
background-color: var(--primary); | ||
} | ||
|
||
.toggleBox:checked + .toggle::before { | ||
transform: translateX(20px); | ||
} | ||
</style> | ||
|
||
<div class="toggleContainer"> | ||
{name} | ||
<input id={id} type="checkbox" class="toggleBox"/> | ||
<label for={id} class="toggle"/> | ||
</div> | ||
<div class='toggleContainer'> | ||
{name} | ||
<input id={id} type='checkbox' class='toggleBox' /> | ||
<label for={id} class='toggle'></label> | ||
</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