LanguageSelector.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <v-select
  3. v-model="locale"
  4. :items="items"
  5. :key="`locale-${locale}`"
  6. density="compact"
  7. variant="plain"
  8. :hide-details="true"
  9. >
  10. <template v-slot:selection="data">
  11. <v-img :src="data.item.raw.logo" left :width="16" class="mr-2"/>
  12. <span>{{ data.item.title }}</span>
  13. </template>
  14. <template v-slot:item="{ props, item }">
  15. <v-list-item v-bind="props">
  16. <template v-slot:prepend>
  17. <v-img :src="item.raw.logo" :width="16" class="mr-2"/>
  18. </template>
  19. </v-list-item>
  20. </template>
  21. </v-select>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref, watch } from 'vue'
  25. import { useI18n } from 'vue-i18n'
  26. const items = [
  27. { value: 'fr', title: 'FR', logo: '/images/logos/french_flag.svg' },
  28. { value: 'en', title: 'EN', logo: '/images/logos/us-uk_flag.svg' },
  29. ]
  30. const { setLocale } = useI18n()
  31. const locale = ref('fr')
  32. watch(locale, () => {
  33. setLocale(locale.value)
  34. });
  35. </script>
  36. <style scoped lang="scss">
  37. :deep(.v-field__input) {
  38. padding: 0;
  39. }
  40. :deep(.v-select__menu-icon) {
  41. font-size: 15px;
  42. margin-top: 1px;
  43. }
  44. :deep(.v-list) {
  45. width: 72px;
  46. }
  47. :deep(.v-list-item) {
  48. padding: 24px;
  49. }
  50. :deep(.v-list-item__content) {
  51. display: flex;
  52. flex-direction: row;
  53. .v-avatar {
  54. width: 18px;
  55. height: 18px;
  56. }
  57. }
  58. </style>