vp-translation.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script setup lang="ts">
  2. import { useToggle } from '@vueuse/core'
  3. import VPLink from '../common/vp-link.vue'
  4. import { useTranslation } from '../../composables/translation'
  5. import ExpandIcon from '../icons/expand.vue'
  6. const emit = defineEmits(['close'])
  7. const { languageMap, langs, lang, switchLang, helpTranslate } = useTranslation()
  8. const [show, toggle] = useToggle()
  9. const onSwitchLang = (lang: string) => {
  10. switchLang(lang)
  11. emit('close')
  12. }
  13. </script>
  14. <template>
  15. <div class="full-screen-translation">
  16. <ElButton
  17. style="width: 100%; color: var(--text-color)"
  18. text
  19. @click="toggle"
  20. >
  21. <div class="translation-toggler">
  22. <span> Translations </span>
  23. <ElIcon :size="14">
  24. <ExpandIcon class="toggle-icon" :class="{ expanded: show }" />
  25. </ElIcon>
  26. </div>
  27. </ElButton>
  28. <div v-show="show" class="translation-items">
  29. <p
  30. v-for="l in langs"
  31. :key="l"
  32. :class="{ active: l === lang }"
  33. class="translation-item"
  34. @click="onSwitchLang(l)"
  35. >
  36. {{ languageMap[l] }}
  37. </p>
  38. <p class="translation-item">
  39. <VPLink :href="`/${lang}/guide/translation`">
  40. {{ helpTranslate }}
  41. </VPLink>
  42. </p>
  43. </div>
  44. </div>
  45. </template>
  46. <style lang="scss" scoped>
  47. .full-screen-translation {
  48. border-bottom: 1px solid var(--border-color);
  49. }
  50. .translation-toggler {
  51. width: 100%;
  52. display: flex;
  53. align-items: center;
  54. justify-content: space-between;
  55. line-height: 24px;
  56. .toggle-icon {
  57. transition: transform var(--el-transition-duration);
  58. transform: rotate(180deg);
  59. &.expanded {
  60. transform: rotate(0deg);
  61. }
  62. }
  63. }
  64. .translation-items {
  65. padding-bottom: 12px;
  66. .translation-item {
  67. cursor: pointer;
  68. margin: 0;
  69. font-size: 14px;
  70. line-height: 32px;
  71. &.active {
  72. font-weight: 500;
  73. color: var(--brand-color);
  74. }
  75. .link-item {
  76. font-weight: 500;
  77. }
  78. }
  79. }
  80. </style>