From 51a2798eb55e526a84e1e38e924dec52dcafab9a Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Tue, 24 Nov 2015 11:21:37 +0800 Subject: [PATCH] feat: Popconfirm should support i18n --- components/popconfirm/demo/locale.md | 17 +++++++++ components/popconfirm/index.jsx | 52 +++++++++++++++------------- components/popconfirm/index.md | 2 ++ 3 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 components/popconfirm/demo/locale.md diff --git a/components/popconfirm/demo/locale.md b/components/popconfirm/demo/locale.md new file mode 100644 index 0000000000..a6e45b3485 --- /dev/null +++ b/components/popconfirm/demo/locale.md @@ -0,0 +1,17 @@ +# 国际化 + +- order: 2 + +设置 `okText` `cancelText` 以自定义按钮文字。 + +--- + +````jsx +import { Popconfirm } from 'antd'; + +ReactDOM.render( + + Delete + +, document.getElementById('components-popconfirm-demo-locale')); +```` diff --git a/components/popconfirm/index.jsx b/components/popconfirm/index.jsx index 5bc680f373..a1f1eebf9d 100644 --- a/components/popconfirm/index.jsx +++ b/components/popconfirm/index.jsx @@ -2,7 +2,23 @@ import React from 'react'; import Tooltip from 'rc-tooltip'; import Icon from '../icon'; import Button from '../button'; + const prefixCls = 'ant-popover'; +const noop = function() {}; +const transitionNames = { + top: 'zoom-down', + bottom: 'zoom-up', + left: 'zoom-right', + right: 'zoom-left', + topLeft: 'zoom-down', + bottomLeft: 'zoom-up', + leftTop: 'zoom-right', + rightTop: 'zoom-left', + topRight: 'zoom-down', + bottomRight: 'zoom-up', + leftBottom: 'zoom-right', + rightBottom: 'zoom-left', +}; export default React.createClass({ getInitialState() { @@ -16,10 +32,10 @@ export default React.createClass({ placement: 'top', trigger: 'click', overlayStyle: {}, - onConfirm: function () { - }, - onCancel: function () { - } + onConfirm: noop, + onCancel: noop, + okText: '确定', + cancelText: '取消' }; }, confirm() { @@ -40,43 +56,31 @@ export default React.createClass({ }); }, render() { + const {title, okText, cancelText, placement, overlayStyle, trigger} = this.props; const overlay =

- {this.props.title} + {title}

- - + +
; - const transitionName = ({ - top: 'zoom-down', - bottom: 'zoom-up', - left: 'zoom-right', - right: 'zoom-left', - topLeft: 'zoom-down', - bottomLeft: 'zoom-up', - leftTop: 'zoom-right', - rightTop: 'zoom-left', - topRight: 'zoom-down', - bottomRight: 'zoom-up', - leftBottom: 'zoom-right', - rightBottom: 'zoom-left', - })[this.props.placement]; + const transitionName = transitionNames[placement]; return ( - {this.props.children} diff --git a/components/popconfirm/index.md b/components/popconfirm/index.md index 58540ae0ea..d3eff43d30 100644 --- a/components/popconfirm/index.md +++ b/components/popconfirm/index.md @@ -23,3 +23,5 @@ | title | 确认框的描述 | string | 无 | | onConfirm | 点击确认的回调 | function | 无 | | onCancel | 卡片内容 | function | 无 | +| okText | 确认按钮文字 | String | 确定 | +| cancelText| 取消按钮文字 | String | 取消 |