Skip to content

Commit

Permalink
refactor: optimization Code
Browse files Browse the repository at this point in the history
  • Loading branch information
RedJue committed Aug 24, 2023
1 parent 9db8451 commit 077ab8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions components/modal/ConfirmDialog.tsx
Expand Up @@ -131,12 +131,12 @@ export function ConfirmContent(
{footer === undefined || typeof footer === 'function' ? (
<ModalContextProvider value={btnCtxValueMemo}>
<div className={`${confirmPrefixCls}-btns`}>
{footer === undefined
? footerOriginNode
: footer?.(footerOriginNode, {
{typeof footer === 'function'
? footer(footerOriginNode, {
ConfirmBtn,
CancelBtn,
})}
})
: footerOriginNode}
</div>
</ModalContextProvider>
) : (
Expand Down
15 changes: 6 additions & 9 deletions components/modal/Modal.tsx
@@ -1,18 +1,19 @@
import * as React from 'react';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';
import Dialog from 'rc-dialog';
import * as React from 'react';

import useClosable from '../_util/hooks/useClosable';
import { getTransitionName } from '../_util/motion';
import { canUseDocElement } from '../_util/styleChecker';
import warning from '../_util/warning';
import { ConfigContext } from '../config-provider';
import { NoFormStyle } from '../form/context';
import { NoCompactStyle } from '../space/Compact';
import { usePanelRef } from '../watermark/context';
import type { ModalProps, MousePosition } from './interface';
import { Footer, renderCloseIcon } from './shared';
import useStyle from './style';
import { usePanelRef } from '../watermark/context';

let mousePosition: MousePosition;

Expand Down Expand Up @@ -93,13 +94,9 @@ const Modal: React.FC<ModalProps> = (props) => {
warning(!('visible' in props), 'Modal', '`visible` is deprecated, please use `open` instead.');
}

const dialogFooter =
footer === undefined || typeof footer === 'function' ? (
<Footer {...props} onOk={handleOk} onCancel={handleCancel} />
) : (
footer
);

const dialogFooter = footer !== null && (
<Footer {...props} onOk={handleOk} onCancel={handleCancel} />
);
const [mergedClosable, mergedCloseIcon] = useClosable(
closable,
closeIcon,
Expand Down
4 changes: 3 additions & 1 deletion components/modal/shared.tsx
Expand Up @@ -75,7 +75,7 @@ export const Footer: React.FC<
</>
);

return (
return footer === undefined || typeof footer === 'function' ? (
<DisabledContextProvider disabled={false}>
<ModalContextProvider value={btnCtxValueMemo}>
{typeof footer === 'function'
Expand All @@ -86,5 +86,7 @@ export const Footer: React.FC<
: footerOriginNode}
</ModalContextProvider>
</DisabledContextProvider>
) : (
footer
);
};

0 comments on commit 077ab8d

Please sign in to comment.