/
selectLocale.js
31 lines (27 loc) · 929 Bytes
/
selectLocale.js
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
import React from 'react';
import { LocaleConsumer } from 'fbt-easy-setup';
import Select from 'react-select';
import LocaleText from './localeText';
// NOTE: The fbt babel plugin (collectFBT) requires enums to be required (not imported) and using none relative paths (therefore the aliases in the webpack config)
// eslint-disable-next-line import/no-unresolved
const LocaleEnum = require('Locale$FbtEnum');
const LOCALE_OPTS = Object.keys(LocaleEnum).map(locale => ({
value: locale,
label: <LocaleText locale={locale} />,
}));
const SelectLocale = () => (
<LocaleConsumer>
{({ locale, setLocale }) => (
<Select
className="select"
value={{
value: locale,
label: <LocaleText locale={locale} />,
}}
options={LOCALE_OPTS}
onChange={selectedLocale => setLocale(selectedLocale.value)}
/>
)}
</LocaleConsumer>
);
export default SelectLocale;