mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 09:21:22 +08:00
cc5c4fed51
* chore: add locale files to npm pkg * docs: locale files reference path * docs: fix locale path * chore: bump @ant-design/tools * refactor: default locale file * chore: add site wepack alias * chore: bump @ant-design/tools * fix: site theme locale reference path * chore: add locale files to eslint ignore * fix: markdown demo unable to resolve path to module antd/locale
113 lines
3.3 KiB
TypeScript
113 lines
3.3 KiB
TypeScript
import * as React from 'react';
|
|
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
|
|
import classNames from 'classnames';
|
|
import type { PopconfirmProps } from '.';
|
|
import Button from '../button';
|
|
import { convertLegacyProps } from '../button/button';
|
|
import ActionButton from '../_util/ActionButton';
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
import defaultLocale from '../locale/en_US';
|
|
import { getRenderPropValue } from '../_util/getRenderPropValue';
|
|
import { ConfigContext } from '../config-provider';
|
|
import PopoverPurePanel from '../popover/PurePanel';
|
|
|
|
import useStyle from './style';
|
|
|
|
export interface PopconfirmLocale {
|
|
okText: string;
|
|
cancelText: string;
|
|
}
|
|
|
|
export interface OverlayProps
|
|
extends Pick<
|
|
PopconfirmProps,
|
|
| 'icon'
|
|
| 'okButtonProps'
|
|
| 'cancelButtonProps'
|
|
| 'cancelText'
|
|
| 'okText'
|
|
| 'okType'
|
|
| 'showCancel'
|
|
| 'title'
|
|
> {
|
|
prefixCls: string;
|
|
close?: Function;
|
|
onConfirm?: React.MouseEventHandler<HTMLButtonElement>;
|
|
onCancel?: React.MouseEventHandler<HTMLButtonElement>;
|
|
}
|
|
|
|
export const Overlay: React.FC<OverlayProps> = props => {
|
|
const {
|
|
prefixCls,
|
|
okButtonProps,
|
|
cancelButtonProps,
|
|
title,
|
|
cancelText,
|
|
okText,
|
|
okType = 'primary',
|
|
icon = <ExclamationCircleFilled />,
|
|
showCancel = true,
|
|
close,
|
|
onConfirm,
|
|
onCancel,
|
|
} = props;
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
return (
|
|
<LocaleReceiver componentName="Popconfirm" defaultLocale={defaultLocale.Popconfirm}>
|
|
{contextLocale => (
|
|
<div className={`${prefixCls}-inner-content`}>
|
|
<div className={`${prefixCls}-message`}>
|
|
{icon && <span className={`${prefixCls}-message-icon`}>{icon}</span>}
|
|
<div className={`${prefixCls}-message-title`}>{getRenderPropValue(title)}</div>
|
|
</div>
|
|
<div className={`${prefixCls}-buttons`}>
|
|
{showCancel && (
|
|
<Button onClick={onCancel} size="small" {...cancelButtonProps}>
|
|
{cancelText ?? contextLocale.cancelText}
|
|
</Button>
|
|
)}
|
|
<ActionButton
|
|
buttonProps={{ size: 'small', ...convertLegacyProps(okType), ...okButtonProps }}
|
|
actionFn={onConfirm}
|
|
close={close}
|
|
prefixCls={getPrefixCls('btn')}
|
|
quitOnNullishReturnValue
|
|
emitEvent
|
|
>
|
|
{okText ?? contextLocale.okText}
|
|
</ActionButton>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</LocaleReceiver>
|
|
);
|
|
};
|
|
|
|
export interface PurePanelProps
|
|
extends Omit<OverlayProps, 'prefixCls'>,
|
|
Pick<PopconfirmProps, 'placement'> {
|
|
className?: string;
|
|
style?: React.CSSProperties;
|
|
prefixCls?: string;
|
|
}
|
|
|
|
export default function PurePanel(props: PurePanelProps) {
|
|
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}
|
|
>
|
|
<Overlay {...restProps} prefixCls={prefixCls} />
|
|
</PopoverPurePanel>,
|
|
);
|
|
}
|