FontSizePicker.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. <SmartItem
  19. v-for="(size, index) in fontSizes"
  20. :key="`size-${index}`"
  21. :label="`${getFontSizeName(size)}`"
  22. :icon="
  23. size === active ? 'radio_button_checked' : 'radio_button_unchecked'
  24. "
  25. @click.native="
  26. () => {
  27. setActiveFont(size)
  28. $refs.fontSize.tippy().hide()
  29. }
  30. "
  31. />
  32. </tippy>
  33. </span>
  34. </template>
  35. <script setup lang="ts">
  36. import {
  37. HoppFontSizes,
  38. HoppFontSize,
  39. applySetting,
  40. useSetting,
  41. } from "~/newstore/settings"
  42. import { useI18n } from "~/helpers/utils/composables"
  43. const t = useI18n()
  44. const fontSizes = HoppFontSizes
  45. const active = useSetting("FONT_SIZE")
  46. const getFontSizeName = (size: HoppFontSize) => {
  47. return t(`settings.font_size_${size}`)
  48. }
  49. const setActiveFont = (size: HoppFontSize) => {
  50. document.documentElement.setAttribute("data-font-size", size)
  51. applySetting("FONT_SIZE", size)
  52. }
  53. </script>