diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index be378973c8..162d6526c1 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -1,18 +1,13 @@ -import CloseOutlined from '@ant-design/icons/CloseOutlined'; import classNames from 'classnames'; import Dialog from 'rc-dialog'; import * as React from 'react'; - -import Button from '../button'; import type { ButtonProps, LegacyButtonType } from '../button/button'; -import { convertLegacyProps } from '../button/button'; import type { DirectionType } from '../config-provider'; import { ConfigContext } from '../config-provider'; import { NoFormStyle } from '../form/context'; -import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { getTransitionName } from '../_util/motion'; import { canUseDocElement } from '../_util/styleChecker'; -import { getConfirmLocale } from './locale'; +import { renderCloseIcon, renderFooter } from './PurePanel'; import useStyle from './style'; let mousePosition: { x: number; y: number } | null; @@ -152,28 +147,9 @@ const Modal: React.FC = props => { onOk?.(e); }; - const renderFooter = (locale: ModalLocale) => { - const { okText, okType, cancelText, confirmLoading } = props; - return ( - <> - - - - ); - }; - const { prefixCls: customizePrefixCls, - footer, + className, visible, wrapClassName, centered, @@ -188,18 +164,6 @@ const Modal: React.FC = props => { // Style const [wrapSSR, hashId] = useStyle(prefixCls); - const defaultFooter = ( - - {renderFooter} - - ); - - const closeIconToRender = ( - - {closeIcon || } - - ); - const wrapClassNameExtended = classNames(wrapClassName, { [`${prefixCls}-centered`]: !!centered, [`${prefixCls}-wrap-rtl`]: direction === 'rtl', @@ -214,14 +178,19 @@ const Modal: React.FC = props => { prefixCls={prefixCls} rootClassName={hashId} wrapClassName={wrapClassNameExtended} - footer={footer === undefined ? defaultFooter : footer} + footer={renderFooter({ + ...props, + onOk: handleOk, + onCancel: handleCancel, + })} visible={visible} mousePosition={mousePosition} onClose={handleCancel} - closeIcon={closeIconToRender} + closeIcon={renderCloseIcon(prefixCls, closeIcon)} focusTriggerAfterClose={focusTriggerAfterClose} transitionName={getTransitionName(rootPrefixCls, 'zoom', props.transitionName)} maskTransitionName={getTransitionName(rootPrefixCls, 'fade', props.maskTransitionName)} + className={classNames(hashId, className)} /> , ); @@ -231,7 +200,6 @@ Modal.defaultProps = { width: 520, confirmLoading: false, visible: false, - okType: 'primary' as LegacyButtonType, }; export default Modal; diff --git a/components/modal/PurePanel.tsx b/components/modal/PurePanel.tsx new file mode 100644 index 0000000000..7a9a969c70 --- /dev/null +++ b/components/modal/PurePanel.tsx @@ -0,0 +1,101 @@ +import CloseOutlined from '@ant-design/icons/CloseOutlined'; +import classNames from 'classnames'; +import { Panel } from 'rc-dialog'; +import type { PanelProps } from 'rc-dialog/lib/Dialog/Content/Panel'; +import * as React from 'react'; +import Button from '../button'; +import { convertLegacyProps } from '../button/button'; +import { ConfigContext } from '../config-provider'; +import LocaleReceiver from '../locale-provider/LocaleReceiver'; +import { getConfirmLocale } from './locale'; +import type { ModalProps } from './Modal'; +import useStyle from './style'; + +export interface PurePanelProps extends Omit { + prefixCls?: string; + style?: React.CSSProperties; +} + +export function renderCloseIcon(prefixCls: string, closeIcon?: React.ReactNode) { + return ( + + {closeIcon || } + + ); +} + +export function renderFooter( + props: Pick< + ModalProps, + | 'footer' + | 'okText' + | 'okType' + | 'cancelText' + | 'confirmLoading' + | 'okButtonProps' + | 'cancelButtonProps' + > & { + onOk?: React.MouseEventHandler; + onCancel?: React.MouseEventHandler; + }, +) { + const { + okText, + okType = 'primary', + cancelText, + confirmLoading, + onOk, + onCancel, + okButtonProps, + cancelButtonProps, + footer, + } = props; + + return ( + footer ?? ( + + {locale => ( + <> + + + + )} + + ) + ); +} + +export default function PurePanel(props: PurePanelProps) { + const { + prefixCls: customizePrefixCls, + className, + closeIcon, + closable = true, + ...restProps + } = props; + const { getPrefixCls } = React.useContext(ConfigContext); + + const prefixCls = customizePrefixCls || getPrefixCls('modal'); + + const [, hashId] = useStyle(prefixCls); + + return ( + + ); +} diff --git a/components/modal/__tests__/__snapshots__/Modal.test.tsx.snap b/components/modal/__tests__/__snapshots__/Modal.test.tsx.snap index 51245958ea..c2985b93bc 100644 --- a/components/modal/__tests__/__snapshots__/Modal.test.tsx.snap +++ b/components/modal/__tests__/__snapshots__/Modal.test.tsx.snap @@ -164,6 +164,26 @@ exports[`Modal render without footer 1`] = ` > Here is content of Modal +