Refactor site hero and localized branding UI
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Languages } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -24,9 +24,16 @@ export function LocaleToggle({ locale, className, showLabel = false }: LocaleTog
|
||||
const locales: AppLocale[] = ["de", "en", "ar"];
|
||||
const currentPath = stripLocalePrefix(pathname);
|
||||
const currentLocale = (["de", "en", "ar"].includes(locale) ? locale : "de") as AppLocale;
|
||||
const availableLocales = locales.filter((targetLocale) => targetLocale !== currentLocale);
|
||||
const contentFontClassName = currentLocale === "ar" ? "font-arabic" : "font-latin";
|
||||
const localeFlags: Record<AppLocale, { src: string; alt: string }> = {
|
||||
de: { src: "/flags/de.svg", alt: "German" },
|
||||
en: { src: "/flags/us.svg", alt: "English" },
|
||||
ar: { src: "/flags/sy.svg", alt: "Arabic" },
|
||||
};
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -34,26 +41,41 @@ export function LocaleToggle({ locale, className, showLabel = false }: LocaleTog
|
||||
size={showLabel ? "sm" : "icon"}
|
||||
aria-label={`Locale: ${currentLocale.toUpperCase()}`}
|
||||
className={cn(
|
||||
"rounded-pill border border-transparent text-muted-foreground hover:border-border/70 hover:bg-background/80 hover:text-foreground",
|
||||
"group cursor-pointer rounded-pill border border-transparent text-muted-foreground hover:border-border/70 hover:bg-background/80 hover:text-foreground",
|
||||
showLabel ? "gap-2 px-3" : undefined,
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<Languages className="h-4 w-4" />
|
||||
{showLabel ? <span className="text-xs font-semibold uppercase tracking-[0.22em]">{currentLocale}</span> : null}
|
||||
<Image
|
||||
src={localeFlags[currentLocale].src}
|
||||
alt={localeFlags[currentLocale].alt}
|
||||
width={18}
|
||||
height={18}
|
||||
className="h-[18px] w-[18px] rounded-full object-cover transition-transform duration-300 ease-out group-hover:scale-110"
|
||||
/>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="min-w-[8rem]">
|
||||
{locales.map((targetLocale) => (
|
||||
<DropdownMenuItem key={targetLocale} asChild>
|
||||
<DropdownMenuContent align="end" className={cn("w-auto min-w-0", contentFontClassName)}>
|
||||
{availableLocales.map((targetLocale) => (
|
||||
<DropdownMenuItem
|
||||
key={targetLocale}
|
||||
asChild
|
||||
className={cn(
|
||||
"cursor-pointer",
|
||||
targetLocale === "ar" ? "font-arabic" : "font-latin",
|
||||
)}
|
||||
>
|
||||
<a
|
||||
href={getLocalizedPath(targetLocale, currentPath)}
|
||||
className="flex items-center justify-between gap-4"
|
||||
className="group flex items-center justify-center"
|
||||
>
|
||||
<span>{targetLocale.toUpperCase()}</span>
|
||||
{targetLocale === currentLocale ? (
|
||||
<span className="text-xs text-muted-foreground">Active</span>
|
||||
) : null}
|
||||
<Image
|
||||
src={localeFlags[targetLocale].src}
|
||||
alt={localeFlags[targetLocale].alt}
|
||||
width={18}
|
||||
height={18}
|
||||
className="h-[18px] w-[18px] rounded-full object-cover transition-transform duration-300 ease-out group-hover:scale-110"
|
||||
/>
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user