11import React , { CSSProperties , useEffect , useState } from 'react' ;
2+ import { CloseOutlined } from '@ant-design/icons' ;
23import { Alert , AlertProps , Spin , Tabs } from 'antd' ;
34import classNames from 'classnames' ;
45import { omit } from 'lodash' ;
@@ -16,16 +17,20 @@ type readOnlyTab = readonly Tab[];
1617
1718type TabKey < T extends readOnlyTab > = T [ number ] [ 'key' ] ;
1819
20+ export enum DrawerType {
21+ Form = 'form' ,
22+ Normal = 'normal' ,
23+ }
24+
1925interface NormalDrawerProps extends Omit < AntdDrawerProps , 'placement' > {
20- /** @deprecated */
21- visible ?: boolean ;
2226 size ?: 'small' | 'default' | 'large' ;
2327 loading ?: boolean ;
2428 bodyClassName ?: string ;
2529 title ?: React . ReactNode ;
2630 bodyStyle ?: CSSProperties ;
2731 footer ?: React . ReactNode ;
2832 banner ?: AlertProps [ 'message' ] | Omit < AlertProps , 'banner' > ;
33+ type ?: DrawerType ;
2934}
3035
3136interface TabsDrawerProps < T extends readOnlyTab > extends Omit < NormalDrawerProps , 'children' > {
@@ -65,31 +70,32 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
6570 const slidePrefixCls = 'dtc-drawer' ;
6671
6772 const {
68- visible,
6973 open,
7074 loading = false ,
7175 bodyClassName,
7276 mask = false ,
77+ maskClosable = true ,
7378 bodyStyle,
7479 title,
7580 width,
81+ type = DrawerType . Normal ,
7682 size = 'default' ,
7783 footer,
7884 banner,
7985 onClose,
8086 ...rest
8187 } = props ;
8288
83- const composeOpen = open || visible ;
8489 const finalWidth = width ?? getWidthFromSize ( size ) ;
90+ const isFormType = type === DrawerType . Form ;
8591
8692 const [ internalTabKey , setInternalTabKey ] = useState ( '' ) ;
8793
8894 useEffect ( ( ) => {
89- composeOpen &&
95+ open &&
9096 isTabMode ( props ) &&
9197 setInternalTabKey ( props . defaultKey ?? props . tabs ?. [ 0 ] ?. key ?? '' ) ;
92- } , [ composeOpen ] ) ;
98+ } , [ open ] ) ;
9399
94100 const currentKey = isControlled ( props ) ? props . activeKey : internalTabKey ;
95101
@@ -111,21 +117,32 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
111117
112118 return (
113119 < RcDrawer
114- open = { composeOpen }
120+ open = { open }
115121 placement = "right"
116- mask = { mask }
122+ mask = { isFormType ? true : mask }
123+ maskClosable = { isFormType ? false : maskClosable }
117124 width = { finalWidth }
118125 prefixCls = { slidePrefixCls }
119126 onClose = { onClose }
120127 { ...rest }
121128 { ...motionProps }
122129 >
123- { ! mask && renderButton ( ) }
130+ { ! isFormType && renderButton ( ) }
124131 < Spin wrapperClassName = { `${ slidePrefixCls } -nested-loading` } spinning = { loading } >
125- { title && < div className = { `${ slidePrefixCls } -header` } > { title } </ div > }
132+ { title && (
133+ < div className = { `${ slidePrefixCls } -header` } >
134+ { title }
135+ { isFormType && (
136+ < CloseOutlined
137+ className = { `${ slidePrefixCls } -header--icon` }
138+ onClick = { onClose }
139+ />
140+ ) }
141+ </ div >
142+ ) }
126143 { banner && (
127144 < Alert
128- message = { isValidBanner ( banner ) ? banner : banner . message }
145+ message = { isValidBanner ( banner ) ? banner : ( banner as any ) . message }
129146 banner
130147 { ...( isValidBanner ( banner ) ? { } : omit ( banner , 'message' ) ) }
131148 />
0 commit comments