import React, { useState } from "react"; import { Button, Dropdown, Flag } from "components"; import { useLocaleState } from "context"; import { changeLocale, getFlagCodeForLocale, getLocale, intl } from "locale"; export interface LocalPickerProps { /** * On click handler */ onChange?: any; } export const LocalePicker: React.FC = ({ onChange, ...rest }) => { const { locale, setLocale } = useLocaleState(); // const [locale, setLocale] = useState(getLocale()); const [localeShown, setLocaleShown] = useState(false); const handleOnChange = (e: any) => { changeLocale(e.currentTarget.rel); setLocale(e.currentTarget.rel); setLocaleShown(false); onChange && onChange(locale); }; const options = [ ["us", "en-US"], ["de", "de-DE"], ["ir", "fa-IR"], ]; return (
{options.map((item) => { return ( } onClick={handleOnChange}> {intl.formatMessage({ id: `locale-${item[1]}`, defaultMessage: item[1], })} ); })}
); };