update UI
This commit is contained in:
1 parent
0c6f1c0ffc
commit
0c5939ed7a
7 files changed
+218
-61
No files matched your search
@@ -136,7 +136,7 @@ const submitFeedback = async () => {
|
||||
<div class="dialog-body space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field block">{{ t('feedback.labels.type') }}</label>
|
||||
<div class="segment-control segment-control--chips segment-control--md" role="radiogroup" :aria-label="t('feedback.labels.type')">
|
||||
<div class="segment-control segment-control--cols-3 segment-control--md" role="radiogroup" :aria-label="t('feedback.labels.type')">
|
||||
<button
|
||||
v-for="item in typeOptions"
|
||||
:key="item"
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Check, Languages } from 'lucide-vue-next';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
floating?: boolean;
|
||||
/** header:登录顶栏;sidebar:Chat 侧栏底栏图标行 */
|
||||
variant?: 'header' | 'sidebar';
|
||||
/** sidebar 折叠栏用 md 图标 */
|
||||
iconSize?: 'sm' | 'md';
|
||||
}>(),
|
||||
{
|
||||
floating: false,
|
||||
variant: 'header',
|
||||
iconSize: 'sm',
|
||||
},
|
||||
);
|
||||
|
||||
const { locale, t } = useI18n();
|
||||
const open = ref(false);
|
||||
const rootRef = ref<HTMLElement | null>(null);
|
||||
|
||||
/** 语言菜单文案固定,不随当前 locale 翻译(与产品约定一致) */
|
||||
const LOCALE_PICKER_OPTIONS = [
|
||||
{ value: 'zh-CN', label: '简体中文' },
|
||||
{ value: 'zh-TW', label: '繁體中文' },
|
||||
{ value: 'en', label: 'English' },
|
||||
{ value: 'th', label: 'ไทย' },
|
||||
] as const;
|
||||
|
||||
const buttonClass = computed(() => {
|
||||
if (props.variant === 'sidebar') {
|
||||
return [
|
||||
'flex items-center justify-center transition-colors hover:text-secondary',
|
||||
open.value ? 'text-brand-600' : 'text-muted',
|
||||
];
|
||||
}
|
||||
if (props.floating) return 'header-locale-btn header-locale-btn--floating';
|
||||
return 'header-locale-btn';
|
||||
});
|
||||
|
||||
const iconClass = computed(() => {
|
||||
if (props.variant === 'header') return 'h-4 w-4 md:h-5 md:w-5';
|
||||
return props.iconSize === 'md' ? 'h-5 w-5' : 'h-4 w-4';
|
||||
});
|
||||
|
||||
const menuClass = computed(() =>
|
||||
props.variant === 'sidebar'
|
||||
? 'header-locale-menu header-locale-menu--sidebar'
|
||||
: 'header-locale-menu',
|
||||
);
|
||||
|
||||
const selectLocale = (code: string) => {
|
||||
locale.value = code;
|
||||
open.value = false;
|
||||
};
|
||||
|
||||
const onDocumentClick = (event: MouseEvent) => {
|
||||
if (!rootRef.value?.contains(event.target as Node)) {
|
||||
open.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(open, (isOpen) => {
|
||||
if (isOpen) {
|
||||
document.addEventListener('click', onDocumentClick);
|
||||
return;
|
||||
}
|
||||
document.removeEventListener('click', onDocumentClick);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', onDocumentClick);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="rootRef" class="relative shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
:class="buttonClass"
|
||||
:title="t('workspace.languageLabel')"
|
||||
:aria-label="t('workspace.languageLabel')"
|
||||
:aria-expanded="open"
|
||||
aria-haspopup="listbox"
|
||||
@click.stop="open = !open"
|
||||
>
|
||||
<Languages :class="iconClass" />
|
||||
</button>
|
||||
|
||||
<div
|
||||
v-if="open"
|
||||
:class="menuClass"
|
||||
role="listbox"
|
||||
:aria-label="t('workspace.languageLabel')"
|
||||
@click.stop
|
||||
>
|
||||
<button
|
||||
v-for="item in LOCALE_PICKER_OPTIONS"
|
||||
:key="item.value"
|
||||
type="button"
|
||||
role="option"
|
||||
:aria-selected="locale === item.value"
|
||||
class="header-locale-menu__item"
|
||||
:class="{ 'header-locale-menu__item--active': locale === item.value }"
|
||||
@click="selectLocale(item.value)"
|
||||
>
|
||||
<span>{{ item.label }}</span>
|
||||
<Check v-if="locale === item.value" class="h-4 w-4 shrink-0 text-brand-600" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user