mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
demo: update Drawer demo (#48935)
This commit is contained in:
parent
08e39ba2e4
commit
84b072e585
@ -2788,7 +2788,7 @@ Array [
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
Open
|
||||
Open Drawer
|
||||
</span>
|
||||
</button>,
|
||||
<div
|
||||
|
@ -265,7 +265,7 @@ exports[`renders components/drawer/demo/loading.tsx correctly 1`] = `
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
Open
|
||||
Open Drawer
|
||||
</span>
|
||||
</button>
|
||||
`;
|
||||
|
@ -1,44 +1,36 @@
|
||||
import React from 'react';
|
||||
import type { DrawerProps } from 'antd';
|
||||
import { Button, Drawer } from 'antd';
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [loading, setLoading] = React.useState<DrawerProps['loading']>(true);
|
||||
const timerRef = React.useRef<ReturnType<typeof setTimeout>>();
|
||||
const [open, setOpen] = React.useState<boolean>(false);
|
||||
const [loading, setLoading] = React.useState<boolean>(true);
|
||||
|
||||
const clearTimer = () => {
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
}
|
||||
};
|
||||
|
||||
const showDrawer = () => {
|
||||
const showLoading = () => {
|
||||
setOpen(true);
|
||||
setLoading(true);
|
||||
timerRef.current = setTimeout(() => {
|
||||
|
||||
// Simple loading mock. You should add cleanup logic in real world.
|
||||
setTimeout(() => {
|
||||
setLoading(false);
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
React.useEffect(() => clearTimer, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button type="primary" onClick={showDrawer}>
|
||||
Open
|
||||
<Button type="primary" onClick={showLoading}>
|
||||
Open Drawer
|
||||
</Button>
|
||||
<Drawer
|
||||
closable
|
||||
destroyOnClose
|
||||
title="Basic Drawer"
|
||||
title={<p>Loading Drawer</p>}
|
||||
placement="right"
|
||||
closable={false}
|
||||
open={open}
|
||||
loading={loading}
|
||||
onClose={() => setOpen(false)}
|
||||
>
|
||||
<Button type="primary" style={{ marginBottom: 16 }} onClick={() => setLoading(true)}>
|
||||
set Loading true
|
||||
<Button type="primary" style={{ marginBottom: 16 }} onClick={showLoading}>
|
||||
Reload
|
||||
</Button>
|
||||
<p>Some contents...</p>
|
||||
<p>Some contents...</p>
|
||||
|
Loading…
Reference in New Issue
Block a user