mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-04 00:49:39 +08:00
3bb3485ac7
* Revert "refactor: fix compiling (#44616)" This reverts commitb284648f11
. * feat: modal purepanel support footer render * demo: update debug demo * test: update test case * Revert "test: update test case" This reverts commit34d151f866
. * chore: add more unit test case * Revert "Revert "refactor: fix compiling (#44616)"" This reverts commit0e054de421
. * fix(Modal): custom footer render errors * chore: fix TS error * chore: improvement type * chore: update * chore: update * Revert "chore: update" This reverts commitc72bb07db9
. * Revert "chore: update" This reverts commit9a4276078c
. * Revert "chore: improvement type" This reverts commit159e3dc754
. * Revert "chore: fix TS error" This reverts commitf1a9aa59b2
. * Revert "feat: modal purepanel support footer render" This reverts commit68de65e76a
. * Revert "demo: update debug demo" This reverts commit6741af239b
. * Update components/modal/__tests__/Modal.test.tsx Co-authored-by: 红 <wxh16144@qq.com> Signed-off-by: afc163 <afc163@gmail.com> --------- Signed-off-by: afc163 <afc163@gmail.com> Co-authored-by: afc163 <afc163@gmail.com>
94 lines
2.4 KiB
TypeScript
94 lines
2.4 KiB
TypeScript
import React from 'react';
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
import { DisabledContextProvider } from '../config-provider/DisabledContext';
|
|
import { useLocale } from '../locale';
|
|
import NormalCancelBtn from './components/NormalCancelBtn';
|
|
import NormalOkBtn from './components/NormalOkBtn';
|
|
import type { ModalContextProps } from './context';
|
|
import { ModalContextProvider } from './context';
|
|
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,
|
|
footer,
|
|
} = props;
|
|
|
|
const [locale] = useLocale('Modal', getConfirmLocale());
|
|
|
|
// ================== 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)]);
|
|
|
|
let footerNode;
|
|
if (typeof footer === 'function' || typeof footer === 'undefined') {
|
|
footerNode = (
|
|
<>
|
|
<NormalCancelBtn />
|
|
<NormalOkBtn />
|
|
</>
|
|
);
|
|
|
|
if (typeof footer === 'function') {
|
|
footerNode = footer(footerNode, {
|
|
OkBtn: NormalOkBtn,
|
|
CancelBtn: NormalCancelBtn,
|
|
});
|
|
}
|
|
|
|
footerNode = <ModalContextProvider value={btnCtxValueMemo}>{footerNode}</ModalContextProvider>;
|
|
} else {
|
|
footerNode = footer;
|
|
}
|
|
|
|
return <DisabledContextProvider disabled={false}>{footerNode}</DisabledContextProvider>;
|
|
};
|