提交 2482140d 编写于 作者: A afc163 提交者: Benjy Cui

Change context locale name

上级 193eb144
......@@ -6,13 +6,13 @@ import GregorianCalendar from 'gregorian-calendar';
export default {
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
getLocale() {
let locale = defaultLocale;
if (this.context.locale && this.context.locale.DatePicker) {
locale = this.context.locale.DatePicker;
if (this.context.antLocale && this.context.antLocale.DatePicker) {
locale = this.context.antLocale.DatePicker;
}
// 统一合并为完整的 Locale
const result = objectAssign({}, locale, this.props.locale);
......
......@@ -7,7 +7,8 @@
---
````jsx
import { LocaleProvider, Pagination, DatePicker, TimePicker, Popconfirm, Table, Modal, Button, Select } from 'antd';
import { LocaleProvider, Pagination, DatePicker, TimePicker,
Popconfirm, Table, Modal, Button, Select } from 'antd';
import enUS from 'antd/lib/locale-provider/en_US';
const Option = Select.Option;
......@@ -68,7 +69,7 @@ const App = React.createClass({
<div>
<LocaleProvider locale={this.state.locale}><Page /></LocaleProvider>
<div>
<Select defaultValue={enUS} onChange={this.changeLocale}>
<Select defaultValue={enUS} onChange={this.changeLocale} dropdownMatchSelectWidth={false}>
<Option value={enUS}>English</Option>
<Option value={null}>中文</Option>
</Select>
......
......@@ -3,16 +3,16 @@ import React from 'react';
export default class LocaleProvider extends React.Component {
getChildContext() {
return {
locale: this.props.locale,
antLocale: this.props.locale,
};
}
render() {
return React.cloneElement(this.props.children);
return React.Children.only(this.props.children);
}
}
LocaleProvider.childContextTypes = {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
};
LocaleProvider.propTypes = {
......
......@@ -23,7 +23,7 @@ let AntModal = React.createClass({
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
handleCancel(e) {
......@@ -56,9 +56,9 @@ let AntModal = React.createClass({
let props = this.props;
let { okText, cancelText } = props;
if (this.context.locale && this.context.locale.Modal) {
okText = okText || this.context.locale.Modal.okText;
cancelText = cancelText || this.context.locale.Modal.cancelText;
if (this.context.antLocale && this.context.antLocale.Modal) {
okText = okText || this.context.antLocale.Modal.okText;
cancelText = cancelText || this.context.antLocale.Modal.cancelText;
}
let defaultFooter = [
......
......@@ -17,8 +17,8 @@ class AntPagination extends React.Component {
let selectComponentClass = Select;
let locale;
if (this.context.locale && this.context.locale.Pagination) {
locale = this.context.locale.Pagination;
if (this.context.antLocale && this.context.antLocale.Pagination) {
locale = this.context.antLocale.Pagination;
} else {
locale = this.props.locale;
}
......@@ -45,7 +45,7 @@ AntPagination.defaultProps = {
};
AntPagination.contextTypes = {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
};
export default AntPagination;
......@@ -38,7 +38,7 @@ export default React.createClass({
};
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
componentWillReceiveProps(nextProps) {
if ('visible' in nextProps) {
......@@ -65,9 +65,9 @@ export default React.createClass({
render() {
const { title, placement, overlayStyle, trigger, ...restProps } = this.props;
let { okText, cancelText } = this.props;
if (this.context.locale && this.context.locale.Popconfirm) {
okText = okText || this.context.locale.Popconfirm.okText;
cancelText = cancelText || this.context.locale.Popconfirm.cancelText;
if (this.context.antLocale && this.context.antLocale.Popconfirm) {
okText = okText || this.context.antLocale.Popconfirm.okText;
cancelText = cancelText || this.context.antLocale.Popconfirm.cancelText;
}
const overlay = (
<div>
......
......@@ -75,7 +75,7 @@ let AntTable = React.createClass({
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
getDefaultSelection() {
......@@ -89,8 +89,8 @@ let AntTable = React.createClass({
getLocale() {
let locale = {};
if (this.context.locale && this.context.locale.Table) {
locale = this.context.locale.Table;
if (this.context.antLocale && this.context.antLocale.Table) {
locale = this.context.antLocale.Table;
}
return objectAssign({}, defaultLocale, locale, this.props.locale);
},
......
......@@ -28,7 +28,7 @@ const AntTimePicker = React.createClass({
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
getFormatter() {
......@@ -73,8 +73,8 @@ const AntTimePicker = React.createClass({
getLocale() {
let locale = defaultLocale;
if (this.context.locale && this.context.locale.TimePicker) {
locale = this.context.locale.TimePicker;
if (this.context.antLocale && this.context.antLocale.TimePicker) {
locale = this.context.antLocale.TimePicker;
}
// 统一合并为完整的 Locale
return objectAssign({}, locale, this.props.locale);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册