docs: translate modal (#2634)

This commit is contained in:
Gray Choi 2016-08-11 12:41:06 +09:00 committed by Benjy Cui
parent be553af441
commit 5c2087311f
11 changed files with 206 additions and 63 deletions

View File

@ -1,17 +1,26 @@
--- ---
order: 1 order: 1
title: 异步关闭 title:
zh-CN: 异步关闭
en-US: Asynchronously close
--- ---
## zh-CN
点击确定后异步关闭对话框,例如提交表单。 点击确定后异步关闭对话框,例如提交表单。
## en-US
Asynchronously close a modal dialog when a user clicked OK button, for example,
you can use this pattern when you submit a form.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
const Test = React.createClass({ const Test = React.createClass({
getInitialState() { getInitialState() {
return { return {
ModalText: '对话框的内容', ModalText: 'Content of the modal dialog',
visible: false, visible: false,
}; };
}, },
@ -22,7 +31,7 @@ const Test = React.createClass({
}, },
handleOk() { handleOk() {
this.setState({ this.setState({
ModalText: '对话框将在两秒后关闭', ModalText: 'The modal dialog will be closed after two seconds',
confirmLoading: true, confirmLoading: true,
}); });
setTimeout(() => { setTimeout(() => {
@ -33,7 +42,7 @@ const Test = React.createClass({
}, 2000); }, 2000);
}, },
handleCancel() { handleCancel() {
console.log('点击了取消'); console.log('Clicked cancel button');
this.setState({ this.setState({
visible: false, visible: false,
}); });
@ -41,8 +50,8 @@ const Test = React.createClass({
render() { render() {
return ( return (
<div> <div>
<Button type="primary" onClick={this.showModal}>显示对话框</Button> <Button type="primary" onClick={this.showModal}>Open a modal dialog</Button>
<Modal title="对话框标题" <Modal title="Title of the modal dialog"
visible={this.state.visible} visible={this.state.visible}
onOk={this.handleOk} onOk={this.handleOk}
confirmLoading={this.state.confirmLoading} confirmLoading={this.state.confirmLoading}

View File

@ -1,10 +1,18 @@
--- ---
order: 0 order: 0
title: 基本 title:
zh-CN: 基本
en-US: Basic
--- ---
## en-US
第一个对话框。 第一个对话框。
## zh-CN
Basic modal dialog.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
@ -18,7 +26,7 @@ const App = React.createClass({
}); });
}, },
handleOk() { handleOk() {
console.log('点击了确定'); console.log('Clicked OK');
this.setState({ this.setState({
visible: false, visible: false,
}); });
@ -32,13 +40,13 @@ const App = React.createClass({
render() { render() {
return ( return (
<div> <div>
<Button type="primary" onClick={this.showModal}>显示对话框</Button> <Button type="primary" onClick={this.showModal}>Open a modal dialog</Button>
<Modal title="第一个 Modal" visible={this.state.visible} <Modal title="Basic Modal" visible={this.state.visible}
onOk={this.handleOk} onCancel={this.handleCancel} onOk={this.handleOk} onCancel={this.handleCancel}
> >
<p>对话框的内容</p> <p>some contents...</p>
<p>对话框的内容</p> <p>some contents...</p>
<p>对话框的内容</p> <p>some contents...</p>
</Modal> </Modal>
</div> </div>
); );

View File

@ -1,18 +1,27 @@
--- ---
order: 5 order: 5
title: 确认对话框 title:
zh-CN: 确认对话框
en-US: Confirmation modal dialog
--- ---
## zh-CN
使用 `confirm()` 可以快捷地弹出确认框。onCancel/onOk 返回 promise 可以延迟关闭 使用 `confirm()` 可以快捷地弹出确认框。onCancel/onOk 返回 promise 可以延迟关闭
## en-US
To use `confirm()` to popup confirmation modal dialog. Let onCancel/onOk function return a promise object to
delay closing the dialog.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
const confirm = Modal.confirm; const confirm = Modal.confirm;
function showConfirm() { function showConfirm() {
confirm({ confirm({
title: '您是否确认要删除这项内容', title: 'Are you sure you want to delete this item ?',
content: '点确认 1 秒后关闭', content: 'When clicked the OK button, this dialog will be closed after 1 second',
onOk() { onOk() {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, 1000); setTimeout(resolve, 1000);
@ -24,7 +33,7 @@ function showConfirm() {
ReactDOM.render( ReactDOM.render(
<Button onClick={showConfirm}> <Button onClick={showConfirm}>
确认对话框 Confirmation modal dialog
</Button> </Button>
, mountNode); , mountNode);
```` ````

View File

@ -1,20 +1,28 @@
--- ---
order: 3 order: 3
title: 确认对话框 title:
zh-CN: 确认对话框
en-US: Confirmation modal dialog
--- ---
## zh-CN
使用 `confirm()` 可以快捷地弹出确认框。 使用 `confirm()` 可以快捷地弹出确认框。
## en-US
To use `confirm()` to popup a confirmation modal dialog.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
const confirm = Modal.confirm; const confirm = Modal.confirm;
function showConfirm() { function showConfirm() {
confirm({ confirm({
title: '您是否确认要删除这项内容', title: 'Are you sure you want to delete these items ?',
content: '一些解释', content: 'some descriptions',
onOk() { onOk() {
console.log('确定'); console.log('OK');
}, },
onCancel() {}, onCancel() {},
}); });
@ -22,7 +30,7 @@ function showConfirm() {
ReactDOM.render( ReactDOM.render(
<Button onClick={showConfirm}> <Button onClick={showConfirm}>
确认对话框 confirmation modal dialog
</Button> </Button>
, mountNode); , mountNode);
```` ````

View File

@ -1,10 +1,20 @@
--- ---
order: 2 order: 2
title: 自定义页脚 title:
zh-CN: 自定义页脚
en-US: Customized footer
--- ---
## zh-CN
更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。 更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。
## en-US
A more complex example, as illustrated in this example, we define a customized footer button bar,
the dialog will change to loading state after clicking submit button , when the loading is over,
the modal dialog will be closed.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
@ -33,23 +43,23 @@ const Test = React.createClass({
return ( return (
<div> <div>
<Button type="primary" onClick={this.showModal}> <Button type="primary" onClick={this.showModal}>
显示对话框 Open modal dialog
</Button> </Button>
<Modal ref="modal" <Modal ref="modal"
visible={this.state.visible} visible={this.state.visible}
title="对话框标题" onOk={this.handleOk} onCancel={this.handleCancel} title="Title" onOk={this.handleOk} onCancel={this.handleCancel}
footer={[ footer={[
<Button key="back" type="ghost" size="large" onClick={this.handleCancel}>返 回</Button>, <Button key="back" type="ghost" size="large" onClick={this.handleCancel}>Return</Button>,
<Button key="submit" type="primary" size="large" loading={this.state.loading} onClick={this.handleOk}> <Button key="submit" type="primary" size="large" loading={this.state.loading} onClick={this.handleOk}>
提 交 Submit
</Button>, </Button>,
]} ]}
> >
<p>对话框的内容</p> <p>Some contents...</p>
<p>对话框的内容</p> <p>Some contents...</p>
<p>对话框的内容</p> <p>Some contents...</p>
<p>对话框的内容</p> <p>Some contents...</p>
<p>对话框的内容</p> <p>Some contents...</p>
</Modal> </Modal>
</div> </div>
); );

View File

@ -1,20 +1,28 @@
--- ---
order: 5 order: 5
title: 信息提示 title:
zh-CN: 信息提示
en-US: Infomation modal dialog
--- ---
## zh-CN
各种类型的信息提示,只提供一个按钮用于关闭。 各种类型的信息提示,只提供一个按钮用于关闭。
## en-US
In the various types of informaion modal dialog, only one button to close dialog is provided.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
function info() { function info() {
Modal.info({ Modal.info({
title: '这是一条通知信息', title: 'This is a notification message',
content: ( content: (
<div> <div>
<p>一些附加信息一些附加信息一些附加信息</p> <p>some messages...some messages...</p>
<p>一些附加信息一些附加信息一些附加信息</p> <p>some messages...some messages...</p>
</div> </div>
), ),
onOk() {}, onOk() {},
@ -23,29 +31,29 @@ function info() {
function success() { function success() {
Modal.success({ Modal.success({
title: '这是一条通知信息', title: 'This is a success message',
content: '一些附加信息一些附加信息一些附加信息', content: 'some messages...some messages...',
}); });
} }
function error() { function error() {
Modal.error({ Modal.error({
title: '这是一条通知信息', title: 'This is an error message',
content: '一些附加信息一些附加信息一些附加信息', content: 'some messages...some messages...',
}); });
} }
function warning() { function warning() {
Modal.warning({ Modal.warning({
title: '这是一条警告信息', title: 'This is a warning messge',
content: '一些附加信息一些附加信息一些附加信息', content: 'some messages...some messages...',
}); });
} }
ReactDOM.render(<div> ReactDOM.render(<div>
<Button onClick={info}>信息提示</Button> <Button onClick={info}>Info</Button>
<Button onClick={success}>成功提示</Button> <Button onClick={success}>Success</Button>
<Button onClick={error}>失败提示</Button> <Button onClick={error}>Error</Button>
<Button onClick={warning}>警告提示</Button> <Button onClick={warning}>Warning</Button>
</div>, mountNode); </div>, mountNode);
```` ````

View File

@ -1,10 +1,18 @@
--- ---
order: 6 order: 6
title: 国际化 title:
zh-CN: 国际化
en-US: Internationalization
--- ---
## zh-CN
设置 `okText``cancelText` 以自定义按钮文字。 设置 `okText``cancelText` 以自定义按钮文字。
## en-US
To customize the text of the buttons, you need to set `okText` and `cancelText` props.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';

View File

@ -1,23 +1,31 @@
--- ---
order: 7 order: 7
title: 手动移除 title:
zh-CN: 手动移除
en-US: Manual to destroy
--- ---
## zh-CN
手动关闭modal。 手动关闭modal。
## en-US
Manually destroying a modal.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
function success() { function success() {
const modal = Modal.success({ const modal = Modal.success({
title: '这是一条通知信息', title: 'This is a notification message',
content: '一秒后自动移除', content: 'This modal will be destroyed after 1 second',
}); });
setTimeout(() => modal.destroy(), 1000); setTimeout(() => modal.destroy(), 1000);
} }
ReactDOM.render(<div> ReactDOM.render(<div>
<Button onClick={success}>成功提示</Button> <Button onClick={success}>Success</Button>
</div>, mountNode); </div>, mountNode);
```` ````

View File

@ -1,10 +1,19 @@
--- ---
order: 7 order: 7
title: 自定义位置 title:
zh-CN: 自定义位置
en-US: To customize the position of modal
--- ---
## zh-CN
`1.0` 之后Modal 的 `align` 属性被移除,您可以直接使用 `style.top` 或配合其他样式来设置对话框位置。 `1.0` 之后Modal 的 `align` 属性被移除,您可以直接使用 `style.top` 或配合其他样式来设置对话框位置。
## en-US
After release `1.0`, Modal's `align` prop was removed. You can use `style.top` or other styles to
set position of modal dialog.
````jsx ````jsx
import { Modal, Button } from 'antd'; import { Modal, Button } from 'antd';
@ -24,29 +33,29 @@ const App = React.createClass({
render() { render() {
return ( return (
<div> <div>
<Button type="primary" onClick={() => this.setModal1Visible(true)}>显示距离顶部 20px 的对话框</Button> <Button type="primary" onClick={() => this.setModal1Visible(true)}>Display a modal dialog at 20px to Top</Button>
<Modal <Modal
title="距离顶部 20px 的对话框" title="20px to Top"
style={{ top: 20 }} style={{ top: 20 }}
visible={this.state.modal1Visible} visible={this.state.modal1Visible}
onOk={() => this.setModal1Visible(false)} onOk={() => this.setModal1Visible(false)}
onCancel={() => this.setModal1Visible(false)} onCancel={() => this.setModal1Visible(false)}
> >
<p>对话框的内容</p> <p>some contents...</p>
<p>对话框的内容</p> <p>some contents...</p>
<p>对话框的内容</p> <p>some contents...</p>
</Modal> </Modal>
<Button type="primary" onClick={() => this.setModal2Visible(true)}>显示垂直居中的对话框</Button> <Button type="primary" onClick={() => this.setModal2Visible(true)}>Vertically centered modal dialog</Button>
<Modal <Modal
title="垂直居中的对话框" title="Vertically centered modal dialog"
wrapClassName="vertical-center-modal" wrapClassName="vertical-center-modal"
visible={this.state.modal2Visible} visible={this.state.modal2Visible}
onOk={() => this.setModal2Visible(false)} onOk={() => this.setModal2Visible(false)}
onCancel={() => this.setModal2Visible(false)} onCancel={() => this.setModal2Visible(false)}
> >
<p>对话框的内容</p> <p>some contents...</p>
<p>对话框的内容</p> <p>some contents...</p>
<p>对话框的内容</p> <p>some contents...</p>
</Modal> </Modal>
</div> </div>
); );
@ -57,7 +66,7 @@ ReactDOM.render(<App />, mountNode);
```` ````
````css ````css
/* 使用 css 技巧来动态设置的对话框位置 */ /* use css to set position of modal */
.vertical-center-modal { .vertical-center-modal {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -0,0 +1,66 @@
---
type: Views
category: Components
english: Modal
---
Modal dialogs.
## When to use
When requiring users to interact with application, but without jumping to a new page to interrupt
the user's workflow, you can use `Modal` to create a new floating layer over the currtent page for user
getting feedback or information purposes.
Additionaly, if you need show a simple confirmation dialog, you can use `ant.Modal.confirm()`,
and so on.
## API
| Property | Description | Type | Default |
|------------|----------------|------------------|--------------|
| visible | Determine whether a modal dialog is visible or not | Boolean | no |
| confirmLoading | Determine whether to apply loading visual effect for OK button or not | Boolean | no |
| title | The modal dialog's title | React.Element | no |
| closable | Determine whether a close (x) button is visible on top right of the modal dialog or not | Boolean | true |
| onOk | Specify a function that will be called when a user clicked OK button | function | no |
| onCancel | Specify a function that will be called when a user clicked mask, close button on top right or cancel button | function(e) | no |
| width | Width of a modal dialog | String or Number | 520 |
| footer | Footer content | React.Element | OK and cancel button |
| okText | Text of the OK button | String | OK |
| cancelText | Text of the Cancel button | String | Cancel |
| maskClosable | Determine whether to close the modal dialog when clicked mask of it. | Boolean | true |
| style | Style of floating layer, typically used at least for adjusting the position. | Object | - |
| wrapClassName | The class name of the container of the modal dialog | String | - |
### Modal.xxx()
There are five ways to display the information based on the content's nature:
- `Modal.info`
- `Modal.success`
- `Modal.error`
- `Modal.warning`
- `Modal.confirm`
The item listd above are all functions, expecting a settings object as parameter.
The propeties of the object are follows:
| Property | Description | Type | Default |
|------------|----------------|------------------|---------------|
| title | Title | React.Element or String | no |
| content | Content | React.Element or String | no |
| onOk | Specify a function that will be called when a user clicked OK button. The parameter of this function is a function whose execution should include closing the dialog. You can also just return a promise and when the promise is resolved, the modal dialog will also be closed | function | no |
| onCancel | Specify a function that will be called when a user clicked Cancel button. The parameter of this function is a function whose execution should include closing the dialog. You can also just return a promise and when the promise is resolved, the modal dialog will also be closed | function | no |
| width | Width of dialog | String or Number | 416 |
| iconType | Type of Icon component | String | question-circle |
| okText | Text of OK button | String | OK |
| cancelText | Text of cancel button | String | Cancel |
<style>
.code-box-demo .ant-btn {
margin-right: 8px;
}
</style>