2022-07-15 15:28:09 +08:00
|
|
|
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
|
|
|
|
import classNames from 'classnames';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2022-07-15 11:11:50 +08:00
|
|
|
import type { PopconfirmProps } from '.';
|
2023-05-11 15:44:55 +08:00
|
|
|
import ActionButton from '../_util/ActionButton';
|
|
|
|
import { getRenderPropValue } from '../_util/getRenderPropValue';
|
2022-07-15 11:11:50 +08:00
|
|
|
import Button from '../button';
|
2023-09-12 11:38:11 +08:00
|
|
|
import { convertLegacyProps } from '../button/buttonHelpers';
|
2022-07-15 11:11:50 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-03-21 13:08:43 +08:00
|
|
|
import { useLocale } from '../locale';
|
2023-05-11 15:44:55 +08:00
|
|
|
import defaultLocale from '../locale/en_US';
|
2022-07-15 15:28:09 +08:00
|
|
|
import PopoverPurePanel from '../popover/PurePanel';
|
|
|
|
import useStyle from './style';
|
2022-07-15 11:11:50 +08:00
|
|
|
|
|
|
|
export interface PopconfirmLocale {
|
|
|
|
okText: string;
|
|
|
|
cancelText: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface OverlayProps
|
|
|
|
extends Pick<
|
|
|
|
PopconfirmProps,
|
|
|
|
| 'icon'
|
|
|
|
| 'okButtonProps'
|
|
|
|
| 'cancelButtonProps'
|
|
|
|
| 'cancelText'
|
|
|
|
| 'okText'
|
|
|
|
| 'okType'
|
|
|
|
| 'showCancel'
|
|
|
|
| 'title'
|
2022-12-08 16:39:42 +08:00
|
|
|
| 'description'
|
2023-05-11 15:44:55 +08:00
|
|
|
| 'onPopupClick'
|
2022-07-15 11:11:50 +08:00
|
|
|
> {
|
|
|
|
prefixCls: string;
|
|
|
|
close?: Function;
|
2022-12-15 17:48:29 +08:00
|
|
|
onConfirm?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
|
|
|
onCancel?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
2022-07-15 11:11:50 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
export const Overlay: React.FC<OverlayProps> = (props) => {
|
2022-07-15 11:11:50 +08:00
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
okButtonProps,
|
|
|
|
cancelButtonProps,
|
|
|
|
title,
|
2022-12-08 16:39:42 +08:00
|
|
|
description,
|
2022-07-15 11:11:50 +08:00
|
|
|
cancelText,
|
|
|
|
okText,
|
2022-07-15 15:28:09 +08:00
|
|
|
okType = 'primary',
|
|
|
|
icon = <ExclamationCircleFilled />,
|
2022-07-15 11:11:50 +08:00
|
|
|
showCancel = true,
|
|
|
|
close,
|
|
|
|
onConfirm,
|
|
|
|
onCancel,
|
2023-05-11 15:44:55 +08:00
|
|
|
onPopupClick,
|
2022-07-15 11:11:50 +08:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
|
2023-02-24 10:51:59 +08:00
|
|
|
const [contextLocale] = useLocale('Popconfirm', defaultLocale.Popconfirm);
|
2023-05-17 14:49:42 +08:00
|
|
|
const theTitle = getRenderPropValue(title);
|
|
|
|
const theDescription = getRenderPropValue(description);
|
2023-02-22 18:18:26 +08:00
|
|
|
|
2022-07-15 11:11:50 +08:00
|
|
|
return (
|
2023-05-11 15:44:55 +08:00
|
|
|
<div className={`${prefixCls}-inner-content`} onClick={onPopupClick}>
|
2023-02-22 18:18:26 +08:00
|
|
|
<div className={`${prefixCls}-message`}>
|
|
|
|
{icon && <span className={`${prefixCls}-message-icon`}>{icon}</span>}
|
2023-05-17 14:49:42 +08:00
|
|
|
<div className={`${prefixCls}-message-text`}>
|
|
|
|
{theTitle && <div className={classNames(`${prefixCls}-title`)}>{theTitle}</div>}
|
|
|
|
{theDescription && <div className={`${prefixCls}-description`}>{theDescription}</div>}
|
2022-07-15 11:11:50 +08:00
|
|
|
</div>
|
2023-02-22 18:18:26 +08:00
|
|
|
</div>
|
|
|
|
<div className={`${prefixCls}-buttons`}>
|
|
|
|
{showCancel && (
|
|
|
|
<Button onClick={onCancel} size="small" {...cancelButtonProps}>
|
|
|
|
{cancelText ?? contextLocale?.cancelText}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
<ActionButton
|
2023-07-18 23:59:53 +08:00
|
|
|
buttonProps={{
|
|
|
|
size: 'small',
|
|
|
|
...convertLegacyProps(okType),
|
|
|
|
...okButtonProps,
|
|
|
|
}}
|
2023-02-22 18:18:26 +08:00
|
|
|
actionFn={onConfirm}
|
|
|
|
close={close}
|
|
|
|
prefixCls={getPrefixCls('btn')}
|
|
|
|
quitOnNullishReturnValue
|
|
|
|
emitEvent
|
|
|
|
>
|
|
|
|
{okText ?? contextLocale?.okText}
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-15 11:11:50 +08:00
|
|
|
);
|
2022-10-01 21:58:46 +08:00
|
|
|
};
|
2022-07-15 15:28:09 +08:00
|
|
|
|
|
|
|
export interface PurePanelProps
|
|
|
|
extends Omit<OverlayProps, 'prefixCls'>,
|
|
|
|
Pick<PopconfirmProps, 'placement'> {
|
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
prefixCls?: string;
|
|
|
|
}
|
|
|
|
|
2023-07-11 23:01:17 +08:00
|
|
|
const PurePanel: React.FC<PurePanelProps> = (props) => {
|
2022-07-15 15:28:09 +08:00
|
|
|
const { prefixCls: customizePrefixCls, placement, className, style, ...restProps } = props;
|
|
|
|
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('popconfirm', customizePrefixCls);
|
|
|
|
const [wrapSSR] = useStyle(prefixCls);
|
|
|
|
|
|
|
|
return wrapSSR(
|
|
|
|
<PopoverPurePanel
|
|
|
|
placement={placement}
|
|
|
|
className={classNames(prefixCls, className)}
|
|
|
|
style={style}
|
2022-12-06 23:14:30 +08:00
|
|
|
content={<Overlay prefixCls={prefixCls} {...restProps} />}
|
|
|
|
/>,
|
2022-07-15 15:28:09 +08:00
|
|
|
);
|
2023-07-11 23:01:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default PurePanel;
|