vp-translation.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 style="width: 100%; color: var(--text-color)" text @click="toggle">
  17. <div class="translation-toggler">
  18. <span> Translations </span>
  19. <ElIcon :size="14">
  20. <ExpandIcon class="toggle-icon" :class="{ expanded: show }" />
  21. </ElIcon>
  22. </div>
  23. </ElButton>
  24. <div v-show="show" class="translation-items">
  25. <p v-for="l in langs" :key="l" :class="{ active: l === lang }" class="translation-item" @click="onSwitchLang(l)">
  26. {{ languageMap[l] }}
  27. </p>
  28. <p class="translation-item">
  29. <VPLink :href="`/${lang}/guide/translation`">
  30. {{ helpTranslate }}
  31. </VPLink>
  32. </p>
  33. </div>
  34. </div>
  35. </template>
  36. <style lang="scss" scoped>
  37. .full-screen-translation {
  38. border-bottom: 1px solid var(--border-color);
  39. }
  40. .translation-toggler {
  41. width: 100%;
  42. display: flex;
  43. align-items: center;
  44. justify-content: space-between;
  45. line-height: 24px;
  46. .toggle-icon {
  47. transition: transform var(--el-transition-duration);
  48. transform: rotate(180deg);
  49. &.expanded {
  50. transform: rotate(0deg);
  51. }
  52. }
  53. }
  54. .translation-items {
  55. padding-bottom: 12px;
  56. .translation-item {
  57. cursor: pointer;
  58. margin: 0;
  59. font-size: 14px;
  60. line-height: 32px;
  61. &.active {
  62. font-weight: 500;
  63. color: var(--brand-color);
  64. }
  65. .link-item {
  66. font-weight: 500;
  67. }
  68. }
  69. }
  70. </style>