2020-07-30 19:30:45 +02:00
|
|
|
import React from 'react';
|
2020-08-06 21:05:28 +02:00
|
|
|
import styled from 'styled-components';
|
2020-07-30 19:30:45 +02:00
|
|
|
import { useModalBehavior } from '../utils/custom-hooks';
|
|
|
|
|
2020-08-06 21:05:28 +02:00
|
|
|
const BackgroundOverlay = styled.div`
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
width: 100% !important;
|
|
|
|
height: 100% !important;
|
|
|
|
|
|
|
|
background: black;
|
|
|
|
opacity: 0.3;
|
|
|
|
`;
|
2020-08-06 20:59:22 +02:00
|
|
|
|
2020-08-06 21:24:47 +02:00
|
|
|
export default (Element, hasOverlay = false) => {
|
2020-08-06 21:05:28 +02:00
|
|
|
const [visible, toggle, setRef] = useModalBehavior();
|
2020-07-30 19:30:45 +02:00
|
|
|
|
2020-08-06 21:24:47 +02:00
|
|
|
const wrapper = () => (visible &&
|
|
|
|
<div>
|
|
|
|
{hasOverlay && <BackgroundOverlay />}
|
2020-08-07 23:32:50 +02:00
|
|
|
<div ref={setRef}>
|
|
|
|
{ (typeof (Element) === 'function')
|
|
|
|
? Element(toggle)
|
|
|
|
: Element}
|
|
|
|
</div>
|
2020-08-07 16:24:25 +02:00
|
|
|
</div>);
|
2020-07-30 19:30:45 +02:00
|
|
|
|
2020-08-06 21:05:28 +02:00
|
|
|
return [toggle, wrapper];
|
2020-07-30 19:30:45 +02:00
|
|
|
};
|