2022-06-11 21:39:58 +08:00
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { Panel } from 'rc-dialog';
|
|
|
|
import type { PanelProps } from 'rc-dialog/lib/Dialog/Content/Panel';
|
|
|
|
import * as React from 'react';
|
|
|
|
import Button from '../button';
|
|
|
|
import { convertLegacyProps } from '../button/button';
|
|
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2022-07-15 20:51:07 +08:00
|
|
|
import { ConfirmContent } from './ConfirmDialog';
|
2022-06-11 21:39:58 +08:00
|
|
|
import { getConfirmLocale } from './locale';
|
2022-07-15 20:51:07 +08:00
|
|
|
import type { ModalProps, ModalFuncProps } from './Modal';
|
2022-06-11 21:39:58 +08:00
|
|
|
import useStyle from './style';
|
|
|
|
|
2022-07-15 20:51:07 +08:00
|
|
|
export interface PurePanelProps
|
|
|
|
extends Omit<PanelProps, 'prefixCls'>,
|
|
|
|
Pick<ModalFuncProps, 'type'> {
|
2022-06-11 21:39:58 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function renderCloseIcon(prefixCls: string, closeIcon?: React.ReactNode) {
|
|
|
|
return (
|
|
|
|
<span className={`${prefixCls}-close-x`}>
|
|
|
|
{closeIcon || <CloseOutlined className={`${prefixCls}-close-icon`} />}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function renderFooter(
|
|
|
|
props: Pick<
|
|
|
|
ModalProps,
|
|
|
|
| 'footer'
|
|
|
|
| 'okText'
|
|
|
|
| 'okType'
|
|
|
|
| 'cancelText'
|
|
|
|
| 'confirmLoading'
|
|
|
|
| 'okButtonProps'
|
|
|
|
| 'cancelButtonProps'
|
|
|
|
> & {
|
|
|
|
onOk?: React.MouseEventHandler;
|
|
|
|
onCancel?: React.MouseEventHandler;
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
const {
|
|
|
|
okText,
|
|
|
|
okType = 'primary',
|
|
|
|
cancelText,
|
|
|
|
confirmLoading,
|
|
|
|
onOk,
|
|
|
|
onCancel,
|
|
|
|
okButtonProps,
|
|
|
|
cancelButtonProps,
|
|
|
|
footer,
|
|
|
|
} = props;
|
|
|
|
|
2022-10-21 10:16:03 +08:00
|
|
|
return footer === undefined ? (
|
|
|
|
<LocaleReceiver componentName="Modal" defaultLocale={getConfirmLocale()}>
|
2022-11-19 13:47:33 +08:00
|
|
|
{(locale) => (
|
2022-10-21 10:16:03 +08:00
|
|
|
<>
|
|
|
|
<Button onClick={onCancel} {...cancelButtonProps}>
|
|
|
|
{cancelText || locale!.cancelText}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
{...convertLegacyProps(okType)}
|
|
|
|
loading={confirmLoading}
|
|
|
|
onClick={onOk}
|
|
|
|
{...okButtonProps}
|
|
|
|
>
|
|
|
|
{okText || locale!.okText}
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</LocaleReceiver>
|
|
|
|
) : (
|
|
|
|
footer
|
2022-06-11 21:39:58 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function PurePanel(props: PurePanelProps) {
|
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
className,
|
|
|
|
closeIcon,
|
2022-07-15 20:51:07 +08:00
|
|
|
closable,
|
|
|
|
type,
|
|
|
|
title,
|
|
|
|
children,
|
2022-06-11 21:39:58 +08:00
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
|
2022-07-15 20:51:07 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
2022-06-11 21:39:58 +08:00
|
|
|
const prefixCls = customizePrefixCls || getPrefixCls('modal');
|
|
|
|
|
|
|
|
const [, hashId] = useStyle(prefixCls);
|
|
|
|
|
2022-07-15 20:51:07 +08:00
|
|
|
const confirmPrefixCls = `${prefixCls}-confirm`;
|
|
|
|
|
|
|
|
// Choose target props by confirm mark
|
|
|
|
let additionalProps: Partial<PanelProps> = {};
|
|
|
|
if (type) {
|
|
|
|
additionalProps = {
|
|
|
|
closable: closable ?? false,
|
|
|
|
title: '',
|
|
|
|
footer: '',
|
|
|
|
children: (
|
|
|
|
<ConfirmContent
|
|
|
|
{...props}
|
|
|
|
confirmPrefixCls={confirmPrefixCls}
|
|
|
|
rootPrefixCls={rootPrefixCls}
|
|
|
|
content={children}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
additionalProps = {
|
|
|
|
closable: closable ?? true,
|
|
|
|
title,
|
|
|
|
footer: renderFooter(props),
|
|
|
|
children,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-11 21:39:58 +08:00
|
|
|
return (
|
|
|
|
<Panel
|
|
|
|
prefixCls={prefixCls}
|
2022-07-15 20:51:07 +08:00
|
|
|
className={classNames(
|
|
|
|
hashId,
|
|
|
|
`${prefixCls}-pure-panel`,
|
|
|
|
type && confirmPrefixCls,
|
|
|
|
type && `${confirmPrefixCls}-${type}`,
|
|
|
|
className,
|
|
|
|
)}
|
2022-06-11 21:39:58 +08:00
|
|
|
{...restProps}
|
|
|
|
closeIcon={renderCloseIcon(prefixCls, closeIcon)}
|
|
|
|
closable={closable}
|
2022-07-15 20:51:07 +08:00
|
|
|
{...additionalProps}
|
2022-06-11 21:39:58 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|