ThemeToggle.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="theme-switcher" :class="{ 'is-dark': isDark }">
  3. <text
  4. class="theme-btn theme-btn--dark"
  5. :class="{ active: isDark }"
  6. @click="setDark"
  7. >🌙</text>
  8. <text
  9. class="theme-btn theme-btn--light"
  10. :class="{ active: !isDark }"
  11. @click="setLight"
  12. >☀️</text>
  13. </view>
  14. </template>
  15. <script setup>
  16. import { computed } from 'vue'
  17. import { useThemeStore } from '@/stores/theme'
  18. const themeStore = useThemeStore()
  19. const isDark = computed(() => themeStore.theme === 'dark')
  20. function setDark() {
  21. themeStore.setTheme('dark')
  22. }
  23. function setLight() {
  24. themeStore.setTheme('light')
  25. }
  26. </script>
  27. <style>
  28. .theme-switcher {
  29. display: inline-flex;
  30. align-items: center;
  31. background: rgba(255, 255, 255, 0.12);
  32. border: 1px solid rgba(255, 255, 255, 0.2);
  33. border-radius: 999px;
  34. padding: 3px;
  35. gap: 2px;
  36. }
  37. .theme-btn {
  38. font-size: 16px;
  39. padding: 6px 10px;
  40. border-radius: 999px;
  41. cursor: pointer;
  42. transition: all 0.25s ease;
  43. line-height: 1;
  44. opacity: 0.5;
  45. filter: grayscale(0.6);
  46. }
  47. .theme-btn.active {
  48. opacity: 1;
  49. filter: grayscale(0);
  50. background: rgba(255, 255, 255, 0.95);
  51. box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  52. }
  53. .theme-switcher.is-dark .theme-btn.active {
  54. background: rgba(255, 255, 255, 1);
  55. }
  56. </style>