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