2023-01-04 18:56:10 +09:00
|
|
|
<script setup lang="ts">
|
|
|
|
import Fuse from 'fuse.js'
|
|
|
|
|
|
|
|
let { modelValue } = $defineModel<{
|
2023-01-04 19:21:18 +09:00
|
|
|
modelValue: string
|
2023-01-04 18:56:10 +09:00
|
|
|
}>()
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
const languageKeyword = $ref('')
|
|
|
|
|
2023-01-30 20:09:04 +09:00
|
|
|
const fuse = new Fuse(languagesNameList, {
|
2023-01-04 18:56:10 +09:00
|
|
|
keys: ['code', 'nativeName', 'name'],
|
|
|
|
shouldSort: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
const languages = $computed(() =>
|
|
|
|
languageKeyword.trim()
|
|
|
|
? fuse.search(languageKeyword).map(r => r.item)
|
2023-01-30 20:09:04 +09:00
|
|
|
: [...languagesNameList].sort(({ code: a }, { code: b }) => {
|
2023-01-04 19:21:18 +09:00
|
|
|
return a === modelValue ? -1 : b === modelValue ? 1 : a.localeCompare(b)
|
2023-01-04 18:56:10 +09:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
2023-01-04 19:21:18 +09:00
|
|
|
function chooseLanguage(language: string) {
|
2023-01-04 18:56:10 +09:00
|
|
|
modelValue = language
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-30 20:20:22 +09:00
|
|
|
<div relative of-x-hidden>
|
|
|
|
<div p2>
|
|
|
|
<input
|
|
|
|
v-model="languageKeyword"
|
|
|
|
:placeholder="t('language.search')"
|
|
|
|
p2 border-rounded w-full bg-transparent
|
|
|
|
outline-none border="~ base"
|
|
|
|
>
|
|
|
|
</div>
|
2023-01-04 18:56:10 +09:00
|
|
|
<div max-h-40vh overflow-auto>
|
|
|
|
<CommonDropdownItem
|
|
|
|
v-for="{ code, nativeName, name } in languages"
|
|
|
|
:key="code"
|
2023-01-04 19:21:18 +09:00
|
|
|
:text="nativeName"
|
|
|
|
:description="name"
|
|
|
|
:checked="code === modelValue"
|
2023-01-04 18:56:10 +09:00
|
|
|
@click="chooseLanguage(code)"
|
2023-01-04 19:21:18 +09:00
|
|
|
/>
|
2023-01-04 18:56:10 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|