demo: update Drawer demo (#48935)

This commit is contained in:
lijianan 2024-05-15 15:15:02 +08:00 committed by GitHub
parent 08e39ba2e4
commit 84b072e585
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 22 deletions

View File

@ -2788,7 +2788,7 @@ Array [
type="button"
>
<span>
Open
Open Drawer
</span>
</button>,
<div

View File

@ -265,7 +265,7 @@ exports[`renders components/drawer/demo/loading.tsx correctly 1`] = `
type="button"
>
<span>
Open
Open Drawer
</span>
</button>
`;

View File

@ -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>