light-dark-toggle.html 815 B

123456789101112131415161718192021
  1. {{ if $.Param "enableDarkMode" }}
  2. <button id="toggleToDark" class="navbar__icons--icon" aria-label="Toggle to dark mode">
  3. {{ partial "svgs/light-mode.svg" (dict "width" 20 "height" 20) }}
  4. </button>
  5. <button id="toggleToLight" class="navbar__icons--icon" aria-label="Toggle to light mode">
  6. {{ partial "svgs/dark-mode.svg" (dict "width" 20 "height" 20) }}
  7. </button>
  8. <script>
  9. var theme = localStorage.getItem('theme');
  10. var toggleToLightBtn = document.getElementById('toggleToLight');
  11. var toggleToDarkBtn = document.getElementById('toggleToDark');
  12. if (theme && theme === 'dark') {
  13. toggleToLightBtn.className = 'navbar__icons--icon';
  14. toggleToDarkBtn.className = 'hide';
  15. } else {
  16. toggleToLightBtn.className = 'hide';
  17. toggleToDarkBtn.className = 'navbar__icons--icon';
  18. }
  19. </script>
  20. {{ end }}