fumadocs-ui
Version:
The Radix UI version of Fumadocs UI
47 lines (44 loc) • 1.76 kB
JavaScript
'use client';
import { buttonVariants } from "../../components/ui/button.js";
import { i18n_exports } from "../../contexts/i18n.js";
import { Popover, PopoverContent, PopoverTrigger } from "../../components/ui/popover.js";
import { cn } from "@fumadocs/ui/cn";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/layouts/shared/language-toggle.tsx
function LanguageToggle(props) {
const context = (0, i18n_exports.useI18n)();
if (!context.locales) throw new Error("Missing `<I18nProvider />`");
return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(PopoverTrigger, {
"aria-label": context.text.chooseLanguage,
...props,
className: cn(buttonVariants({
color: "ghost",
className: "gap-1.5 p-1.5"
}), props.className),
children: props.children
}), /* @__PURE__ */ jsxs(PopoverContent, {
className: "flex flex-col overflow-x-hidden p-0",
children: [/* @__PURE__ */ jsx("p", {
className: "mb-1 p-2 text-xs font-medium text-fd-muted-foreground",
children: context.text.chooseLanguage
}), context.locales.map((item) => /* @__PURE__ */ jsx("button", {
type: "button",
className: cn("p-2 text-start text-sm", item.locale === context.locale ? "bg-fd-primary/10 font-medium text-fd-primary" : "hover:bg-fd-accent hover:text-fd-accent-foreground"),
onClick: () => {
context.onChange?.(item.locale);
},
children: item.name
}, item.locale))]
})] });
}
function LanguageToggleText(props) {
const context = (0, i18n_exports.useI18n)();
const text = context.locales?.find((item) => item.locale === context.locale)?.name;
return /* @__PURE__ */ jsx("span", {
...props,
children: text
});
}
//#endregion
export { LanguageToggle, LanguageToggleText };
//# sourceMappingURL=language-toggle.js.map