umami/components/settings/LanguageButton.js

31 lines
765 B
JavaScript
Raw Normal View History

import { languages } from 'lib/lang';
import useLocale from 'hooks/useLocale';
2020-09-21 06:31:53 +02:00
import MenuButton from 'components/common/MenuButton';
import Globe from 'assets/globe.svg';
2020-10-02 21:15:42 +02:00
import styles from './LanguageButton.module.css';
import { Icon } from 'react-basics';
2020-09-07 10:22:16 +02:00
2020-09-21 06:31:53 +02:00
export default function LanguageButton() {
const { locale, saveLocale } = useLocale();
const menuOptions = Object.keys(languages).map(key => ({ ...languages[key], value: key }));
2020-09-07 10:22:16 +02:00
function handleSelect(value) {
saveLocale(value);
2020-09-07 10:22:16 +02:00
}
return (
<MenuButton
options={menuOptions}
value={locale}
menuClassName={styles.menu}
2022-03-04 04:45:49 +01:00
buttonVariant="light"
onSelect={handleSelect}
2021-11-04 23:55:12 +01:00
hideLabel
>
<Icon>
<Globe />
</Icon>
</MenuButton>
2020-09-07 10:22:16 +02:00
);
}