ColorModePicker.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="flex">
  3. <ButtonSecondary
  4. v-for="(color, index) of colors"
  5. :key="`color-${index}`"
  6. v-tippy="{ theme: 'tooltip' }"
  7. :title="$t(getColorModeName(color))"
  8. :class="{
  9. 'bg-primaryLight !text-accent hover:text-accent': color === active,
  10. }"
  11. class="rounded"
  12. :svg="getIcon(color)"
  13. @click.native="setBGMode(color)"
  14. />
  15. </div>
  16. </template>
  17. <script setup lang="ts">
  18. import {
  19. applySetting,
  20. HoppBgColor,
  21. HoppBgColors,
  22. useSetting,
  23. } from "~/newstore/settings"
  24. const colors = HoppBgColors
  25. const active = useSetting("BG_COLOR")
  26. const setBGMode = (color: HoppBgColor) => {
  27. applySetting("BG_COLOR", color)
  28. }
  29. const getIcon = (color: HoppBgColor) => {
  30. switch (color) {
  31. case "system":
  32. return "monitor"
  33. case "light":
  34. return "sun"
  35. case "dark":
  36. return "cloud"
  37. case "black":
  38. return "moon"
  39. default:
  40. return "monitor"
  41. }
  42. }
  43. const getColorModeName = (colorMode: string) => {
  44. switch (colorMode) {
  45. case "system":
  46. return "settings.system_mode"
  47. case "light":
  48. return "settings.light_mode"
  49. case "dark":
  50. return "settings.dark_mode"
  51. case "black":
  52. return "settings.black_mode"
  53. default:
  54. return "settings.system_mode"
  55. }
  56. }
  57. </script>