LanguageSelector.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. const items = [
  25. { value: 'fr', title: 'FR', logo: '/images/logos/french_flag.svg' },
  26. { value: 'en', title: 'EN', logo: '/images/logos/us-uk_flag.svg' },
  27. ]
  28. const { setLocale } = useI18n()
  29. const locale = ref('fr')
  30. watch(locale, () => {
  31. setLocale(locale.value)
  32. });
  33. </script>
  34. <style scoped lang="scss">
  35. :deep(.v-field__input) {
  36. padding: 0;
  37. }
  38. :deep(.v-select__menu-icon) {
  39. font-size: 15px;
  40. margin-top: 1px;
  41. }
  42. :deep(.v-list) {
  43. width: 72px;
  44. }
  45. :deep(.v-list-item) {
  46. padding: 24px;
  47. }
  48. :deep(.v-list-item__content) {
  49. display: flex;
  50. flex-direction: row;
  51. .v-avatar {
  52. width: 18px;
  53. height: 18px;
  54. }
  55. }
  56. </style>