@@ -22,7 +22,7 @@ export enum DrawerType {
22
22
Normal = 'normal' ,
23
23
}
24
24
25
- interface NormalDrawerProps extends Omit < AntdDrawerProps , 'placement' > {
25
+ interface BaseDrawerProps extends Omit < AntdDrawerProps , 'placement' | 'children '> {
26
26
size ?: 'small' | 'default' | 'large' ;
27
27
loading ?: boolean ;
28
28
bodyClassName ?: string ;
@@ -33,35 +33,35 @@ interface NormalDrawerProps extends Omit<AntdDrawerProps, 'placement'> {
33
33
type ?: DrawerType ;
34
34
}
35
35
36
- interface TabsDrawerProps < T extends readOnlyTab > extends Omit < NormalDrawerProps , 'children' > {
36
+ export interface DrawerProps < T extends readOnlyTab = any > extends BaseDrawerProps {
37
37
tabs ?: T ;
38
38
defaultKey ?: TabKey < T > ;
39
39
activeKey ?: TabKey < T > ;
40
- children ?: ( key : TabKey < T > ) => React . ReactNode ;
40
+ children ?: React . ReactNode | ( ( key : TabKey < T > ) => React . ReactNode ) ;
41
41
onChange ?: ( key : TabKey < T > ) => void ;
42
42
}
43
43
44
- function isFunction < T extends readOnlyTab > ( props : DrawerProps < T > ) : props is TabsDrawerProps < T > {
44
+ function isFunction < T extends readOnlyTab > (
45
+ props : DrawerProps < T >
46
+ ) : props is DrawerProps < T > & { children : ( key : string ) => React . ReactNode } {
45
47
return typeof props . children === 'function' ;
46
48
}
47
49
48
- function isTabMode < T extends readOnlyTab > ( props : DrawerProps < T > ) : props is TabsDrawerProps < T > {
50
+ function isTabMode < T extends readOnlyTab > ( props : DrawerProps < T > ) : props is DrawerProps < T > {
49
51
return 'tabs' in props ;
50
52
}
51
53
52
- function isControlled < T extends readOnlyTab > ( props : DrawerProps < T > ) : props is TabsDrawerProps < T > {
54
+ function isControlled < T extends readOnlyTab > ( props : DrawerProps < T > ) : props is DrawerProps < T > {
53
55
return 'activeKey' in props ;
54
56
}
55
57
56
- export type DrawerProps < T extends readOnlyTab > = TabsDrawerProps < T > | NormalDrawerProps ;
57
-
58
- const getWidthFromSize = ( size : NormalDrawerProps [ 'size' ] ) => {
58
+ const getWidthFromSize = ( size : DrawerProps [ 'size' ] ) => {
59
59
if ( size === 'small' ) return 720 ;
60
60
if ( size === 'large' ) return 1256 ;
61
61
return 1000 ;
62
62
} ;
63
63
64
- const isValidBanner = ( banner : NormalDrawerProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
64
+ const isValidBanner = ( banner : DrawerProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
65
65
if ( typeof banner === 'object' ) return React . isValidElement ( banner ) ;
66
66
return true ;
67
67
} ;
@@ -163,7 +163,9 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
163
163
className = { classNames ( `${ slidePrefixCls } -body` , bodyClassName ) }
164
164
style = { bodyStyle }
165
165
>
166
- { isFunction ( props ) ? props . children ?.( currentKey ?? '' ) : props . children }
166
+ { isFunction ( props )
167
+ ? props . children ?.( currentKey ?? '' )
168
+ : ( props . children as React . ReactNode ) }
167
169
</ div >
168
170
{ footer ? (
169
171
< div className = { classNames ( `${ slidePrefixCls } -footer` ) } > { footer } </ div >
0 commit comments