import classNames from 'classnames'; import type { DrawerProps as RCDrawerProps } from 'rc-drawer'; import * as React from 'react'; import useClosable from '../_util/hooks/useClosable'; export interface DrawerPanelProps { prefixCls: string; title?: React.ReactNode; footer?: React.ReactNode; extra?: React.ReactNode; /** * Recommend to use closeIcon instead * * e.g. * * `` */ closable?: boolean; closeIcon?: boolean | 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; } const DrawerPanel: React.FC = (props) => { const { prefixCls, title, footer, extra, closeIcon, closable, onClose, headerStyle, drawerStyle, bodyStyle, footerStyle, children, } = props; const customCloseIconRender = React.useCallback( (icon: React.ReactNode) => ( {icon} ), [onClose], ); const [mergedClosable, mergedCloseIcon] = useClosable( closable, closeIcon, customCloseIconRender, undefined, true, ); const headerNode = React.useMemo(() => { if (!title && !mergedClosable) { return null; } return ( {mergedCloseIcon} {title && {title}} {extra && {extra}} ); }, [mergedClosable, mergedCloseIcon, extra, headerStyle, prefixCls, title]); const footerNode = React.useMemo(() => { if (!footer) { return null; } const footerClassName = `${prefixCls}-footer`; return ( {footer} ); }, [footer, footerStyle, prefixCls]); return ( {headerNode} {children} {footerNode} ); }; export default DrawerPanel;