11import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
23import { matchShape } from 'found' ;
34import { useIntl } from 'react-intl' ;
4- import { configShape } from '../util/shapes' ;
55import { useConfigContext } from '../configurations/ConfigContext' ;
66
7- const language = ( lang , highlight , match , intl ) => {
7+ const Language = ( { lang } , { match } ) => {
8+ const { language } = useConfigContext ( ) ;
9+ const intl = useIntl ( ) ;
10+ const highlight = lang === language ;
11+
812 const aria = highlight
913 ? intl . formatMessage (
1014 { id : 'search-current-suggestion' } ,
@@ -24,21 +28,18 @@ const language = (lang, highlight, match, intl) => {
2428 ) ;
2529} ;
2630
27- const LangSelect = ( { } , { match } ) => { // eslint-disable-line
28- const config = useConfigContext ( ) ;
29- const intl = useIntl ( ) ;
31+ Language . contextTypes = { match : matchShape . isRequired } ;
32+ Language . propTypes = { lang : PropTypes . string . isRequired } ;
33+
34+ const LanguageSelect = ( { } , { match } ) => { // eslint-disable-line
35+ const { availableLanguages } = useConfigContext ( ) ;
3036 return (
3137 < div key = "lang-select" id = "lang-select" >
32- { config . availableLanguages . map ( lang =>
33- language ( lang , lang === config . language , match , intl ) ,
34- ) }
38+ { availableLanguages . map ( lang => (
39+ < Language key = { lang } lang = { lang } />
40+ ) ) }
3541 </ div >
3642 ) ;
3743} ;
3844
39- LangSelect . contextTypes = {
40- config : configShape . isRequired ,
41- match : matchShape . isRequired ,
42- } ;
43-
44- export default LangSelect ;
45+ export default LanguageSelect ;
0 commit comments