diff --git a/components/locale-provider/LocaleReceiver.tsx b/components/locale-provider/LocaleReceiver.tsx index 7e65da17d3..6334a64561 100644 --- a/components/locale-provider/LocaleReceiver.tsx +++ b/components/locale-provider/LocaleReceiver.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import * as PropTypes from 'prop-types'; import defaultLocaleData from './default'; +import LocaleContext from './context'; export interface LocaleReceiverProps { componentName?: string; @@ -21,17 +21,13 @@ export default class LocaleReceiver extends React.Component componentName: 'global', }; - static contextTypes = { - antLocale: PropTypes.object, - }; - - context: LocaleReceiverContext; + static contextType = LocaleContext; getLocale() { const { componentName, defaultLocale } = this.props; const locale: object | Function = defaultLocale || (defaultLocaleData as LocaleInterface)[componentName || 'global']; - const { antLocale } = this.context; + const antLocale = this.context; const localeFromContext = componentName && antLocale ? antLocale[componentName] : {}; return { ...(typeof locale === 'function' ? locale() : locale), @@ -40,7 +36,7 @@ export default class LocaleReceiver extends React.Component } getLocaleCode() { - const { antLocale } = this.context; + const antLocale = this.context; const localeCode = antLocale && antLocale.locale; // Had use LocaleProvide but didn't set locale if (antLocale && antLocale.exist && !localeCode) { @@ -50,6 +46,6 @@ export default class LocaleReceiver extends React.Component } render() { - return this.props.children(this.getLocale(), this.getLocaleCode(), this.context.antLocale); + return this.props.children(this.getLocale(), this.getLocaleCode(), this.context); } } diff --git a/components/locale-provider/context.ts b/components/locale-provider/context.ts new file mode 100644 index 0000000000..68ade79b1f --- /dev/null +++ b/components/locale-provider/context.ts @@ -0,0 +1,6 @@ +import { createContext } from 'react'; +import { Locale } from '.'; + +const LocaleContext = createContext<(Partial & { exist?: boolean }) | undefined>(undefined); + +export default LocaleContext; diff --git a/components/locale-provider/index.tsx b/components/locale-provider/index.tsx index 267c32a31f..574596e388 100644 --- a/components/locale-provider/index.tsx +++ b/components/locale-provider/index.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import * as PropTypes from 'prop-types'; import warning from '../_util/warning'; import { ModalLocale, changeConfirmLocale } from '../modal/locale'; @@ -10,6 +9,7 @@ import { PopconfirmLocale } from '../popconfirm'; import { UploadLocale } from '../upload/interface'; import { TransferLocale } from '../transfer'; import { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker'; +import LocaleContext from './context'; export const ANT_MARK = 'internalMark'; @@ -43,10 +43,6 @@ export default class LocaleProvider extends React.Component{children} + ); } } diff --git a/tests/dekko/lib.test.js b/tests/dekko/lib.test.js index ae88be09b2..0841ffbae5 100644 --- a/tests/dekko/lib.test.js +++ b/tests/dekko/lib.test.js @@ -6,10 +6,7 @@ function getFileName(filePath) { return filePath.slice(filePath.lastIndexOf(path.sep) + 1); } -$('lib') - .isDirectory() - .hasFile('index.js') - .hasFile('index.d.ts'); +$('lib').isDirectory().hasFile('index.js').hasFile('index.d.ts'); $('lib/*') .filter( @@ -27,9 +24,7 @@ $('lib/*') .hasFile('index.d.ts') .hasDirectory('style'); -$('lib/*/style') - .hasFile('css.js') - .hasFile('index.js'); +$('lib/*/style').hasFile('css.js').hasFile('index.js'); // locale const filterLocaleFile = filePath => { @@ -40,7 +35,8 @@ const filterLocaleFile = filePath => { !fileName.endsWith('.map') && !fileName.endsWith('style') && !fileName.includes('-') && - !fileName.endsWith('LocaleReceiver.js') + !fileName.endsWith('LocaleReceiver.js') && + !fileName.endsWith('context.js') ); }; const localeFiles = $('lib/locale/*').filter(filterLocaleFile);