feat: Modal should support internationalization

This commit is contained in:
Benjy Cui 2015-11-24 11:01:36 +08:00
parent c14dcc7e40
commit fdd9ef7d18
4 changed files with 105 additions and 9 deletions

View File

@ -72,19 +72,22 @@ export default function (props) {
<span className="ant-confirm-title">{props.title}</span> <span className="ant-confirm-title">{props.title}</span>
<div className="ant-confirm-content">{props.content}</div> <div className="ant-confirm-content">{props.content}</div>
</div>; </div>;
let footer = <div className="ant-confirm-btns">
<Button type="ghost" size="large" onClick={onCancel}> </Button>
<Button type="primary" size="large" onClick={onOk}> </Button>
</div>;
let footer = null;
if (props.okCancel) { if (props.okCancel) {
footer = <div className="ant-confirm-btns"> footer = <div className="ant-confirm-btns">
<Button type="ghost" size="large" onClick={onCancel}> </Button> <Button type="ghost" size="large" onClick={onCancel}>
<Button type="primary" size="large" onClick={onOk}> </Button> {props.cancelText || '取消'}
</Button>
<Button type="primary" size="large" onClick={onOk}>
{props.okText || '确定'}
</Button>
</div>; </div>;
} else { } else {
footer = <div className="ant-confirm-btns"> footer = <div className="ant-confirm-btns">
<Button type="primary" size="large" onClick={onOk}>知道了</Button> <Button type="primary" size="large" onClick={onOk}>
{props.okText || '知道了'}
</Button>
</div>; </div>;
} }

View File

@ -0,0 +1,87 @@
# 国际化
- order: 6
设置 `okText``cancelText` 以自定义按钮文字。
---
````jsx
import { Modal, Button } from 'antd';
const LocalizedModal = React.createClass({
getInitialState() {
return { visible: false };
},
showModal() {
this.setState({
visible: true
});
},
handleOk() {
this.setState({
visible: false
});
},
handleCancel() {
this.setState({
visible: false
});
},
render() {
return <div>
<Button type="primary" onClick={this.showModal}>Show Modal</Button>
<Modal title="Modal" visible={this.state.visible}
onOk={this.handleOk} onCancel={this.handleCancel}
okText="OK" cancelText="Cancel">
<p>Bla bla ...</p>
<p>Bla bla ...</p>
<p>Bla bla ...</p>
</Modal>
</div>;
}
});
function confirm() {
Modal.confirm({
title: 'Confirm',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel'
});
}
function info() {
Modal.info({
title: 'Info',
content: 'Bla bla ...',
okText: 'OK'
});
}
function success() {
Modal.success({
title: 'Success',
content: 'Bla bla ...',
okText: 'OK'
});
}
function error() {
Modal.error({
title: 'Error',
content: 'Bla bla ...',
okText: 'OK'
});
}
ReactDOM.render(<div>
<LocalizedModal />
<br />
<Button onClick={confirm}>confirm</Button>
<Button onClick={info}>Info</Button>
<Button onClick={success}>Success</Button>
<Button onClick={error}>Error</Button>
</div>, document.getElementById('components-modal-demo-locale'));
````

View File

@ -15,6 +15,8 @@ let AntModal = React.createClass({
prefixCls: 'ant-modal', prefixCls: 'ant-modal',
onOk: noop, onOk: noop,
onCancel: noop, onCancel: noop,
okText: '确定',
cancelText: '取消',
width: 520, width: 520,
transitionName: 'zoom', transitionName: 'zoom',
maskAnimation: 'fade', maskAnimation: 'fade',
@ -56,14 +58,14 @@ let AntModal = React.createClass({
type="ghost" type="ghost"
size="large" size="large"
onClick={this.handleCancel}> onClick={this.handleCancel}>
取消 {props.cancelText}
</Button>, </Button>,
<Button key="confirm" <Button key="confirm"
type="primary" type="primary"
size="large" size="large"
loading={props.confirmLoading} loading={props.confirmLoading}
onClick={this.handleOk}> onClick={this.handleOk}>
确定 {props.okText}
</Button> </Button>
]; ];
let footer = props.footer || defaultFooter; let footer = props.footer || defaultFooter;

View File

@ -27,6 +27,8 @@
| onCancel | 点击遮罩层或右上角叉或取消按钮的回调 | function | 无 | | onCancel | 点击遮罩层或右上角叉或取消按钮的回调 | function | 无 |
| width | 宽度 | String or Number | 520 | | width | 宽度 | String or Number | 520 |
| footer | 底部内容 | React.Element | 确定取消按钮 | | footer | 底部内容 | React.Element | 确定取消按钮 |
| okText | 确认按钮文字 | String | 确定 |
| cancelText | 取消按钮文字 | String | 取消 |
### Modal.xxx() ### Modal.xxx()
@ -47,6 +49,8 @@
| onCancel | 取消回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭 | function | 无 | | onCancel | 取消回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭 | function | 无 |
| width | 宽度 | String or Number | 416 | | width | 宽度 | String or Number | 416 |
| iconClassName | 图标 Icon 类型 | String | question-circle | | iconClassName | 图标 Icon 类型 | String | question-circle |
| okText | 确认按钮文字 | String | 确定 |
| cancelText | 取消按钮文字 | String | 取消 |
<style> <style>
.code-box-demo .ant-btn { .code-box-demo .ant-btn {