-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (51 loc) · 1.31 KB
/
index.js
File metadata and controls
60 lines (51 loc) · 1.31 KB
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
import React from 'react';
import { useTranslation } from 'react-i18next';
import i18n from 'i18next';
import cn from 'classnames';
import SrOnly from '../SrOnly';
import { TRANSLATION_LANGUAGE_OPTIONS } from '../../config';
import styles from './LanguagePicker.module.scss';
const LanguagePicker = ({
value = 'fi',
onChange,
className: classNameProp,
}) => {
const { t } = useTranslation();
const selectOnChange = (e) => {
onChange(e.target.value, e);
};
const className = cn(classNameProp, styles.select);
const style = {
fontSize: '1em',
};
if (value === 'ptbr') {
style.fontSize = '0.65em';
}
if (i18n.dir(value) === 'rtl') {
style.backgroundPosition = 'left 6px center'
}
return (
/*eslint jsx-a11y/no-onchange: "off" */
<>
<SrOnly>
<label htmlFor="language-select">
{t('navigation:LanguagePickerSrLabel')}
</label>
</SrOnly>
<select
id="language-select"
value={value}
onChange={selectOnChange}
className={className}
style={style}
>
{TRANSLATION_LANGUAGE_OPTIONS.map(({ value: optionValue, label }) => (
<option value={optionValue} key={optionValue}>
{label}
</option>
))}
</select>
</>
);
};
export default LanguagePicker;