From fdd9ef7d182b6487259c1699b38915644f2b3276 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Tue, 24 Nov 2015 11:01:36 +0800 Subject: [PATCH] feat: Modal should support internationalization --- components/modal/confirm.jsx | 17 ++++--- components/modal/demo/locale.md | 87 +++++++++++++++++++++++++++++++++ components/modal/index.jsx | 6 ++- components/modal/index.md | 4 ++ 4 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 components/modal/demo/locale.md diff --git a/components/modal/confirm.jsx b/components/modal/confirm.jsx index 62004b8b13..a376cff447 100644 --- a/components/modal/confirm.jsx +++ b/components/modal/confirm.jsx @@ -72,19 +72,22 @@ export default function (props) { {props.title}
{props.content}
; - let footer =
- - -
; + let footer = null; if (props.okCancel) { footer =
- - + +
; } else { footer =
- +
; } diff --git a/components/modal/demo/locale.md b/components/modal/demo/locale.md new file mode 100644 index 0000000000..ba3c619137 --- /dev/null +++ b/components/modal/demo/locale.md @@ -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
+ + +

Bla bla ...

+

Bla bla ...

+

Bla bla ...

+
+
; + } +}); + +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(
+ +
+ + + + +
, document.getElementById('components-modal-demo-locale')); +```` + diff --git a/components/modal/index.jsx b/components/modal/index.jsx index e9cfcc68c4..9166a13e9a 100644 --- a/components/modal/index.jsx +++ b/components/modal/index.jsx @@ -15,6 +15,8 @@ let AntModal = React.createClass({ prefixCls: 'ant-modal', onOk: noop, onCancel: noop, + okText: '确定', + cancelText: '取消', width: 520, transitionName: 'zoom', maskAnimation: 'fade', @@ -56,14 +58,14 @@ let AntModal = React.createClass({ type="ghost" size="large" onClick={this.handleCancel}> - 取消 + {props.cancelText} , ]; let footer = props.footer || defaultFooter; diff --git a/components/modal/index.md b/components/modal/index.md index e491444b6b..ce3a403a34 100644 --- a/components/modal/index.md +++ b/components/modal/index.md @@ -27,6 +27,8 @@ | onCancel | 点击遮罩层或右上角叉或取消按钮的回调 | function | 无 | | width | 宽度 | String or Number | 520 | | footer | 底部内容 | React.Element | 确定取消按钮 | +| okText | 确认按钮文字 | String | 确定 | +| cancelText | 取消按钮文字 | String | 取消 | ### Modal.xxx() @@ -47,6 +49,8 @@ | onCancel | 取消回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭 | function | 无 | | width | 宽度 | String or Number | 416 | | iconClassName | 图标 Icon 类型 | String | question-circle | +| okText | 确认按钮文字 | String | 确定 | +| cancelText | 取消按钮文字 | String | 取消 |