Merge pull request #4179 from ethereum/lang-dropdown-hometab
create lang selector componente2e_for_clickable_fn
commit
1dc3078e97
@ -0,0 +1,45 @@ |
|||||||
|
import React, { useEffect, useState } from 'react' |
||||||
|
import { Dropdown, DropdownButton } from 'react-bootstrap' |
||||||
|
import DropdownItem from 'react-bootstrap/DropdownItem' |
||||||
|
import { localeLang } from './types/carouselTypes' |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function LanguageOptions({ plugin }: { plugin: any }) { |
||||||
|
const [langOptions, setLangOptions] = useState<string>() |
||||||
|
|
||||||
|
const changeLanguage = async (lang: string) => { |
||||||
|
await plugin.call('locale', 'switchLocale', lang) |
||||||
|
} |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
plugin.call('locale', 'currentLocale').then(opt => { |
||||||
|
setLangOptions(opt.code.toUpperCase()) |
||||||
|
}) |
||||||
|
}, [langOptions]) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
plugin.on('locale', 'localeChanged', (lang: localeLang) => { |
||||||
|
setLangOptions(lang.code.toUpperCase()) |
||||||
|
}) |
||||||
|
}, [langOptions]) |
||||||
|
|
||||||
|
return ( |
||||||
|
<> |
||||||
|
<div className="d-flex align-items-center justify-content-end mr-2"> |
||||||
|
<DropdownButton title={langOptions} id="langdropdown" size="sm"> |
||||||
|
{['EN', 'ES', 'FR', 'ZH'].map(lang => ( |
||||||
|
<DropdownItem as={'span'} onClick={() => |
||||||
|
{ |
||||||
|
changeLanguage(lang.toLowerCase()) |
||||||
|
setLangOptions(lang) |
||||||
|
}} |
||||||
|
> |
||||||
|
{lang} |
||||||
|
</DropdownItem> |
||||||
|
))} |
||||||
|
</DropdownButton> |
||||||
|
</div> |
||||||
|
</> |
||||||
|
) |
||||||
|
} |
Loading…
Reference in new issue