ant-design/components/drawer/demo/loading.tsx

44 lines
1015 B
TypeScript
Raw Normal View History

2024-05-09 11:56:53 +08:00
import React from 'react';
import { Button, Drawer } from 'antd';
const App: React.FC = () => {
2024-05-15 15:15:02 +08:00
const [open, setOpen] = React.useState<boolean>(false);
const [loading, setLoading] = React.useState<boolean>(true);
2024-05-15 15:15:02 +08:00
const showLoading = () => {
2024-05-09 11:56:53 +08:00
setOpen(true);
setLoading(true);
2024-05-15 15:15:02 +08:00
// Simple loading mock. You should add cleanup logic in real world.
setTimeout(() => {
2024-05-09 11:56:53 +08:00
setLoading(false);
}, 2000);
};
return (
<>
2024-05-15 15:15:02 +08:00
<Button type="primary" onClick={showLoading}>
Open Drawer
</Button>
<Drawer
2024-05-15 15:15:02 +08:00
closable
2024-05-09 11:56:53 +08:00
destroyOnClose
2024-05-15 15:15:02 +08:00
title={<p>Loading Drawer</p>}
placement="right"
open={open}
loading={loading}
2024-05-09 11:56:53 +08:00
onClose={() => setOpen(false)}
>
2024-05-15 15:15:02 +08:00
<Button type="primary" style={{ marginBottom: 16 }} onClick={showLoading}>
Reload
2024-05-09 11:56:53 +08:00
</Button>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</>
);
};
export default App;