mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-22 22:48:29 +08:00
8f81594f91
* refactor: extract injectLocale and refactor Pagination, ref: #5103 * refactor: use injectLocale in Popconfirm, ref: #5103 * refactor: use injectLocale in TimePicker * refactor: use injectLocale in Transfer * refactor: use injectLocale in TreeSelect * refactor: remove useless code in AutoComplete * test: update snapshot
33 lines
828 B
TypeScript
33 lines
828 B
TypeScript
import React, { PropTypes } from 'react';
|
|
|
|
export interface ComponentProps {
|
|
locale?: any;
|
|
}
|
|
|
|
export interface ComponentContext {
|
|
antLocale?: { [key: string]: any };
|
|
}
|
|
|
|
export default (componentName: string, defaultLocale) => (
|
|
function<P>(Component: typeof React.Component): React.ComponentClass<P> {
|
|
return class extends Component<P & ComponentProps, any> {
|
|
static contextTypes = {
|
|
antLocale: PropTypes.object,
|
|
};
|
|
|
|
context: ComponentContext;
|
|
|
|
getLocale() {
|
|
const { antLocale } = this.context;
|
|
const localeFromContext = antLocale && antLocale[componentName];
|
|
const localeFromProps: any = this.props.locale || {};
|
|
return {
|
|
...defaultLocale,
|
|
...(localeFromContext || {}),
|
|
...localeFromProps,
|
|
};
|
|
}
|
|
};
|
|
}
|
|
);
|