mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-24 15:46:10 +08:00
b284648f11
* refactor: fix compiling * perf: code logic update
53 lines
1.3 KiB
TypeScript
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;
|