mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-01-23 05:18:12 -05:00
Add locale picker to app header
This commit is contained in:
parent
0244187c29
commit
cb3f0ec9b4
@ -3,6 +3,7 @@ import {
|
|||||||
Box,
|
Box,
|
||||||
Menu,
|
Menu,
|
||||||
MenuButton,
|
MenuButton,
|
||||||
|
MenuButtonProps,
|
||||||
MenuList,
|
MenuList,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
@ -16,29 +17,30 @@ import {
|
|||||||
} from "locale";
|
} from "locale";
|
||||||
|
|
||||||
interface LocalPickerProps {
|
interface LocalPickerProps {
|
||||||
/**
|
|
||||||
* On change handler
|
|
||||||
*/
|
|
||||||
onChange?: any;
|
onChange?: any;
|
||||||
/**
|
|
||||||
* Class
|
|
||||||
*/
|
|
||||||
className?: string;
|
className?: string;
|
||||||
|
background?: "normal" | "transparent";
|
||||||
}
|
}
|
||||||
|
|
||||||
function LocalePicker({ onChange, className }: LocalPickerProps) {
|
function LocalePicker({ onChange, className, background }: LocalPickerProps) {
|
||||||
const { locale, setLocale } = useLocaleState();
|
const { locale, setLocale } = useLocaleState();
|
||||||
|
|
||||||
|
const additionalProps: Partial<MenuButtonProps> = {};
|
||||||
|
if (background === "transparent") {
|
||||||
|
additionalProps["backgroundColor"] = "transparent";
|
||||||
|
}
|
||||||
|
|
||||||
const changeTo = (lang: string) => {
|
const changeTo = (lang: string) => {
|
||||||
changeLocale(lang);
|
changeLocale(lang);
|
||||||
setLocale(lang);
|
setLocale(lang);
|
||||||
onChange && onChange(locale);
|
onChange && onChange(locale);
|
||||||
|
location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className={className}>
|
<Box className={className}>
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuButton as={Button}>
|
<MenuButton as={Button} {...additionalProps}>
|
||||||
<Flag countryCode={getFlagCodeForLocale(locale)} />
|
<Flag countryCode={getFlagCodeForLocale(locale)} />
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
useColorModeValue,
|
useColorModeValue,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { ThemeSwitcher } from "components";
|
import { LocalePicker, ThemeSwitcher } from "components";
|
||||||
import { useAuthState } from "context";
|
import { useAuthState } from "context";
|
||||||
import { useUser } from "hooks";
|
import { useUser } from "hooks";
|
||||||
import { intl } from "locale";
|
import { intl } from "locale";
|
||||||
@ -67,6 +67,7 @@ function NavigationHeader({
|
|||||||
</HStack>
|
</HStack>
|
||||||
<HStack>
|
<HStack>
|
||||||
<ThemeSwitcher background="transparent" />
|
<ThemeSwitcher background="transparent" />
|
||||||
|
<LocalePicker className="text-right" background="transparent" />
|
||||||
<Box pl={2}>
|
<Box pl={2}>
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
|
Loading…
Reference in New Issue
Block a user