AvatarMenuAppearanceItem.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { storeToRefs } from 'pinia'
  4. import { computed, ref } from 'vue'
  5. import CommonPopoverMenuItem, {
  6. type Props,
  7. } from '#desktop/components/CommonPopover/CommonPopoverMenuItem.vue'
  8. import ThemeSwitch from '#desktop/components/ThemeSwitch/ThemeSwitch.vue'
  9. import type { ThemeSwitchInstance } from '#desktop/components/ThemeSwitch/types.ts'
  10. import { useThemeStore } from '#desktop/stores/theme.ts'
  11. defineProps<Props>()
  12. const themeSwitch = ref<ThemeSwitchInstance>()
  13. const cycleThemeSwitchValue = () => {
  14. themeSwitch.value?.cycleValue()
  15. }
  16. const themeStore = useThemeStore()
  17. const { updateTheme } = themeStore
  18. const { currentTheme } = storeToRefs(themeStore)
  19. const modelTheme = computed({
  20. get: () => currentTheme.value,
  21. set: (theme) => updateTheme(theme),
  22. })
  23. </script>
  24. <template>
  25. <CommonPopoverMenuItem
  26. v-bind="{ ...$props, ...$attrs }"
  27. @click="cycleThemeSwitchValue"
  28. />
  29. <div class="flex items-center px-2">
  30. <ThemeSwitch
  31. ref="themeSwitch"
  32. v-model="modelTheme"
  33. class="hover:outline-blue-300 focus:outline-blue-600 hover:focus:outline-blue-600 dark:hover:outline-blue-950 dark:focus:outline-blue-900 dark:hover:focus:outline-blue-900"
  34. size="small"
  35. />
  36. </div>
  37. </template>