revite/src/components/common/LocaleSelector.tsx

31 lines
908 B
TypeScript
Raw Normal View History

2021-12-11 06:56:33 -05:00
import { useApplicationState } from "../../mobx/State";
2021-07-05 06:23:23 -04:00
import { Language, Languages } from "../../context/Locale";
import ComboBox from "../ui/ComboBox";
2021-12-11 06:56:33 -05:00
/**
* Component providing a language selector combobox.
* Note: this is not an observer but this is fine as we are just using a combobox.
*/
export default function LocaleSelector() {
const locale = useApplicationState().locale;
2021-07-05 06:25:20 -04:00
return (
<ComboBox
2021-12-11 06:56:33 -05:00
value={locale.getLanguage()}
2021-07-05 06:25:20 -04:00
onChange={(e) =>
2021-12-11 06:56:33 -05:00
locale.setLanguage(e.currentTarget.value as Language)
2021-07-05 06:25:20 -04:00
}>
{Object.keys(Languages).map((x) => {
const l = Languages[x as keyof typeof Languages];
return (
2021-08-05 09:47:00 -04:00
<option value={x} key={x}>
2021-07-05 06:25:20 -04:00
{l.emoji} {l.display}
</option>
);
})}
</ComboBox>
);
}