1
1
import React , { RefObject , useEffect , useImperativeHandle , useState } from 'react' ;
2
2
import cx from 'classnames' ;
3
+ import { isNull } from 'lodash' ;
3
4
import { Close } from '@kubed/icons' ;
4
5
import { StyledDialog } from './Modal.styles' ;
5
6
import { ButtonProps , Button } from '../Button/Button' ;
@@ -101,8 +102,7 @@ interface ModalRef {
101
102
102
103
export type ModalType = 'info' | 'success' | 'error' | 'warn' | 'warning' | 'confirm' | 'open' ;
103
104
104
- export interface ModalFuncProps
105
- extends Omit < ModalProps , 'footer' | 'forceRender' | 'destroyOnClose' > {
105
+ export interface ModalFuncProps extends Omit < ModalProps , 'forceRender' | 'destroyOnClose' > {
106
106
content ?: React . ReactNode ;
107
107
icon ?: React . ReactNode ;
108
108
type ?: ModalType ;
@@ -126,8 +126,17 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
126
126
onOk ?.( e ) ;
127
127
} ;
128
128
129
+ const renderHeader = ( ) => {
130
+ const { header, title, description, titleIcon } = props ;
131
+ if ( header || isNull ( header ) ) return header ;
132
+
133
+ return < Field value = { title } label = { description } avatar = { titleIcon } /> ;
134
+ } ;
135
+
129
136
const renderFooter = ( ) => {
130
- const { okText, cancelText, confirmLoading, cancelButtonProps, okButtonProps } = props ;
137
+ const { footer, okText, cancelText, confirmLoading, cancelButtonProps, okButtonProps } = props ;
138
+ if ( footer || isNull ( footer ) ) return footer ;
139
+
131
140
return (
132
141
< >
133
142
< Button onClick = { handleCancel } radius = "xl" { ...cancelButtonProps } >
@@ -148,18 +157,13 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
148
157
} ;
149
158
150
159
const {
151
- footer,
152
160
visible,
153
161
centered = true ,
154
162
getContainer,
155
163
closeIcon,
156
164
focusTriggerAfterClose = true ,
157
165
width = 600 ,
158
166
wrapClassName,
159
- header,
160
- title,
161
- description,
162
- titleIcon,
163
167
...restProps
164
168
} = props ;
165
169
const [ internalVisible , setInternalVisible ] = useState ( visible ) ;
@@ -178,8 +182,6 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
178
182
179
183
const renderCloseIcon = < > { closeIcon || < Close size = { 24 } /> } </ > ;
180
184
181
- const renderHeader = header || < Field value = { title } label = { description } avatar = { titleIcon } /> ;
182
-
183
185
return (
184
186
< StyledDialog
185
187
{ ...restProps }
@@ -190,8 +192,8 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
190
192
width = { width }
191
193
closeIcon = { renderCloseIcon }
192
194
onClose = { handleCancel }
193
- title = { renderHeader }
194
- footer = { footer || renderFooter ( ) }
195
+ title = { renderHeader ( ) }
196
+ footer = { renderFooter ( ) }
195
197
transitionName = { getTransitionName ( 'kubed' , 'zoom' , props . transitionName ) }
196
198
maskTransitionName = { getTransitionName ( 'kubed' , 'fade' , props . maskTransitionName ) }
197
199
/>
0 commit comments