All files / molecule/drawer/src Overlay.js

44.44% Statements 4/9
0% Branches 0/4
0% Functions 0/2
44.44% Lines 4/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37            1x   1x                             1x                   1x      
import {forwardRef, useEffect} from 'react'
 
import PropTypes from 'prop-types'
 
import {BASE_CLASS} from './settings.js'
 
const DRAWER_OVERLAY_CLASS = `${BASE_CLASS}-overlay`
 
const DrawerOverlay = forwardRef(({isVisible, target, children, ...props}, forwardedRef) => {
  useEffect(() => {
    if (target !== undefined) {
      target.current.style.position = 'relative'
      target.current.style.overflow = 'hidden'
    }
  }, [target])
 
  return isVisible ? (
    <div ref={forwardedRef} className={DRAWER_OVERLAY_CLASS} {...props}>
      {children}
    </div>
  ) : null
})
 
DrawerOverlay.propTypes = {
  /** element ref which overlays covers **/
  target: PropTypes.object,
  /** inner content **/
  children: PropTypes.node,
  /** show-hide overlay  **/
  isVisible: PropTypes.bool,
  /** click handler **/
  onClick: PropTypes.func
}
DrawerOverlay.displayName = 'MoleculeDrawerOverlay'
 
export default DrawerOverlay