2022-06-07 23:29:12 +08:00
|
|
|
import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled';
|
2023-07-03 20:38:14 +08:00
|
|
|
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
|
|
|
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
|
2022-06-07 23:29:12 +08:00
|
|
|
import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
|
2023-07-03 20:38:14 +08:00
|
|
|
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
|
2022-06-07 23:29:12 +08:00
|
|
|
import classNames from 'classnames';
|
2023-07-03 20:38:14 +08:00
|
|
|
import { Notice } from 'rc-notification';
|
2022-06-07 23:29:12 +08:00
|
|
|
import type { NoticeProps } from 'rc-notification/lib/Notice';
|
2023-07-03 20:38:14 +08:00
|
|
|
import * as React from 'react';
|
2022-06-07 23:29:12 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import type { NoticeType } from './interface';
|
2023-07-03 20:38:14 +08:00
|
|
|
import useStyle from './style';
|
2023-11-13 11:47:07 +08:00
|
|
|
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
2022-06-07 23:29:12 +08:00
|
|
|
|
|
|
|
export const TypeIcon = {
|
|
|
|
info: <InfoCircleFilled />,
|
|
|
|
success: <CheckCircleFilled />,
|
|
|
|
error: <CloseCircleFilled />,
|
|
|
|
warning: <ExclamationCircleFilled />,
|
|
|
|
loading: <LoadingOutlined />,
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface PureContentProps {
|
|
|
|
prefixCls: string;
|
|
|
|
type?: NoticeType;
|
|
|
|
icon?: React.ReactNode;
|
|
|
|
children: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2023-07-03 20:38:14 +08:00
|
|
|
export const PureContent: React.FC<PureContentProps> = ({ prefixCls, type, icon, children }) => (
|
|
|
|
<div className={classNames(`${prefixCls}-custom-content`, `${prefixCls}-${type}`)}>
|
|
|
|
{icon || TypeIcon[type!]}
|
|
|
|
<span>{children}</span>
|
|
|
|
</div>
|
|
|
|
);
|
2022-06-07 23:29:12 +08:00
|
|
|
|
|
|
|
export interface PurePanelProps
|
|
|
|
extends Omit<NoticeProps, 'prefixCls' | 'eventKey'>,
|
|
|
|
Omit<PureContentProps, 'prefixCls' | 'children'> {
|
|
|
|
prefixCls?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @private Internal Component. Do not use in your production. */
|
2023-07-03 20:38:14 +08:00
|
|
|
const PurePanel: React.FC<PurePanelProps> = (props) => {
|
2022-06-07 23:29:12 +08:00
|
|
|
const { prefixCls: staticPrefixCls, className, type, icon, content, ...restProps } = props;
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
|
|
|
|
const prefixCls = staticPrefixCls || getPrefixCls('message');
|
|
|
|
|
2023-11-13 11:47:07 +08:00
|
|
|
const rootCls = useCSSVarCls(prefixCls);
|
2023-11-29 17:23:45 +08:00
|
|
|
const [wrapCSSVar, hashId] = useStyle(prefixCls, rootCls);
|
2022-06-07 23:29:12 +08:00
|
|
|
|
2023-11-13 11:47:07 +08:00
|
|
|
return wrapCSSVar(
|
2022-06-07 23:29:12 +08:00
|
|
|
<Notice
|
|
|
|
{...restProps}
|
|
|
|
prefixCls={prefixCls}
|
2023-11-13 11:47:07 +08:00
|
|
|
className={classNames(className, hashId, `${prefixCls}-notice-pure-panel`, rootCls)}
|
2022-06-07 23:29:12 +08:00
|
|
|
eventKey="pure"
|
|
|
|
duration={null}
|
|
|
|
content={
|
|
|
|
<PureContent prefixCls={prefixCls} type={type} icon={icon}>
|
|
|
|
{content}
|
|
|
|
</PureContent>
|
|
|
|
}
|
2023-11-13 11:47:07 +08:00
|
|
|
/>,
|
2022-06-07 23:29:12 +08:00
|
|
|
);
|
2023-07-03 20:38:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default PurePanel;
|