2023-03-22 05:28:36 +01:00
|
|
|
import { Icon, Button, PopupTrigger, Popup, Text } from 'react-basics';
|
2023-01-28 06:53:13 +01:00
|
|
|
import classNames from 'classnames';
|
2021-06-30 03:41:34 +02:00
|
|
|
import { languages } from 'lib/lang';
|
2020-09-17 09:17:11 +02:00
|
|
|
import useLocale from 'hooks/useLocale';
|
2023-01-31 06:44:07 +01:00
|
|
|
import Icons from 'components/icons';
|
2020-10-02 21:15:42 +02:00
|
|
|
import styles from './LanguageButton.module.css';
|
2020-09-07 10:22:16 +02:00
|
|
|
|
2023-03-22 05:28:36 +01:00
|
|
|
export default function LanguageButton() {
|
2021-06-30 03:41:34 +02:00
|
|
|
const { locale, saveLocale } = useLocale();
|
2023-01-28 06:53:13 +01:00
|
|
|
const items = Object.keys(languages).map(key => ({ ...languages[key], value: key }));
|
2020-09-07 10:22:16 +02:00
|
|
|
|
|
|
|
function handleSelect(value) {
|
2021-06-30 03:41:34 +02:00
|
|
|
saveLocale(value);
|
2020-09-07 10:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-01-28 06:53:13 +01:00
|
|
|
<PopupTrigger>
|
2023-03-22 05:28:36 +01:00
|
|
|
<Button variant="quiet">
|
|
|
|
<Icon>
|
|
|
|
<Icons.Globe />
|
|
|
|
</Icon>
|
|
|
|
</Button>
|
|
|
|
<Popup position="bottom" alignment="end">
|
2023-01-28 06:53:13 +01:00
|
|
|
<div className={styles.menu}>
|
|
|
|
{items.map(({ value, label }) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={value}
|
|
|
|
className={classNames(styles.item, { [styles.selected]: value === locale })}
|
|
|
|
onClick={handleSelect.bind(null, value)}
|
|
|
|
>
|
|
|
|
<Text>{label}</Text>
|
|
|
|
{value === locale && (
|
|
|
|
<Icon className={styles.icon}>
|
|
|
|
<Icons.Check />
|
|
|
|
</Icon>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</Popup>
|
|
|
|
</PopupTrigger>
|
2020-09-07 10:22:16 +02:00
|
|
|
);
|
|
|
|
}
|