import React , { PureComponent , createContext } from 'react' ; import type { Context } from 'react' ; import type { ConfigProviderProps , Locale } from './PropsType' ; import setTheme from './setTheme' ; import setPrimaryColor from './setPrimaryColor' ; const defaultConfig = { locale : ( { } as unknown ) as Locale , theme : 'light' , primaryColor : '#00bc70' , } ; export const LocaleContext = createContext ( defaultConfig . locale ) ; export const ConfigContext = createContext ( defaultConfig ) ; let runTimeLocale ; const changeRunTimeLocale = ( locale ) => { runTimeLocale = locale ; } ; export const getRunTimeLocale = ( ) => runTimeLocale ; export default class ConfigProvider extends PureComponent < ConfigProviderProps , { } > { static defaultProps = defaultConfig ; componentDidMount ( ) { this . update ( ) ; } componentDidUpdate ( ) { this . update ( ) ; } update ( ) { const { locale , theme , primaryColor } = this . props ; changeRunTimeLocale ( locale ) ; setTheme ( theme ) ; setPrimaryColor ( primaryColor ) ; } render ( ) { const { locale , theme , primaryColor , children } = this . props ; return ( < ConfigContext . Provider value = { { locale , theme , primaryColor } } > { React . Children . only ( children ) } < /ConfigContext.Provider>); } }