2018-05-24 14:38:21 +02:00
|
|
|
|
import FocusTrap from 'focus-trap-react'
|
2019-10-11 16:00:22 +02:00
|
|
|
|
import React, { useEffect } from 'react'
|
2018-07-25 16:07:53 +02:00
|
|
|
|
import * as animate from 'Ui/animate'
|
2018-07-12 10:09:41 +02:00
|
|
|
|
import { LinkButton } from 'Ui/Button'
|
2018-01-30 15:16:32 +01:00
|
|
|
|
import './Overlay.css'
|
2019-11-10 16:57:44 +01:00
|
|
|
|
|
|
|
|
|
type OverlayProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
|
|
|
onClose?: () => void
|
|
|
|
|
children: React.ReactNode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function Overlay({
|
|
|
|
|
onClose,
|
|
|
|
|
children,
|
|
|
|
|
...otherProps
|
|
|
|
|
}: OverlayProps) {
|
2019-10-11 16:00:22 +02:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
const body = document.getElementsByTagName('body')[0]
|
2019-11-10 16:57:44 +01:00
|
|
|
|
body.classList.add('no-scroll')
|
2019-10-11 16:00:22 +02:00
|
|
|
|
return () => {
|
|
|
|
|
body.classList.remove('no-scroll')
|
|
|
|
|
}
|
2019-11-10 16:57:44 +01:00
|
|
|
|
}, [])
|
2019-09-11 10:06:26 +02:00
|
|
|
|
return (
|
|
|
|
|
<div id="overlayWrapper">
|
|
|
|
|
<animate.fromBottom>
|
|
|
|
|
<FocusTrap
|
|
|
|
|
focusTrapOptions={{
|
|
|
|
|
onDeactivate: onClose,
|
2019-10-01 18:42:08 +02:00
|
|
|
|
clickOutsideDeactivates: !!onClose
|
2019-11-10 16:57:44 +01:00
|
|
|
|
}}
|
|
|
|
|
>
|
2019-10-02 18:12:40 +02:00
|
|
|
|
<div
|
|
|
|
|
aria-modal="true"
|
|
|
|
|
id="overlayContent"
|
2019-10-02 18:46:05 +02:00
|
|
|
|
{...otherProps}
|
2019-11-10 16:57:44 +01:00
|
|
|
|
className={'ui__ card ' + otherProps?.className}
|
|
|
|
|
>
|
2019-09-11 10:06:26 +02:00
|
|
|
|
{children}
|
2019-10-01 18:42:08 +02:00
|
|
|
|
{onClose && (
|
|
|
|
|
<LinkButton
|
|
|
|
|
aria-label="close"
|
|
|
|
|
onClick={onClose}
|
2019-11-10 16:57:44 +01:00
|
|
|
|
id="overlayCloseButton"
|
|
|
|
|
>
|
2019-10-01 18:42:08 +02:00
|
|
|
|
×
|
|
|
|
|
</LinkButton>
|
|
|
|
|
)}
|
2019-09-11 10:06:26 +02:00
|
|
|
|
</div>
|
|
|
|
|
</FocusTrap>
|
|
|
|
|
</animate.fromBottom>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2018-01-30 15:16:32 +01:00
|
|
|
|
}
|