feat: add showCancel prop for popconfirm (#32620)

Co-authored-by: machixian <machixian@myweimai.com>
This commit is contained in:
WeijieChen 2021-10-26 19:12:08 +08:00 committed by GitHub
parent 2769f44536
commit 16bb5489e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View File

@ -24,6 +24,7 @@ The difference with the `confirm` modal dialog is that it's more lightweight tha
| okButtonProps | The ok button props | [ButtonProps](/components/button/#API) | - |
| okText | The text of the Confirm button | string | `OK` |
| okType | Button `type` of the Confirm button | string | `primary` |
| showCancel | Show cancel button | boolean | true |
| title | The title of the confirmation box | ReactNode \| () => ReactNode | - |
| onCancel | A callback of cancel | function(e) | - |
| onConfirm | A callback of confirmation | function(e) | - |

View File

@ -24,6 +24,7 @@ export interface PopconfirmProps extends AbstractTooltipProps {
cancelText?: React.ReactNode;
okButtonProps?: ButtonProps;
cancelButtonProps?: ButtonProps;
showCancel?: boolean;
icon?: React.ReactNode;
onVisibleChange?: (
visible: boolean,
@ -82,7 +83,16 @@ const Popconfirm = React.forwardRef<unknown, PopconfirmProps>((props, ref) => {
};
const renderOverlay = (prefixCls: string, popconfirmLocale: PopconfirmLocale) => {
const { okButtonProps, cancelButtonProps, title, cancelText, okText, okType, icon } = props;
const {
okButtonProps,
cancelButtonProps,
title,
cancelText,
okText,
okType,
icon,
showCancel = true,
} = props;
return (
<div className={`${prefixCls}-inner-content`}>
<div className={`${prefixCls}-message`}>
@ -90,9 +100,11 @@ const Popconfirm = React.forwardRef<unknown, PopconfirmProps>((props, ref) => {
<div className={`${prefixCls}-message-title`}>{getRenderPropValue(title)}</div>
</div>
<div className={`${prefixCls}-buttons`}>
{showCancel && (
<Button onClick={onCancel} size="small" {...cancelButtonProps}>
{cancelText || popconfirmLocale.cancelText}
</Button>
)}
<ActionButton
buttonProps={{ size: 'small', ...convertLegacyProps(okType), ...okButtonProps }}
actionFn={onConfirm}

View File

@ -25,6 +25,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/fjMCD9xRq/Popconfirm.svg
| okButtonProps | ok 按钮 props | [ButtonProps](/components/button/#API) | - |
| okText | 确认按钮文字 | string | `确定` |
| okType | 确认按钮类型 | string | `primary` |
| showCancel | 是否显示取消按钮 | boolean | true |
| title | 确认框的描述 | ReactNode \| () => ReactNode | - |
| onCancel | 点击取消的回调 | function(e) | - |
| onConfirm | 点击确认的回调 | function(e) | - |