This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
LanguageButton.tsx
94 lines (82 loc) · 2.36 KB
/
LanguageButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { useState } from 'react';
import IconButton from '@mui/material/IconButton';
import Menu from '@mui/material/Menu';
import Tooltip from '@mui/material/Tooltip';
import LanguageIcon from '@mui/icons-material/Language';
import { languages } from '../../../languages';
import { Language } from '../../../types';
import LanguageOption from './LanguageOption';
interface LanguageButtonProps {
handleLanguageChange: (arg0: Language) => void
language: Language
}
const LanguageButton = ({ handleLanguageChange, language }: LanguageButtonProps): JSX.Element => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = (languageCode: Language) => {
if (Object.values(Language).includes(languageCode)) {
handleLanguageChange(languageCode);
}
setAnchorEl(null);
};
return (
<>
<IconButton
color="inherit"
edge="end"
onClick={handleClick}
size="large"
sx={{ mr: 0 }}
>
<Tooltip title={languages['Change language'][language]}>
<LanguageIcon />
</Tooltip>
</IconButton>
<Menu
anchorEl={anchorEl}
onClose={handleClose}
open={open}
>
<LanguageOption
flag="US"
handleClose={handleClose}
language={language}
languageCode={Language.English}
languageText="English"
/>
<LanguageOption
flag="FI"
handleClose={handleClose}
language={language}
languageCode={Language.Finnish}
languageText="suomi"
/>
<LanguageOption
flag="IT"
handleClose={handleClose}
language={language}
languageCode={Language.Italian}
languageText="Italiano"
/>
<LanguageOption
flag="KR"
handleClose={handleClose}
language={language}
languageCode={Language.Korean}
languageText="한국어"
/>
<LanguageOption
flag="SE"
handleClose={handleClose}
language={language}
languageCode={Language.Swedish}
languageText="svenska"
/>
</Menu>
</>
);
};
export default LanguageButton;