2017-05-09 13:40:33 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-17 15:23:25 +08:00
|
|
|
|
|
|
|
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> {
|
2017-03-26 10:02:34 +08:00
|
|
|
const ComponentWithStatics = Component as any;
|
2017-03-17 15:23:25 +08:00
|
|
|
return class extends Component<P & ComponentProps, any> {
|
2017-03-26 10:02:34 +08:00
|
|
|
static propTypes = ComponentWithStatics.propTypes;
|
|
|
|
static defaultProps = ComponentWithStatics.defaultProps;
|
2017-03-17 15:23:25 +08:00
|
|
|
static contextTypes = {
|
2017-03-26 10:02:34 +08:00
|
|
|
...(ComponentWithStatics.context || {}),
|
2017-03-17 15:23:25 +08:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|