2023-02-22 18:18:26 +08:00
|
|
|
/* eslint-disable react/jsx-no-useless-fragment */
|
2023-06-06 09:54:14 +08:00
|
|
|
|
2023-08-31 22:21:32 +08:00
|
|
|
import * as React from 'react';
|
2022-06-11 21:39:58 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { Panel } from 'rc-dialog';
|
|
|
|
import type { PanelProps } from 'rc-dialog/lib/Dialog/Content/Panel';
|
2023-08-31 22:21:32 +08:00
|
|
|
|
|
|
|
import { withPureRenderTheme } from '../_util/PurePanel';
|
2022-06-11 21:39:58 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2024-04-08 14:04:08 +08:00
|
|
|
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
2022-07-15 20:51:07 +08:00
|
|
|
import { ConfirmContent } from './ConfirmDialog';
|
2023-06-06 09:54:14 +08:00
|
|
|
import type { ModalFuncProps } from './interface';
|
|
|
|
import { Footer, renderCloseIcon } from './shared';
|
2022-06-11 21:39:58 +08:00
|
|
|
import useStyle from './style';
|
|
|
|
|
2022-07-15 20:51:07 +08:00
|
|
|
export interface PurePanelProps
|
2023-11-08 11:10:35 +08:00
|
|
|
extends Omit<PanelProps, 'prefixCls' | 'footer'>,
|
|
|
|
Pick<ModalFuncProps, 'type' | 'footer'> {
|
2022-06-11 21:39:58 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
}
|
|
|
|
|
2023-02-22 18:18:26 +08:00
|
|
|
const PurePanel: React.FC<PurePanelProps> = (props) => {
|
2022-06-11 21:39:58 +08:00
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
className,
|
|
|
|
closeIcon,
|
2022-07-15 20:51:07 +08:00
|
|
|
closable,
|
|
|
|
type,
|
|
|
|
title,
|
|
|
|
children,
|
2023-11-08 11:10:35 +08:00
|
|
|
footer,
|
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');
|
2023-11-13 15:31:49 +08:00
|
|
|
const rootCls = useCSSVarCls(rootPrefixCls);
|
2023-12-14 14:58:53 +08:00
|
|
|
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
|
2022-06-11 21:39:58 +08:00
|
|
|
|
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}
|
2023-08-31 22:21:32 +08:00
|
|
|
prefixCls={prefixCls}
|
2022-07-15 20:51:07 +08:00
|
|
|
confirmPrefixCls={confirmPrefixCls}
|
|
|
|
rootPrefixCls={rootPrefixCls}
|
|
|
|
content={children}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
additionalProps = {
|
|
|
|
closable: closable ?? true,
|
|
|
|
title,
|
2023-11-08 11:10:35 +08:00
|
|
|
footer: footer !== null && <Footer {...props} />,
|
2022-07-15 20:51:07 +08:00
|
|
|
children,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-13 15:31:49 +08:00
|
|
|
return wrapCSSVar(
|
2022-06-11 21:39:58 +08:00
|
|
|
<Panel
|
|
|
|
prefixCls={prefixCls}
|
2022-07-15 20:51:07 +08:00
|
|
|
className={classNames(
|
|
|
|
hashId,
|
|
|
|
`${prefixCls}-pure-panel`,
|
|
|
|
type && confirmPrefixCls,
|
|
|
|
type && `${confirmPrefixCls}-${type}`,
|
|
|
|
className,
|
2023-12-14 14:58:53 +08:00
|
|
|
cssVarCls,
|
2023-11-13 15:31:49 +08:00
|
|
|
rootCls,
|
2022-07-15 20:51:07 +08:00
|
|
|
)}
|
2022-06-11 21:39:58 +08:00
|
|
|
{...restProps}
|
|
|
|
closeIcon={renderCloseIcon(prefixCls, closeIcon)}
|
|
|
|
closable={closable}
|
2022-07-15 20:51:07 +08:00
|
|
|
{...additionalProps}
|
2023-11-13 15:31:49 +08:00
|
|
|
/>,
|
2022-06-11 21:39:58 +08:00
|
|
|
);
|
2023-02-22 18:18:26 +08:00
|
|
|
};
|
|
|
|
|
2023-08-08 19:48:41 +08:00
|
|
|
export default withPureRenderTheme(PurePanel);
|