2023-06-06 09:54:14 +08:00
|
|
|
import React from 'react';
|
2023-08-28 11:54:43 +08:00
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
|
2023-08-10 16:48:28 +08:00
|
|
|
import { DisabledContextProvider } from '../config-provider/DisabledContext';
|
2023-06-06 09:54:14 +08:00
|
|
|
import { useLocale } from '../locale';
|
2023-08-28 11:54:43 +08:00
|
|
|
import NormalCancelBtn from './components/NormalCancelBtn';
|
|
|
|
import NormalOkBtn from './components/NormalOkBtn';
|
|
|
|
import type { ModalContextProps } from './context';
|
|
|
|
import { ModalContextProvider } from './context';
|
2023-06-06 09:54:14 +08:00
|
|
|
import type { ModalProps } from './interface';
|
|
|
|
import { getConfirmLocale } from './locale';
|
|
|
|
|
|
|
|
export function renderCloseIcon(prefixCls: string, closeIcon?: React.ReactNode) {
|
|
|
|
return (
|
|
|
|
<span className={`${prefixCls}-close-x`}>
|
|
|
|
{closeIcon || <CloseOutlined className={`${prefixCls}-close-icon`} />}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface FooterProps {
|
|
|
|
onOk?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
|
|
|
onCancel?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Footer: React.FC<
|
|
|
|
FooterProps &
|
|
|
|
Pick<
|
|
|
|
ModalProps,
|
|
|
|
| 'footer'
|
|
|
|
| 'okText'
|
|
|
|
| 'okType'
|
|
|
|
| 'cancelText'
|
|
|
|
| 'confirmLoading'
|
|
|
|
| 'okButtonProps'
|
|
|
|
| 'cancelButtonProps'
|
|
|
|
>
|
|
|
|
> = (props) => {
|
|
|
|
const {
|
|
|
|
okText,
|
|
|
|
okType = 'primary',
|
|
|
|
cancelText,
|
|
|
|
confirmLoading,
|
|
|
|
onOk,
|
|
|
|
onCancel,
|
|
|
|
okButtonProps,
|
|
|
|
cancelButtonProps,
|
2023-08-28 11:54:43 +08:00
|
|
|
footer,
|
2023-06-06 09:54:14 +08:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
const [locale] = useLocale('Modal', getConfirmLocale());
|
|
|
|
|
2023-08-28 11:54:43 +08:00
|
|
|
// ================== Locale Text ==================
|
|
|
|
const okTextLocale = okText || locale?.okText;
|
|
|
|
const cancelTextLocale = cancelText || locale?.cancelText;
|
|
|
|
|
|
|
|
// ================= Context Value =================
|
|
|
|
const btnCtxValue: ModalContextProps = {
|
|
|
|
confirmLoading,
|
|
|
|
okButtonProps,
|
|
|
|
cancelButtonProps,
|
|
|
|
okTextLocale,
|
|
|
|
cancelTextLocale,
|
|
|
|
okType,
|
|
|
|
onOk,
|
|
|
|
onCancel,
|
|
|
|
};
|
|
|
|
|
|
|
|
const btnCtxValueMemo = React.useMemo(() => btnCtxValue, [...Object.values(btnCtxValue)]);
|
|
|
|
|
2024-06-22 21:59:12 +08:00
|
|
|
let footerNode: React.ReactNode;
|
2023-09-04 17:20:30 +08:00
|
|
|
if (typeof footer === 'function' || typeof footer === 'undefined') {
|
|
|
|
footerNode = (
|
2023-09-18 18:33:25 +08:00
|
|
|
<>
|
2023-09-04 17:20:30 +08:00
|
|
|
<NormalCancelBtn />
|
|
|
|
<NormalOkBtn />
|
2023-09-18 18:33:25 +08:00
|
|
|
</>
|
2023-09-04 17:20:30 +08:00
|
|
|
);
|
2023-09-18 18:33:25 +08:00
|
|
|
|
2023-09-04 17:20:30 +08:00
|
|
|
if (typeof footer === 'function') {
|
|
|
|
footerNode = footer(footerNode, {
|
|
|
|
OkBtn: NormalOkBtn,
|
|
|
|
CancelBtn: NormalCancelBtn,
|
|
|
|
});
|
|
|
|
}
|
2023-09-18 18:33:25 +08:00
|
|
|
|
|
|
|
footerNode = <ModalContextProvider value={btnCtxValueMemo}>{footerNode}</ModalContextProvider>;
|
2023-09-04 17:20:30 +08:00
|
|
|
} else {
|
|
|
|
footerNode = footer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <DisabledContextProvider disabled={false}>{footerNode}</DisabledContextProvider>;
|
2023-06-06 09:54:14 +08:00
|
|
|
};
|