Files
learn-languages/src/components/LanguageSettings.tsx
goddonebianu 572534a009
All checks were successful
continuous-integration/drone/push Build is passing
clean code
2025-12-11 17:14:37 +08:00

47 lines
1.6 KiB
TypeScript

"use client";
import IMAGES from "@/config/images";
import IconClick from "./IconClick";
import { useState } from "react";
import GhostButton from "./buttons/GhostButton";
export default function LanguageSettings() {
const [showLanguageMenu, setShowLanguageMenu] = useState(false);
const handleLanguageClick = () => {
setShowLanguageMenu((prev) => !prev);
};
const setLocale = async (locale: string) => {
document.cookie = `locale=${locale}`;
window.location.reload();
};
return (
<>
<IconClick
src={IMAGES.language_white}
alt="language"
disableOnHoverBgChange={true}
onClick={handleLanguageClick}
></IconClick>
<div className="relative">
{showLanguageMenu && (
<div>
<div className="absolute top-10 right-0 rounded-md shadow-md flex flex-col gap-2">
<GhostButton
className="w-full"
onClick={() => setLocale("en-US")}
>
English
</GhostButton>
<GhostButton
className="w-full"
onClick={() => setLocale("zh-CN")}
>
</GhostButton>
</div>
</div>
)}
</div></>
);
}