Skip to content

Commit

Permalink
Merge pull request #69 from garyb1/68-dark-mode
Browse files Browse the repository at this point in the history
#68 - Dark Mode Accessible Name
  • Loading branch information
markteekman committed Dec 10, 2023
2 parents 077f5ac + 47019d1 commit bad0816
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions DarkMode.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
type Props = Record<string, never>
---
<button class="darkmode-toggle" aria-pressed="false" aria-label="Enable dark mode" transition:persist>
<button class="darkmode-toggle" aria-pressed="false" aria-label="Toggle Dark Mode" transition:persist>
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="32" height="32" viewBox="0 0 24 24"
><path
fill="currentColor"
Expand All @@ -21,15 +21,13 @@ const enableDarkMode = (store = true) => {
document.body.classList.add('darkmode')
darkModeToggle.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="32" height="32" viewBox="0 0 24 24"><path fill-rule="evenodd" clip-rule="evenodd" d="M13 3a1 1 0 1 0-2 0v1a1 1 0 1 0 2 0V3zM5.707 4.293a1 1 0 0 0-1.414 1.414l1 1a1 1 0 0 0 1.414-1.414l-1-1zm14 0a1 1 0 0 0-1.414 0l-1 1a1 1 0 0 0 1.414 1.414l1-1a1 1 0 0 0 0-1.414zM12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm-9 4a1 1 0 1 0 0 2h1a1 1 0 1 0 0-2H3zm17 0a1 1 0 1 0 0 2h1a1 1 0 1 0 0-2h-1zM6.707 18.707a1 1 0 1 0-1.414-1.414l-1 1a1 1 0 1 0 1.414 1.414l1-1zm12-1.414a1 1 0 0 0-1.414 1.414l1 1a1 1 0 0 0 1.414-1.414l-1-1zM13 20a1 1 0 1 0-2 0v1a1 1 0 1 0 2 0v-1z" fill="currentColor"/></svg>`
darkModeToggle.setAttribute('aria-pressed', 'true')
darkModeToggle.setAttribute('aria-label', 'Disable dark mode')
if (store) localStorage.setItem('darkMode', 'enabled')
}
const disableDarkMode = (store = true) => {
document.body.classList.remove('darkmode')
darkModeToggle.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M9.353 3C5.849 4.408 3 7.463 3 11.47A9.53 9.53 0 0 0 12.53 21c4.007 0 7.062-2.849 8.47-6.353C8.17 17.065 8.14 8.14 9.353 3z"/></svg>`
darkModeToggle.setAttribute('aria-pressed', 'false')
darkModeToggle.setAttribute('aria-label', 'Enable dark mode')
if (store) localStorage.setItem('darkMode', 'disabled')
}
Expand Down

0 comments on commit bad0816

Please sign in to comment.