You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
2.6 KiB

import React from 'react'
import {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
} from '@/components/ui/dropdown-menu'
import { Button } from '@/components/ui/button'
import { Ic } from '@/icons'
import { useTranslation, SupportedLanguage } from '@/i18n'
export default function LanguageSwitcher() {
const { language, setLanguage, languages, t, currentLanguageInfo } = useTranslation()
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="outline"
size="sm"
className="h-9 px-2.5 sm:px-3 rounded-xl border-border/70 bg-card/40 hover:bg-card text-xs font-semibold gap-2 shadow-xs transition-all"
title={t('topbar.language')}
>
<span className="text-sm leading-none">{currentLanguageInfo.flag}</span>
<span className="hidden sm:inline-block text-[12px] text-foreground">
{currentLanguageInfo.nativeName}
</span>
<Ic name="chevDown" className="size-3 text-muted-foreground transition-transform opacity-70" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-44 rounded-2xl p-1.5 shadow-xl border-border/70">
<DropdownMenuLabel className="text-[11px] font-bold text-muted-foreground px-2 py-1">
{t('topbar.selectLanguage')}
</DropdownMenuLabel>
<DropdownMenuSeparator />
{languages.map((item) => {
const isSelected = item.code === language
return (
<DropdownMenuItem
key={item.code}
onSelect={() => setLanguage(item.code as SupportedLanguage)}
onClick={() => setLanguage(item.code as SupportedLanguage)}
className={`flex items-center justify-between px-2.5 py-2 rounded-xl text-xs font-medium cursor-pointer transition-colors ${
isSelected
? 'bg-primary/15 text-primary font-bold shadow-2xs'
: 'text-foreground hover:bg-muted/50'
}`}
>
<div className="flex items-center gap-2">
<span className="text-base leading-none">{item.flag}</span>
<span>{item.nativeName}</span>
<span className="text-[10px] text-muted-foreground uppercase font-mono">
({item.code})
</span>
</div>
{isSelected && <Ic name="check" className="size-3.5 text-primary" />}
</DropdownMenuItem>
)
})}
</DropdownMenuContent>
</DropdownMenu>
)
}