Fix locale not found content (#1604)

* Add notFoundContent to LocaleProvider, close #1488

* Fix TreeSelect notFoundContent style
This commit is contained in:
afc163 2016-05-08 16:05:36 +08:00
parent d4c1d230f5
commit 1864ab3175
6 changed files with 47 additions and 10 deletions

View File

@ -7,8 +7,9 @@ title: 所有组件
````jsx ````jsx
import { LocaleProvider, Pagination, DatePicker, TimePicker, Calendar, import { LocaleProvider, Pagination, DatePicker, TimePicker, Calendar,
Popconfirm, Table, Modal, Button, Select, Transfer } from 'antd'; Popconfirm, Table, Modal, Button, Select, Transfer, Radio } from 'antd';
import enUS from 'antd/lib/locale-provider/en_US'; import enUS from 'antd/lib/locale-provider/en_US';
import ruRU from 'antd/lib/locale-provider/ru_RU';
const Option = Select.Option; const Option = Select.Option;
const RangePicker = DatePicker.RangePicker; const RangePicker = DatePicker.RangePicker;
@ -55,6 +56,10 @@ const Page = React.createClass({
<Pagination defaultCurrent={1} total={50} showSizeChanger /> <Pagination defaultCurrent={1} total={50} showSizeChanger />
</div> </div>
<div className="example"> <div className="example">
<Select showSearch style={{ width: 200 }}>
<Option value="jack">jack</Option>
<Option value="lucy">lucy</Option>
</Select>
<DatePicker /> <DatePicker />
<TimePicker /> <TimePicker />
<RangePicker style={{ width: 200 }} /> <RangePicker style={{ width: 200 }} />
@ -95,18 +100,19 @@ const App = React.createClass({
locale: enUS, locale: enUS,
}; };
}, },
changeLocale(locale) { changeLocale(e) {
this.setState({ locale }); this.setState({ locale: e.target.value });
}, },
render() { render() {
return ( return (
<div> <div>
<div className="change-locale"> <div className="change-locale">
<span>Change locale of components: </span> <span style={{ marginRight: 16 }}>Change locale of components: </span>
<Select defaultValue={enUS} onChange={this.changeLocale} dropdownMatchSelectWidth={false}> <Radio.Group defaultValue={enUS} onChange={this.changeLocale}>
<Option value={enUS}>English</Option> <Radio.Button key="en" value={enUS}>English</Radio.Button>
<Option value={null}>中文</Option> <Radio.Button key="ru" value={ruRU}>русский язык</Radio.Button>
</Select> <Radio.Button key="cn" value={null}>中文</Radio.Button>
</Radio.Group>
</div> </div>
<LocaleProvider locale={this.state.locale}><Page /></LocaleProvider> <LocaleProvider locale={this.state.locale}><Page /></LocaleProvider>
</div> </div>

View File

@ -29,4 +29,7 @@ export default {
itemUnit: 'item', itemUnit: 'item',
itemsUnit: 'items', itemsUnit: 'items',
}, },
Select: {
notFoundContent: 'Not Found',
},
}; };

View File

@ -33,4 +33,7 @@ export default {
itemUnit: 'item', itemUnit: 'item',
itemsUnit: 'items', itemsUnit: 'items',
}, },
Select: {
notFoundContent: 'Not Found',
},
}; };

View File

@ -14,6 +14,10 @@ export default class Select extends React.Component {
showSearch: false, showSearch: false,
} }
static contextTypes = {
antLocale: React.PropTypes.object,
}
render() { render() {
let { let {
size, className, combobox, notFoundContent, prefixCls, showSearch, optionLabelProp, size, className, combobox, notFoundContent, prefixCls, showSearch, optionLabelProp,
@ -26,6 +30,11 @@ export default class Select extends React.Component {
[`${prefixCls}-show-search`]: showSearch, [`${prefixCls}-show-search`]: showSearch,
}); });
const { antLocale } = this.context;
if (antLocale && antLocale.Select) {
notFoundContent = notFoundContent || antLocale.Select.notFoundContent;
}
if (combobox) { if (combobox) {
notFoundContent = null; notFoundContent = null;
// children dom // children dom

View File

@ -13,6 +13,11 @@ export default class TreeSelect extends React.Component {
transitionName: 'slide-up', transitionName: 'slide-up',
choiceTransitionName: 'zoom', choiceTransitionName: 'zoom',
showSearch: false, showSearch: false,
dropdownClassName: 'ant-select-tree-dropdown',
}
static contextTypes = {
antLocale: React.PropTypes.object,
} }
render() { render() {
@ -27,6 +32,11 @@ export default class TreeSelect extends React.Component {
[className]: !!className, [className]: !!className,
}); });
const { antLocale } = this.context;
if (antLocale && antLocale.Select) {
notFoundContent = notFoundContent || antLocale.Select.notFoundContent;
}
if (combobox) { if (combobox) {
notFoundContent = null; notFoundContent = null;
} }

View File

@ -19,8 +19,7 @@
outline: 0; outline: 0;
&.filter-node { &.filter-node {
> a { > a {
color: @error-color!important; font-weight: bold !important;
font-weight: bold!important;
} }
} }
ul { ul {
@ -113,3 +112,10 @@
vertical-align: top; vertical-align: top;
} }
} }
.@{select-tree-prefix-cls}-dropdown .ant-select-dropdown-search + span {
padding: 7px 15px;
color: #ccc;
cursor: not-allowed;
display: block;
}