import * as React from 'react'; import styled from 'styled-components'; import { colors } from '../../config.json'; import { messages } from '../../shared/gettext'; import { AriaInputGroup } from './AriaGroup'; import { CustomScrollbarsRef } from './CustomScrollbars'; import { Container, Layout } from './Layout'; import { BackBarItem, NavigationBar, NavigationContainer, NavigationItems, NavigationScrollbars, TitleBarItem, } from './NavigationBar'; import Selector, { ISelectorItem } from './cell/Selector'; import SettingsHeader, { HeaderTitle } from './SettingsHeader'; interface IProps { preferredLocale: string; preferredLocalesList: Array<{ name: string; code: string }>; setPreferredLocale: (locale: string) => void; onClose: () => void; } interface IState { source: Array>; } const StyledContainer = styled(Container)({ backgroundColor: colors.darkBlue, }); const StyledNavigationScrollbars = styled(NavigationScrollbars)({ flex: 1, }); const StyledSelector = (styled(Selector)({ marginBottom: 0, }) as unknown) as new () => Selector; export default class SelectLanguage extends React.Component { private scrollView = React.createRef(); private selectedCellRef = React.createRef(); constructor(props: IProps) { super(props); this.state = { source: [ ...this.props.preferredLocalesList.map((item) => ({ label: item.name, value: item.code })), ], }; } public componentDidMount() { this.scrollToSelectedCell(); } public render() { return ( { // TRANSLATORS: Back button in navigation bar messages.pgettext('navigation-bar', 'Settings') } { // TRANSLATORS: Title label in navigation bar messages.pgettext('select-language-nav', 'Select language') } {messages.pgettext('select-language-nav', 'Select language')} ); } private scrollToSelectedCell() { const ref = this.selectedCellRef.current; const scrollView = this.scrollView.current; if (scrollView && ref) { if (ref instanceof HTMLElement) { scrollView.scrollToElement(ref, 'middle'); } } } }