ant-design/components/modal/demo/footer.md

84 lines
1.9 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 2
2016-08-23 21:00:35 +08:00
title:
2016-08-11 11:41:06 +08:00
zh-CN: 自定义页脚
en-US: Customized Footer
2016-03-31 09:40:55 +08:00
---
2015-06-12 17:37:39 +08:00
2016-08-11 11:41:06 +08:00
## zh-CN
2015-06-12 17:44:29 +08:00
更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。
2015-06-12 17:37:39 +08:00
不需要默认确定取消按钮时,你可以把 `footer` 设为 `null`
2016-08-11 11:41:06 +08:00
## en-US
2019-05-07 14:57:32 +08:00
A more complex example which define a customized footer button bar. The dialog will change to loading state after clicking the submit button, and when the loading is done, the modal dialog will be closed.
2016-08-11 11:41:06 +08:00
You could set `footer` to `null` if you don't need default footer buttons.
```tsx
2022-05-23 14:37:16 +08:00
import { Button, Modal } from 'antd';
import React, { useState } from 'react';
2015-06-12 17:37:39 +08:00
const App: React.FC = () => {
const [loading, setLoading] = useState(false);
const [open, setOpen] = useState(false);
2018-06-27 15:55:04 +08:00
const showModal = () => {
setOpen(true);
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
const handleOk = () => {
setLoading(true);
setTimeout(() => {
setLoading(false);
setOpen(false);
2015-06-12 17:37:39 +08:00
}, 3000);
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
const handleCancel = () => {
setOpen(false);
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
return (
<>
<Button type="primary" onClick={showModal}>
Open Modal with customized footer
</Button>
<Modal
open={open}
title="Title"
onOk={handleOk}
onCancel={handleCancel}
footer={[
<Button key="back" onClick={handleCancel}>
Return
</Button>,
<Button key="submit" type="primary" loading={loading} onClick={handleOk}>
Submit
</Button>,
<Button
key="link"
href="https://google.com"
type="primary"
loading={loading}
onClick={handleOk}
>
Search on Google
</Button>,
]}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Modal>
</>
);
};
2015-06-12 17:37:39 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```