fix(landing): replace language cycle button with dropdown selector
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m49s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m49s
The landing page language switcher cycled to the next language on every click. It is now a dropdown listing all 13 languages; the cycling button variant is removed from the LanguageSwitcher component.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Globe } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -28,49 +27,27 @@ const languages: { value: Locale; label: string; flag: string }[] = [
|
||||
];
|
||||
|
||||
interface LanguageSwitcherProps {
|
||||
variant?: "select" | "button";
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function LanguageSwitcher({ variant = "select" }: LanguageSwitcherProps) {
|
||||
export function LanguageSwitcher({ className }: LanguageSwitcherProps) {
|
||||
const { locale, setLocale } = useI18n();
|
||||
|
||||
if (variant === "button") {
|
||||
const currentIndex = languages.findIndex((l) => l.value === locale);
|
||||
const nextIndex = (currentIndex + 1) % languages.length;
|
||||
const nextLang = languages[nextIndex];
|
||||
const currentLang = languages[currentIndex];
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setLocale(nextLang.value)}
|
||||
className="gap-1.5 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Globe className="h-4 w-4" />
|
||||
<span className="text-sm">{currentLang.flag}</span>
|
||||
<span className="text-xs font-medium uppercase">{currentLang.value}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
const current = languages.find((l) => l.value === locale) ?? languages[0];
|
||||
|
||||
return (
|
||||
<Select value={locale} onValueChange={(v) => setLocale(v as Locale)}>
|
||||
<SelectTrigger className="w-[150px] h-9">
|
||||
<SelectTrigger className={className} aria-label="Change language">
|
||||
<SelectValue>
|
||||
<span className="flex items-center gap-2">
|
||||
<Globe className="h-4 w-4" />
|
||||
{languages.find((l) => l.value === locale)?.flag}{" "}
|
||||
{languages.find((l) => l.value === locale)?.label}
|
||||
<span>{current.flag}</span>
|
||||
<span>{current.label}</span>
|
||||
</span>
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectContent align="start">
|
||||
{languages.map((lang) => (
|
||||
<SelectItem
|
||||
key={lang.value}
|
||||
value={lang.value}
|
||||
>
|
||||
<SelectItem key={lang.value} value={lang.value}>
|
||||
<span className="flex items-center gap-2">
|
||||
<span>{lang.flag}</span>
|
||||
<span>{lang.label}</span>
|
||||
|
||||
Reference in New Issue
Block a user