8000 refactor(CModal): improve and clean-up syntax · lunaluna2021/coreui-react@18e2cd3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18e2cd3

Browse files
committed
refactor(CModal): improve and clean-up syntax
1 parent 4da20ab commit 18e2cd3

File tree

1 file changed

+12
-52
lines changed
  • packages/coreui-react/src/components/modal

1 file changed

+12
-52
lines changed

packages/coreui-react/src/components/modal/CModal.tsx

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, {
22
createContext,
33
forwardRef,
44
HTMLAttributes,
5-
useCallback,
65
useEffect,
76
useLayoutEffect,
87
useRef,
@@ -142,6 +141,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
142141
if (backdrop === 'static') {
143142
return setStaticBackdrop(true)
144143
}
144+
145145
return onClose && onClose()
146146
}
147147

@@ -164,7 +164,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
164164
() => {
165165
modalRef.current?.focus()
166166
},
167-
!transition ? 0 : duration,
167+
transition ? duration : 0,
168168
)
169169
} else {
170170
document.body.classList.remove('modal-open')
@@ -192,48 +192,11 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
192192
}
193193
}
194194

195-
const handleKeyDown = useCallback(
196-
(event: KeyboardEvent) => {
197-
if (event.key === 'Escape' && keyboard) {
198-
handleDismiss()
199-
}
200-
},
201-
[modalRef, handleDismiss],
202-
)
203-
204-
// const Modal = ({ ref, state }: { ref?: React.Ref<HTMLDivElement>; state?: string }) => (
205-
// <div
206-
// className={classNames(
207-
// 'modal',
208-
// {
209-
// 'modal-static': staticBackdrop,
210-
// fade: transition,
211-
// },
212-
// state === 'entering'
213-
// ? 'd-block'
214-
// : state === 'entered'
215< 8000 code>-
// ? 'show d-block'
216-
// : state === 'exiting'
217-
// ? 'd-block'
218-
// : '',
219-
// className,
220-
// )}
221-
// tabIndex={-1}
222-
// role="dialog"
223-
// ref={ref}
224-
// >
225-
// <CModalDialog
226-
// alignment={alignment}
227-
// fullscreen={fullscreen}
228-
// scrollable={scrollable}
229-
// size={size}
230-
// >
231-
// <CModalContent {...rest} ref={modalContentRef}>
232-
// {children}
233-
// </CModalContent>
234-
// </CModalDialog>
235-
// </div>
236-
// )
195+
const handleKeyDown = (event: KeyboardEvent) => {
196+
if (event.key === 'Escape' && keyboard) {
197+
handleDismiss()
198+
}
199+
}
237200

238201
return (
239202
<>
@@ -244,7 +207,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
244207
onEnter={onShow}
245208
onExit={onClose}
246209
unmountOnExit={unmountOnClose}
247-
timeout={!transition ? 0 : duration}
210+
timeout={transition ? duration : 0}
248211
>
249212
{(state) => (
250213
<CConditionalPortal portal={portal}>
@@ -255,18 +218,15 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
255218
{
256219
'modal-static': staticBackdrop,
257220
fade: transition,
221+
show: state === 'entered',
258222
},
259-
state === 'entering'
260-
? 'd-block'
261-
: state === 'entered'
262-
? 'show d-block'
263-
: state === 'exiting'
264-
? 'd-block'
265-
: '',
266223
className,
267224
)}
268225
tabIndex={-1}
269226
role="dialog"
227+
style={{
228+
...(state !== 'exited' && { display: 'block' }),
229+
}}
270230
ref={forkedRef}
271231
>
272232
<CModalDialog

0 commit comments

Comments
 (0)
0