@@ -22,6 +22,12 @@ export enum DrawerType {
22
22
Normal = 'normal' ,
23
23
}
24
24
25
+ enum DrawerSize {
26
+ Small = 720 ,
27
+ Default = 1000 ,
28
+ Large = 1256 ,
29
+ }
30
+
25
31
interface NormalDrawerProps extends Omit < AntdDrawerProps , 'placement' > {
26
32
size ?: 'small' | 'default' | 'large' ;
27
33
loading ?: boolean ;
@@ -53,12 +59,12 @@ function isControlled<T extends readOnlyTab>(props: DrawerProps<T>): props is Ta
53
59
return 'activeKey' in props ;
54
60
}
55
61
56
- export type DrawerProps < T extends readOnlyTab > = TabsDrawerProps < T > | NormalDrawerProps ;
62
+ export type DrawerProps < T extends readOnlyTab = any > = TabsDrawerProps < T > | NormalDrawerProps ;
57
63
58
64
const getWidthFromSize = ( size : NormalDrawerProps [ 'size' ] ) => {
59
- if ( size === 'small' ) return 720 ;
60
- if ( size === 'large' ) return 1256 ;
61
- return 1000 ;
65
+ if ( size === 'small' ) return ` ${ ( DrawerSize . Small / 1400 ) * 100 } %` ;
66
+ if ( size === 'large' ) return ` ${ ( DrawerSize . Large / 1400 ) * 100 } %` ;
67
+ return ` ${ ( DrawerSize . Default / 1400 ) * 100 } %` ;
62
68
} ;
63
69
64
70
const isValidBanner = ( banner : NormalDrawerProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
@@ -67,7 +73,7 @@ const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProp
67
73
} ;
68
74
69
75
const Drawer = < T extends readOnlyTab > ( props : DrawerProps < T > ) => {
70
- const slidePrefixCls = 'dtc-drawer' ;
76
+ const drawerPrefixCls = 'dtc-drawer' ;
71
77
72
78
const {
73
79
open,
@@ -89,7 +95,7 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
89
95
const finalWidth = width ?? getWidthFromSize ( size ) ;
90
96
const isFormType = type === DrawerType . Form ;
91
97
92
- const [ internalTabKey , setInternalTabKey ] = useState ( '' ) ;
98
+ const [ internalTabKey , setInternalTabKey ] = useState < TabKey < T > > ( '' ) ;
93
99
94
100
useEffect ( ( ) => {
95
101
open &&
@@ -102,7 +108,7 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
102
108
const renderButton = ( ) => {
103
109
return (
104
110
< img
105
- className = { `${ slidePrefixCls } -icon` }
111
+ className = { `${ drawerPrefixCls } -icon` }
106
112
onClick = { onClose }
107
113
src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAABwCAYAAAAE0LDPAAAAAXNSR0IArs4c6QAAAnlJREFUaEPtmk9IVHEQx78jufpw7ykouuEaBG6dEmrXOmRRt476VgvyEngKlNqQMu3PoSU7iCBq4CW2olNdRMRr7HasnnZb0y57WGODzUDjt/RIonbeyzfQYd51h/m8+c7395u3MOSs5Xexr4dKRLt5AhYJtbPRaNO7velo/4Bf6YhoB8B0R3vzNSLaNr8ECnBRRLTc0d583kBEAJU3J5o6HG0ZkgTs1OBATAxgqqghTIoCiPBeFABQSRggZFOxg/anC0ElYq9JlUglYhVgA9RFKhGrABugLlKJWAXYAHWRSsQqwAaoi1QiVgE2gHVRejKDUKgWQ1cvmj/XbMLfA3jA42dwVvPo7+tBd/xo8ICNzQLG7y3AskIYvz2IcEO9LwhbgcmWebGCpeUcEvEYBvrOBg8ol7cxOjaP4lYJqZEkIm2NniGeKjDZ3mQ/YPbJa7S1NiI1YntuuGeAgTx8lMHqx3XYvWdwOnHMUxW+AJufC7hzdwH1VggTt64gHLZYiC+Ayfb85QoWl3KIn+jEpeS54AHlb98xOjaHYrGEG8M2DkWaqkJ8V2CyZd86mJl7hdaWg7h5PVm14f8EMJD0zxM+ePkCuo4f+WsV/ycgm3MwMy8k0d4mp4ZtRIJusmvTxMlODNgB21T8oLlXRbK3B6cS3maDZxeJXnbudb315Wvl9AZ+XbsDpzseQ3/QA+fTRgET9wVHpvmqcNbWK6PSjEy/D9vkB+mnaLDq5D5b/L6x7+8iBbBNVolUItYDKpFKxCrABqiLVCJWATZAXaQSsQqwAeoilYhVgA1QFzESCS8wia9giS6Rma1B0TU40UU+sVVEoWXK6uugPwBjVkdxauLcgwAAAABJRU5ErkJggg=="
108
114
alt = "closeBtn"
@@ -122,19 +128,19 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
122
128
mask = { isFormType ? true : mask }
123
129
maskClosable = { isFormType ? false : maskClosable }
124
130
width = { finalWidth }
125
- prefixCls = { slidePrefixCls }
131
+ prefixCls = { drawerPrefixCls }
126
132
onClose = { onClose }
127
133
{ ...rest }
128
134
{ ...motionProps }
129
135
>
130
136
{ ! isFormType && renderButton ( ) }
131
- < Spin wrapperClassName = { `${ slidePrefixCls } -nested-loading` } spinning = { loading } >
137
+ < Spin wrapperClassName = { `${ drawerPrefixCls } -nested-loading` } spinning = { loading } >
132
138
{ title && (
133
- < div className = { `${ slidePrefixCls } -header` } >
139
+ < div className = { `${ drawerPrefixCls } -header` } >
134
140
{ title }
135
141
{ isFormType && (
136
142
< CloseOutlined
137
- className = { `${ slidePrefixCls } -header--icon` }
143
+ className = { `${ drawerPrefixCls } -header--icon` }
138
144
onClick = { onClose }
139
145
/>
140
146
) }
@@ -152,21 +158,21 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
152
158
destroyInactiveTabPane
153
159
activeKey = { currentKey }
154
160
onChange = { handleChangeKey }
155
- className = { `${ slidePrefixCls } -tabs` }
161
+ className = { `${ drawerPrefixCls } -tabs` }
156
162
>
157
163
{ props . tabs ?. map ( ( tab : { key : string ; title : React . ReactNode } ) => (
158
164
< Tabs . TabPane tab = { tab . title } key = { tab . key } />
159
165
) ) }
160
166
</ Tabs >
161
167
) }
162
168
< div
163
- className = { classNames ( `${ slidePrefixCls } -body` , bodyClassName ) }
169
+ className = { classNames ( `${ drawerPrefixCls } -body` , bodyClassName ) }
164
170
style = { bodyStyle }
165
171
>
166
172
{ isFunction ( props ) ? props . children ?.( currentKey ?? '' ) : props . children }
167
173
</ div >
168
174
{ footer ? (
169
- < div className = { classNames ( `${ slidePrefixCls } -footer` ) } > { footer } </ div >
175
+ < div className = { classNames ( `${ drawerPrefixCls } -footer` ) } > { footer } </ div >
170
176
) : null }
171
177
</ Spin >
172
178
</ RcDrawer >
0 commit comments