File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ // TODO: add smooth transition.
2
+
3
+ import React , { forwardRef , HTMLAttributes } from 'react'
4
+ import { createPortal } from 'react-dom'
5
+ import { CSSTransition } from 'react-transition-group'
6
+ import PropTypes from 'prop-types'
7
+ import classNames from 'classnames'
8
+
9
+ export interface CBackdropProps extends HTMLAttributes < HTMLDivElement > {
10
+ /**
11
+ * A string of all className you want applied to the base component. [docs]
12
+ */
13
+ className ?: string
14
+ /**
15
+ * Toggle the visibility of modal component. [docs]
16
+ */
17
+ visible ?: boolean
18
+ addEndListener ?: any
19
+ }
20
+
21
+ export const CBackdrop = forwardRef < HTMLDivElement , CBackdropProps > (
22
+ ( { className, visible, ...rest } , ref ) => {
23
+ const _className = classNames (
24
+ 'modal-backdrop fade' ,
25
+ {
26
+ show : visible
27
+ } ,
28
+ className
29
+ )
30
+
31
+ const backdrop = ( ref ?: React . Ref < HTMLDivElement > ) => {
32
+ return < div className = { _className } { ...rest } ref = { ref } />
33
+ }
34
+
35
+ return (
36
+ < CSSTransition
37
+ in = { visible }
38
+ timeout = { 150 }
39
+ mountOnEnter
40
+ unmountOnExit
41
+ >
42
+ < div className = { _className } { ...rest } ref = { ref } />
43
+ </ CSSTransition >
44
+ )
45
+ } ,
46
+ )
47
+
48
+ CBackdrop . propTypes = {
49
+ className : PropTypes . string ,
50
+ visible : PropTypes . bool ,
51
+ }
52
+
53
+ CBackdrop . displayName = 'CBackdrop'
You can’t perform that action at this time.
0 commit comments