diff --git a/components/drawer/DrawerPanel.tsx b/components/drawer/DrawerPanel.tsx index 31ccb78e338d..b422af366aae 100644 --- a/components/drawer/DrawerPanel.tsx +++ b/components/drawer/DrawerPanel.tsx @@ -5,6 +5,8 @@ import type { DrawerProps as RCDrawerProps } from 'rc-drawer'; import useClosable, { pickClosable } from '../_util/hooks/useClosable'; import type { ClosableType } from '../_util/hooks/useClosable'; import { ConfigContext } from '../config-provider'; +import Spin from '../spin'; +import type { SpinProps } from '../spin'; export interface DrawerClassNames extends NonNullable { header?: string; @@ -38,6 +40,7 @@ export interface DrawerPanelProps { children?: React.ReactNode; classNames?: DrawerClassNames; styles?: DrawerStyles; + loading?: boolean | Omit; /** @deprecated Please use `styles.header` instead */ headerStyle?: React.CSSProperties; @@ -59,6 +62,7 @@ const DrawerPanel: React.FC = (props) => { title, footer, extra, + loading, onClose, headerStyle, bodyStyle, @@ -87,6 +91,19 @@ const DrawerPanel: React.FC = (props) => { }, ); + // >>>>>>>>> Spinning + let spinProps: SpinProps | undefined; + if (typeof loading === 'boolean') { + spinProps = { + spinning: loading, + }; + } else if (typeof loading === 'object') { + spinProps = { + spinning: true, + ...loading, + }; + } + const headerNode = React.useMemo(() => { if (!title && !mergedClosable) { return null; @@ -139,6 +156,21 @@ const DrawerPanel: React.FC = (props) => { ); }, [footer, footerStyle, prefixCls]); + if (spinProps?.spinning) { + return ( + + ); + } + return ( <> {headerNode} diff --git a/components/drawer/__tests__/Drawer.test.tsx b/components/drawer/__tests__/Drawer.test.tsx index 676d6bb98080..bc5f0880785e 100644 --- a/components/drawer/__tests__/Drawer.test.tsx +++ b/components/drawer/__tests__/Drawer.test.tsx @@ -178,6 +178,35 @@ describe('Drawer', () => { expect(baseElement.querySelectorAll('button.forceRender').length).toBe(1); }); + describe('Drawer loading', () => { + it('have a spinner', () => { + const { container: wrapper } = render( + + Here is content of Drawer + , + ); + + triggerMotion(); + expect(wrapper.firstChild).toMatchSnapshot(); + }); + it('have a custom loading', () => { + const loadingContent = 'Custom Loading...'; + const { container: wrapper } = render( + {loadingContent}, spinning: true }} + getContainer={false} + > + Here is content of Drawer + , + ); + + triggerMotion(); + const [loadingWrapper] = wrapper.getElementsByClassName('ant-spin-dot'); + expect(loadingWrapper).toHaveTextContent(loadingContent); + }); + }); + it('support closeIcon', () => { const { container: wrapper } = render( close} width={400} getContainer={false}> diff --git a/components/drawer/__tests__/__snapshots__/Drawer.test.tsx.snap b/components/drawer/__tests__/__snapshots__/Drawer.test.tsx.snap index 3593c5e35d00..6bd0196a06b9 100644 --- a/components/drawer/__tests__/__snapshots__/Drawer.test.tsx.snap +++ b/components/drawer/__tests__/__snapshots__/Drawer.test.tsx.snap @@ -1,5 +1,62 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Drawer Drawer loading have a spinner 1`] = ` +
+
+