mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-14 08:09:13 +08:00
20d5502193
* chore(deps-dev): bump eslint-config-airbnb from 18.2.1 to 19.0.0 Bumps [eslint-config-airbnb](https://github.com/airbnb/javascript) from 18.2.1 to 19.0.0. - [Release notes](https://github.com/airbnb/javascript/releases) - [Commits](https://github.com/airbnb/javascript/compare/eslint-config-airbnb-v18.2.1...eslint-config-airbnb-v19.0.0) --- updated-dependencies: - dependency-name: eslint-config-airbnb dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * chore: code style * memoize-one * add comment * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * fix lint * improve useMemo deps Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 <afc163@gmail.com>
90 lines
2.5 KiB
TypeScript
90 lines
2.5 KiB
TypeScript
import * as React from 'react';
|
|
import memoizeOne from 'memoize-one';
|
|
import { ValidateMessages } from 'rc-field-form/lib/interface';
|
|
import devWarning from '../_util/devWarning';
|
|
|
|
import { ModalLocale, changeConfirmLocale } from '../modal/locale';
|
|
import { TransferLocale as TransferLocaleForEmpty } from '../empty';
|
|
import { PaginationLocale } from '../pagination/Pagination';
|
|
import { TableLocale } from '../table/interface';
|
|
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';
|
|
|
|
export interface Locale {
|
|
locale: string;
|
|
Pagination?: PaginationLocale;
|
|
DatePicker?: DatePickerLocale;
|
|
TimePicker?: Record<string, any>;
|
|
Calendar?: Record<string, any>;
|
|
Table?: TableLocale;
|
|
Modal?: ModalLocale;
|
|
Popconfirm?: PopconfirmLocale;
|
|
Transfer?: Partial<TransferLocale>;
|
|
Select?: Record<string, any>;
|
|
Upload?: UploadLocale;
|
|
Empty?: TransferLocaleForEmpty;
|
|
global?: Record<string, any>;
|
|
PageHeader?: { back: string };
|
|
Icon?: Record<string, any>;
|
|
Text?: Record<string, any>;
|
|
Form?: {
|
|
optional?: string;
|
|
defaultValidateMessages: ValidateMessages;
|
|
};
|
|
Image?: {
|
|
preview: string;
|
|
};
|
|
}
|
|
|
|
export interface LocaleProviderProps {
|
|
locale: Locale;
|
|
children?: React.ReactNode;
|
|
_ANT_MARK__?: string;
|
|
}
|
|
|
|
export default class LocaleProvider extends React.Component<LocaleProviderProps, any> {
|
|
static defaultProps = {
|
|
locale: {},
|
|
};
|
|
|
|
constructor(props: LocaleProviderProps) {
|
|
super(props);
|
|
changeConfirmLocale(props.locale && props.locale.Modal);
|
|
|
|
devWarning(
|
|
props._ANT_MARK__ === ANT_MARK,
|
|
'LocaleProvider',
|
|
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale',
|
|
);
|
|
}
|
|
|
|
componentDidMount() {
|
|
changeConfirmLocale(this.props.locale && this.props.locale.Modal);
|
|
}
|
|
|
|
componentDidUpdate(prevProps: LocaleProviderProps) {
|
|
const { locale } = this.props;
|
|
if (prevProps.locale !== locale) {
|
|
changeConfirmLocale(locale && locale.Modal);
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
changeConfirmLocale();
|
|
}
|
|
|
|
render() {
|
|
const { locale, children } = this.props;
|
|
const contextValue = memoizeOne(localeValue => ({
|
|
...localeValue,
|
|
exist: true,
|
|
}))(locale);
|
|
return <LocaleContext.Provider value={contextValue}>{children}</LocaleContext.Provider>;
|
|
}
|
|
}
|