mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 11:08:45 +08:00
59ad48476b
* chore: add boime lint * fix lint * use files ignore * revert change * ignore clarity.js * fix some errors * fix some errors * fix some errors * fix some errors * add yml file * Update clarity.js Signed-off-by: afc163 <afc163@gmail.com> * add npm run lint:biome * add npm run lint:biome * fix test case * fix ts errors * fix ts errors * fix lint and add .lintstagedrc * shorten prop name * chore: update package.json * update biome.json * chore: remove stylelint * chore: useOptionalChain * fix lint * biome format * prettier all code * prettier all code * fix site test --------- Signed-off-by: afc163 <afc163@gmail.com>
94 lines
2.5 KiB
TypeScript
94 lines
2.5 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: React.ReactNode;
|
|
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>;
|
|
};
|