ColorModePicker.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 lang="ts">
  18. import { defineComponent } from "@nuxtjs/composition-api"
  19. import {
  20. applySetting,
  21. HoppBgColor,
  22. HoppBgColors,
  23. useSetting,
  24. } from "~/newstore/settings"
  25. export default defineComponent({
  26. setup() {
  27. return {
  28. colors: HoppBgColors,
  29. active: useSetting("BG_COLOR"),
  30. }
  31. },
  32. methods: {
  33. setBGMode(color: HoppBgColor) {
  34. applySetting("BG_COLOR", color)
  35. },
  36. getIcon(color: HoppBgColor) {
  37. switch (color) {
  38. case "system":
  39. return "monitor"
  40. case "light":
  41. return "sun"
  42. case "dark":
  43. return "cloud"
  44. case "black":
  45. return "moon"
  46. default:
  47. return "monitor"
  48. }
  49. },
  50. getColorModeName(colorMode: string) {
  51. switch (colorMode) {
  52. case "system":
  53. return "settings.system_mode"
  54. case "light":
  55. return "settings.light_mode"
  56. case "dark":
  57. return "settings.dark_mode"
  58. case "black":
  59. return "settings.black_mode"
  60. default:
  61. return "settings.system_mode"
  62. }
  63. },
  64. },
  65. })
  66. </script>