LangSwitcher.vue
1,226 bytes
| 1 | <script setup lang="ts"> |
|---|---|
| 2 | import { useLangStore } from '@/stores/lang' |
| 3 | import { SUPPORTED_LOCALES, type AppLocale } from '@/i18n' |
| 4 | |
| 5 | const lang = useLangStore() |
| 6 | |
| 7 | function switchTo(code: AppLocale) { |
| 8 | lang.setLocale(code) |
| 9 | } |
| 10 | </script> |
| 11 | |
| 12 | <template> |
| 13 | <div class="sa-lang-switcher"> |
| 14 | <button |
| 15 | v-for="code in SUPPORTED_LOCALES" |
| 16 | :key="code" |
| 17 | type="button" |
| 18 | class="sa-lang-btn" |
| 19 | :class="{ 'sa-lang-btn-active': lang.currentLocale === code }" |
| 20 | @click="switchTo(code)" |
| 21 | > |
| 22 | {{ code.toUpperCase() }} |
| 23 | </button> |
| 24 | </div> |
| 25 | </template> |
| 26 | |
| 27 | <style scoped> |
| 28 | .sa-lang-switcher { |
| 29 | display: inline-flex; |
| 30 | align-items: center; |
| 31 | gap: 2px; |
| 32 | padding: 2px; |
| 33 | border-radius: 999px; |
| 34 | background: var(--sa-gray-100); |
| 35 | border: 1px solid var(--sa-gray-200); |
| 36 | margin-right: 12px; |
| 37 | } |
| 38 | |
| 39 | .sa-lang-btn { |
| 40 | border: 0; |
| 41 | background: transparent; |
| 42 | color: var(--sa-gray-500); |
| 43 | font-size: 0.75rem; |
| 44 | font-weight: 700; |
| 45 | letter-spacing: 0.04em; |
| 46 | padding: 4px 10px; |
| 47 | border-radius: 999px; |
| 48 | cursor: pointer; |
| 49 | transition: all 0.15s ease; |
| 50 | } |
| 51 | |
| 52 | .sa-lang-btn:hover { |
| 53 | color: var(--sa-gray-700); |
| 54 | } |
| 55 | |
| 56 | .sa-lang-btn-active { |
| 57 | background: #fff; |
| 58 | color: var(--sa-gray-900); |
| 59 | box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); |
| 60 | } |
| 61 | </style> |
| 62 | |