ColorModePicker.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. import { useI18n } from "~/helpers/utils/composables"
  25. const t = useI18n()
  26. const colors = HoppBgColors
  27. const active = useSetting("BG_COLOR")
  28. const setBGMode = (color: HoppBgColor) => {
  29. applySetting("BG_COLOR", color)
  30. }
  31. const getIcon = (color: HoppBgColor) => {
  32. switch (color) {
  33. case "system":
  34. return "monitor"
  35. case "light":
  36. return "sun"
  37. case "dark":
  38. return "cloud"
  39. case "black":
  40. return "moon"
  41. default:
  42. return "monitor"
  43. }
  44. }
  45. const getColorModeName = (colorMode: string) => {
  46. switch (colorMode) {
  47. case "system":
  48. return "settings.system_mode"
  49. case "light":
  50. return "settings.light_mode"
  51. case "dark":
  52. return "settings.dark_mode"
  53. case "black":
  54. return "settings.black_mode"
  55. default:
  56. return "settings.system_mode"
  57. }
  58. }
  59. </script>