Skip to content

Commit 2c54cb3

Browse files
committed
feat(CBackdrop): add new component
1 parent ad61c5d commit 2c54cb3

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/components/backdrop/CBackdrop.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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'

0 commit comments

Comments
 (0)