Skip to content

Commit

Permalink
fix: loading replace drawer content while true
Browse files Browse the repository at this point in the history
  • Loading branch information
EnigamaE authored and Enigama committed Apr 25, 2024
1 parent 36187ac commit 1f7693d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 319 deletions.
36 changes: 18 additions & 18 deletions components/drawer/DrawerPanel.tsx
Expand Up @@ -8,21 +8,6 @@ import { ConfigContext } from '../config-provider';
import Spin from '../spin';
import type { SpinProps } from '../spin';

interface PanelNodeProps {
children: React.ReactNode;
spinProps?: SpinProps;
}
const PanelNode: React.FC<PanelNodeProps> = ({ children, spinProps }) => {
if (!spinProps) {
return children;
}
return (
<Spin spinning={false} {...spinProps}>
{children}
</Spin>
);
};

export interface DrawerClassNames extends NonNullable<RCDrawerProps['classNames']> {
header?: string;
body?: string;
Expand Down Expand Up @@ -55,7 +40,7 @@ export interface DrawerPanelProps {
children?: React.ReactNode;
classNames?: DrawerClassNames;
styles?: DrawerStyles;
loading?: boolean | Omit<SpinProps, 'fullscreen'>;
loading?: boolean | Omit<SpinProps, 'fullscreen' | 'tip'>;

/** @deprecated Please use `styles.header` instead */
headerStyle?: React.CSSProperties;
Expand Down Expand Up @@ -171,8 +156,23 @@ const DrawerPanel: React.FC<DrawerPanelProps> = (props) => {
);
}, [footer, footerStyle, prefixCls]);

if (spinProps?.spinning) {
return (
<Spin
spinning={false}
style={{
height: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
{...spinProps}
/>
);
}

return (
<PanelNode spinProps={spinProps}>
<>
{headerNode}
<div
className={classNames(
Expand All @@ -189,7 +189,7 @@ const DrawerPanel: React.FC<DrawerPanelProps> = (props) => {
{children}
</div>
{footerNode}
</PanelNode>
</>
);
};

Expand Down
13 changes: 1 addition & 12 deletions components/drawer/__tests__/Drawer.test.tsx
Expand Up @@ -179,7 +179,7 @@ describe('Drawer', () => {
expect(baseElement.querySelectorAll('button.forceRender').length).toBe(1);
});

describe('Drawer spinner', () => {
describe('Drawer loading', () => {
it('have a spinner', () => {
const { container: wrapper } = render(
<Drawer open loading getContainer={false}>
Expand All @@ -190,17 +190,6 @@ describe('Drawer', () => {
triggerMotion();
expect(wrapper.firstChild).toMatchSnapshot();
});
it('have a spinner with custom text', () => {
const tip = 'Loading...';
const { getByText } = render(
<Drawer open loading={{ tip }} getContainer={false}>
Here is content of Drawer
</Drawer>,
);

triggerMotion();
expect(getByText(tip)).toBeInTheDocument();
});
});

it('support closeIcon', () => {
Expand Down

0 comments on commit 1f7693d

Please sign in to comment.