ant-design/components/locale-provider/index.tsx

55 lines
1.1 KiB
TypeScript
Raw Normal View History

2016-09-21 11:54:53 +08:00
import React from 'react';
import PropTypes from 'prop-types';
2017-07-31 01:50:46 +08:00
import { ModalLocale, changeConfirmLocale } from '../modal/locale';
2016-03-03 16:28:02 +08:00
2016-08-02 16:10:26 +08:00
export interface LocaleProviderProps {
locale: {
Pagination?: Object,
DatePicker?: Object,
TimePicker?: Object,
Calendar?: Object,
Table?: Object,
2017-07-31 01:50:46 +08:00
Modal?: ModalLocale,
2016-08-02 16:10:26 +08:00
Popconfirm?: Object,
Transfer?: Object,
Select?: Object,
};
children?: React.ReactElement<any>;
2016-08-02 16:10:26 +08:00
}
export default class LocaleProvider extends React.Component<LocaleProviderProps, any> {
static propTypes = {
locale: PropTypes.object,
2016-07-13 11:14:24 +08:00
};
static childContextTypes = {
antLocale: PropTypes.object,
2016-07-13 11:14:24 +08:00
};
2016-03-03 16:28:02 +08:00
getChildContext() {
return {
antLocale: {
...this.props.locale,
exist: true,
},
2016-03-03 16:28:02 +08:00
};
}
componentWillMount() {
this.componentDidUpdate();
}
componentDidUpdate() {
const { locale } = this.props;
changeConfirmLocale(locale && locale.Modal);
}
componentWillUnMount() {
changeConfirmLocale();
}
2016-03-03 16:28:02 +08:00
render() {
2016-03-05 16:39:27 +08:00
return React.Children.only(this.props.children);
2016-03-03 16:28:02 +08:00
}
}