Skip to content
Snippets Groups Projects
Modal.tsx 1.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • import React, { useEffect, useContext, ReactNode } from 'react'
    import { AppContext } from 'components/Contexts/AppContextProvider'
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
    import CloseIcon from 'assets/icons/ico/close.svg'
    
    interface ModalProps {
      open: boolean
      border?: boolean
      handleCloseClick: () => void
      children: ReactNode
    
      yellowBorder?: boolean
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    }
    
    const Modal: React.FC<ModalProps> = ({
      open,
      border,
      handleCloseClick,
      children,
    
    Romain CREY's avatar
    Romain CREY committed
      yellowBorder,
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    }: ModalProps) => {
    
      const yellow = yellowBorder ? 'yellow-border' : ''
    
      const { disableBackgroundScroll } = useContext(AppContext)
    
      useEffect(() => {
        open ? disableBackgroundScroll(true) : disableBackgroundScroll(false)
    
    Romain CREY's avatar
    Romain CREY committed
        return () => {
          disableBackgroundScroll(false)
        }
    
      }, [open])
    
      const closeClick = () => {
        disableBackgroundScroll(false)
        handleCloseClick()
      }
    
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
      return (
        <div className={`modal-overlay ${open ? 'modal-opened' : ''}`}>
    
    Romain CREY's avatar
    Romain CREY committed
          <div
    
            className={`modal-box ${border ? 'modal-box-bordered' : ''} ${yellow}`}
    
    Romain CREY's avatar
    Romain CREY committed
          >
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
            <StyledIconButton
              className="modal-close-button"
              icon={CloseIcon}
    
              onClick={closeClick}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
            />
            <div className="modal-content">{children}</div>
          </div>
        </div>
      )
    }
    
    export default Modal