ant-design/components/modal/components/ConfirmCancelBtn.tsx
MadCcc b284648f11
refactor: fix compiling (#44616)
* refactor: fix compiling

* perf: code logic update
2023-09-04 17:20:30 +08:00

53 lines
1.3 KiB
TypeScript

import type { FC } from 'react';
import React, { useContext } from 'react';
import ActionButton from '../../_util/ActionButton';
import type { ConfirmDialogProps } from '../ConfirmDialog';
import { ModalContext } from '../context';
export interface ConfirmCancelBtnProps
extends Pick<
ConfirmDialogProps,
'cancelButtonProps' | 'isSilent' | 'rootPrefixCls' | 'close' | 'onConfirm' | 'onCancel'
> {
autoFocusButton?: false | 'ok' | 'cancel' | null;
cancelTextLocale?:
| string
| number
| true
| React.ReactElement<any, string | React.JSXElementConstructor<any>>
| Iterable<React.ReactNode>;
mergedOkCancel?: boolean;
}
const ConfirmCancelBtn: FC = () => {
const {
autoFocusButton,
cancelButtonProps,
cancelTextLocale,
isSilent,
mergedOkCancel,
rootPrefixCls,
close,
onCancel,
onConfirm,
} = useContext(ModalContext);
return mergedOkCancel ? (
<ActionButton
isSilent={isSilent}
actionFn={onCancel}
close={(...args: any[]) => {
close?.(...args);
onConfirm?.(false);
}}
autoFocus={autoFocusButton === 'cancel'}
buttonProps={cancelButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{cancelTextLocale}
</ActionButton>
) : null;
};
export default ConfirmCancelBtn;