FontSizePicker.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <span class="inline-flex">
  3. <tippy ref="fontSize" interactive trigger="click" theme="popover" arrow>
  4. <template #trigger>
  5. <span class="select-wrapper">
  6. <ButtonSecondary
  7. v-tippy="{ theme: 'tooltip' }"
  8. :title="t('settings.change_font_size')"
  9. class="pr-8"
  10. svg="type"
  11. outline
  12. :label="`${getFontSizeName(
  13. fontSizes.find((size) => size === active)
  14. )}`"
  15. />
  16. </span>
  17. </template>
  18. <div class="flex flex-col" role="menu">
  19. <SmartItem
  20. v-for="(size, index) in fontSizes"
  21. :key="`size-${index}`"
  22. :label="`${getFontSizeName(size)}`"
  23. :icon="
  24. size === active ? 'radio_button_checked' : 'radio_button_unchecked'
  25. "
  26. :active="size === active"
  27. @click.native="
  28. () => {
  29. setActiveFont(size)
  30. fontSize.tippy().hide()
  31. }
  32. "
  33. />
  34. </div>
  35. </tippy>
  36. </span>
  37. </template>
  38. <script setup lang="ts">
  39. import { ref } from "@nuxtjs/composition-api"
  40. import {
  41. HoppFontSizes,
  42. HoppFontSize,
  43. applySetting,
  44. useSetting,
  45. } from "~/newstore/settings"
  46. import { useI18n } from "~/helpers/utils/composables"
  47. const t = useI18n()
  48. const fontSizes = HoppFontSizes
  49. const active = useSetting("FONT_SIZE")
  50. const fontSize = ref<any | null>(null)
  51. const getFontSizeName = (size: HoppFontSize) => {
  52. return t(`settings.font_size_${size}`)
  53. }
  54. const setActiveFont = (size: HoppFontSize) => {
  55. document.documentElement.setAttribute("data-font-size", size)
  56. applySetting("FONT_SIZE", size)
  57. }
  58. </script>