1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-09 04:05:01 +00:00
mon-entreprise/source/components/Overlay.js
2019-10-23 12:21:48 +02:00

42 lines
1,003 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import FocusTrap from 'focus-trap-react'
import React, { useEffect } from 'react'
import * as animate from 'Ui/animate'
import { LinkButton } from 'Ui/Button'
import './Overlay.css'
export default function Overlay({ onClose, children, ...otherProps }) {
useEffect(() => {
const body = document.getElementsByTagName('body')[0]
body.classList.add('no-scroll');
return () => {
body.classList.remove('no-scroll')
}
}
, [])
return (
<div id="overlayWrapper">
<animate.fromBottom>
<FocusTrap
focusTrapOptions={{
onDeactivate: onClose,
clickOutsideDeactivates: !!onClose
}}>
<div
aria-modal="true"
id="overlayContent"
{...otherProps}
className={'ui__ card ' + otherProps.className}>
{children}
{onClose && (
<LinkButton
aria-label="close"
onClick={onClose}
id="overlayCloseButton">
×
</LinkButton>
)}
</div>
</FocusTrap>
</animate.fromBottom>
</div>
)
}