FontSizePicker.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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(fontSizes.find((size) => size == active))"
  13. />
  14. </span>
  15. </template>
  16. <SmartItem
  17. v-for="(size, index) in fontSizes"
  18. :key="`size-${index}`"
  19. :label="getFontSizeName(size)"
  20. :info-icon="size === active ? 'done' : ''"
  21. :active-info-icon="size === active"
  22. @click.native="
  23. setActiveFont(size)
  24. $refs.fontSize.tippy().hide()
  25. "
  26. />
  27. </tippy>
  28. </span>
  29. </template>
  30. <script lang="ts">
  31. import { defineComponent } from "@nuxtjs/composition-api"
  32. import {
  33. HoppFontSizes,
  34. HoppFontSize,
  35. applySetting,
  36. useSetting,
  37. } from "~/newstore/settings"
  38. export default defineComponent({
  39. setup() {
  40. return {
  41. fontSizes: HoppFontSizes,
  42. active: useSetting("FONT_SIZE"),
  43. }
  44. },
  45. methods: {
  46. getFontSizeName(size: HoppFontSize) {
  47. return this.$t(`settings.font_size_${size}`)
  48. },
  49. setActiveFont(size: HoppFontSize) {
  50. document.documentElement.setAttribute("data-font-size", size)
  51. applySetting("FONT_SIZE", size)
  52. },
  53. },
  54. })
  55. </script>