-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature to toggle between light mode and dark mode
wip
(#83)
* Feat: add dark/lightmode to docs website --------- Co-authored-by: Erik van der Bas <[email protected]>
- Loading branch information
Showing
20 changed files
with
333 additions
and
152 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
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 @@ | ||
<button | ||
class="themeSwitcher" | ||
type="button" | ||
onclick="window.switchTheme()" | ||
> | ||
<span class="themeSwitcher__indicator themeSwitcher__indicator--dark"> | ||
<svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-sun"> | ||
<circle cx="12" cy="12" r="4"/> | ||
<path d="M12 2v2"/> | ||
<path d="M12 20v2"/> | ||
<path d="m4.93 4.93 1.41 1.41"/> | ||
<path d="m17.66 17.66 1.41 1.41"/> | ||
<path d="M2 12h2"/><path d="M20 12h2"/> | ||
<path d="m6.34 17.66-1.41 1.41"/> | ||
<path d="m19.07 4.93-1.41 1.41"/> | ||
</svg> | ||
</span> | ||
<span class="themeSwitcher__indicator themeSwitcher__indicator--light"> | ||
<svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-moon"> | ||
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/> | ||
</svg> | ||
</span> | ||
<span class="sr-only"> | ||
Toggle Light Dark Mode | ||
</span> | ||
</button> |
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,20 @@ | ||
window.switchTheme = () => { | ||
const isDark = window.localStorage.getItem('theme') === 'dark'; | ||
document.documentElement.setAttribute('data-theme', isDark ? 'light' : 'dark'); | ||
|
||
localStorage.setItem("theme", document.documentElement.getAttribute('data-theme')); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
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'; | ||
})(); | ||
document.documentElement.setAttribute('data-theme', theme); | ||
window.localStorage.setItem('theme', theme); | ||
}); |
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.