ModeToggle.vue 564 B

123456789101112131415161718
  1. <template>
  2. <button
  3. type="button"
  4. class="flex h-6 w-6 items-center justify-center rounded-md transition hover:bg-zinc-900/5 dark:hover:bg-white/5"
  5. aria-label="Toggle dark mode"
  6. @click="toggleMode()">
  7. <IconsSun class="h-5 w-5 stroke-zinc-900 dark:hidden" />
  8. <IconsMoon class="hidden h-5 w-5 stroke-white dark:block" />
  9. </button>
  10. </template>
  11. <script setup>
  12. const colorMode = useColorMode();
  13. const toggleMode = () => {
  14. colorMode.value = ( colorMode.value == 'dark' ? 'light' : 'dark' );
  15. }
  16. </script>