refactor: enhance LanguageSwitcher component with tooltip for current locale
This commit is contained in:
@@ -1,14 +1,28 @@
|
|||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { AppContext } from "App";
|
import { AppContext } from "App";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { IconButton } from "@mui/material";
|
import { IconButton, Tooltip } from "@mui/material";
|
||||||
|
import Zoom from "@mui/material/Zoom";
|
||||||
|
|
||||||
// import { FormattedMessage } from "react-intl";
|
// import { FormattedMessage } from "react-intl";
|
||||||
import LanguageOutlinedIcon from "@mui/icons-material/LanguageOutlined";
|
import LanguageOutlinedIcon from "@mui/icons-material/LanguageOutlined";
|
||||||
|
|
||||||
const LanguageSwitcher = () => {
|
const LanguageSwitcher = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const appContext = useContext(AppContext);
|
const appContext = useContext(AppContext);
|
||||||
|
const currentLocale =
|
||||||
|
appContext && appContext.locale
|
||||||
|
? String(appContext.locale).toUpperCase()
|
||||||
|
: "EN";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Tooltip
|
||||||
|
title={currentLocale}
|
||||||
|
disableInteractive
|
||||||
|
slots={{
|
||||||
|
transition: Zoom,
|
||||||
|
}}>
|
||||||
|
<span>
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="Language Switcher"
|
aria-label="Language Switcher"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -27,6 +41,8 @@ const LanguageSwitcher = () => {
|
|||||||
}}>
|
}}>
|
||||||
{<LanguageOutlinedIcon />}
|
{<LanguageOutlinedIcon />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user