Skip to content

Commit 56e615d

Browse files
committed
refactor(CModal): move the context outside the component
1 parent de2290b commit 56e615d

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {
2-
createContext,
32
forwardRef,
43
HTMLAttributes,
54
useEffect,
@@ -14,6 +13,7 @@ import { Transition } from 'react-transition-group'
1413
import { CBackdrop } from '../backdrop'
1514
import { CConditionalPortal } from '../conditional-portal'
1615
import { CModalContent } from './CModalContent'
16+
import { CModalContext } from './CModalContext'
1717
import { CModalDialog } from './CModalDialog'
1818

1919
import { useForkedRef } from '../../hooks'
@@ -93,13 +93,6 @@ export interface CModalProps extends HTMLAttributes<HTMLDivElement> {
9393
visible?: boolean
9494
}
9595

96-
interface ModalContextProps {
97-
visible?: boolean
98-
setVisible: React.Dispatch<React.SetStateAction<boolean | undefined>>
99-
}
100-
101-
export const CModalContext = createContext({} as ModalContextProps)
102-
10396
export const CModal = forwardRef<HTMLDivElement, CModalProps>(
10497
(
10598
{
@@ -123,7 +116,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
123116
visible,
124117
...rest
125118
},
126-
ref,
119+
ref
127120
) => {
128121
const activeElementRef = useRef<HTMLElement | null>(null)
129122
const modalRef = useRef<HTMLDivElement>(null)
@@ -184,7 +177,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
184177
() => {
185178
focus && modalRef.current?.focus()
186179
},
187-
transition ? duration : 0,
180+
transition ? duration : 0
188181
)
189182
} else {
190183
document.body.classList.remove('modal-open')
@@ -238,7 +231,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
238231
fade: transition,
239232
show: state === 'entered',
240233
},
241-
className,
234+
className
242235
)}
243236
tabIndex={-1}
244237
{...(_visible
@@ -270,7 +263,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
270263
)}
271264
</>
272265
)
273-
},
266+
}
274267
)
275268

276269
CModal.propTypes = {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createContext } from 'react'
2+
3+
export interface CModalContextProps {
4+
visible?: boolean
5+
setVisible: React.Dispatch<React.SetStateAction<boolean | undefined>>
6+
}
7+
8+
export const CModalContext = createContext({} as CModalContextProps)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

55
import { CCloseButton } from '../close-button/CCloseButton'
6-
import { CModalContext } from './CModal'
6+
import { CModalContext } from './CModalContext'
77

88
export interface CModalHeaderProps extends HTMLAttributes<HTMLDivElement> {
99
/**

0 commit comments

Comments
 (0)