2022-09-21 16:35:01 +08:00
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
import classNames from 'classnames';
|
2023-03-30 14:55:34 +08:00
|
|
|
import type { DrawerProps as RCDrawerProps } from 'rc-drawer';
|
|
|
|
import * as React from 'react';
|
2022-09-21 16:35:01 +08:00
|
|
|
|
|
|
|
export interface DrawerPanelProps {
|
|
|
|
prefixCls: string;
|
|
|
|
|
|
|
|
title?: React.ReactNode;
|
|
|
|
footer?: React.ReactNode;
|
|
|
|
extra?: React.ReactNode;
|
|
|
|
|
|
|
|
closable?: boolean;
|
|
|
|
closeIcon?: React.ReactNode;
|
|
|
|
onClose?: RCDrawerProps['onClose'];
|
|
|
|
|
|
|
|
/** Wrapper dom node style of header and body */
|
|
|
|
drawerStyle?: React.CSSProperties;
|
|
|
|
headerStyle?: React.CSSProperties;
|
|
|
|
bodyStyle?: React.CSSProperties;
|
|
|
|
footerStyle?: React.CSSProperties;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2023-03-30 14:55:34 +08:00
|
|
|
const DrawerPanel: React.FC<DrawerPanelProps> = (props) => {
|
2022-09-21 16:35:01 +08:00
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
title,
|
|
|
|
footer,
|
|
|
|
extra,
|
|
|
|
closable = true,
|
|
|
|
closeIcon = <CloseOutlined />,
|
|
|
|
onClose,
|
|
|
|
headerStyle,
|
|
|
|
drawerStyle,
|
|
|
|
bodyStyle,
|
|
|
|
footerStyle,
|
|
|
|
children,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const closeIconNode = closable && (
|
|
|
|
<button type="button" onClick={onClose} aria-label="Close" className={`${prefixCls}-close`}>
|
|
|
|
{closeIcon}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
|
2023-03-30 14:55:34 +08:00
|
|
|
const headerNode = React.useMemo<React.ReactNode>(() => {
|
2022-09-21 16:35:01 +08:00
|
|
|
if (!title && !closable) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div
|
2023-03-30 14:55:34 +08:00
|
|
|
style={headerStyle}
|
2022-09-21 16:35:01 +08:00
|
|
|
className={classNames(`${prefixCls}-header`, {
|
|
|
|
[`${prefixCls}-header-close-only`]: closable && !title && !extra,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className={`${prefixCls}-header-title`}>
|
|
|
|
{closeIconNode}
|
|
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
|
|
|
</div>
|
|
|
|
{extra && <div className={`${prefixCls}-extra`}>{extra}</div>}
|
|
|
|
</div>
|
|
|
|
);
|
2023-03-30 14:55:34 +08:00
|
|
|
}, [closable, closeIconNode, extra, headerStyle, prefixCls, title]);
|
2022-09-21 16:35:01 +08:00
|
|
|
|
2023-03-30 14:55:34 +08:00
|
|
|
const footerNode = React.useMemo<React.ReactNode>(() => {
|
2022-09-21 16:35:01 +08:00
|
|
|
if (!footer) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const footerClassName = `${prefixCls}-footer`;
|
|
|
|
return (
|
|
|
|
<div className={footerClassName} style={footerStyle}>
|
|
|
|
{footer}
|
|
|
|
</div>
|
|
|
|
);
|
2023-03-30 14:55:34 +08:00
|
|
|
}, [footer, footerStyle, prefixCls]);
|
2022-09-21 16:35:01 +08:00
|
|
|
|
|
|
|
return (
|
2023-03-30 14:55:34 +08:00
|
|
|
<div className={`${prefixCls}-wrapper-body`} style={drawerStyle}>
|
|
|
|
{headerNode}
|
2022-09-21 16:35:01 +08:00
|
|
|
<div className={`${prefixCls}-body`} style={bodyStyle}>
|
|
|
|
{children}
|
|
|
|
</div>
|
2023-03-30 14:55:34 +08:00
|
|
|
{footerNode}
|
2022-09-21 16:35:01 +08:00
|
|
|
</div>
|
|
|
|
);
|
2023-03-30 14:55:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DrawerPanel;
|