-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathWithOverlay.tsx
executable file
·45 lines (39 loc) · 1021 Bytes
/
WithOverlay.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { useState } from 'react';
import Floater from 'react-floater';
import styled from '@emotion/styled';
import { Button, Paragraph } from '@gilbarbara/components';
const Overlay = styled.div`
background-color: rgba(0, 0, 0, 0.2);
position: fixed;
bottom: 0;
left: 0;
right: 0;
top: 0;
z-index: 100;
`;
export default function FloaterOverlay({ cb }: any) {
const [isOpen, setOpen] = useState(false);
const callback = (action: any, props: any) => {
cb(action, props);
setOpen(action === 'open');
};
const handleClick = () => {
setOpen(s => !s);
};
return (
<>
<Floater
callback={callback}
content={<Paragraph>I have an invisible overlay that will close the floater</Paragraph>}
open={isOpen}
placement="top"
styles={{ options: { zIndex: 250 } }}
>
<Button onClick={handleClick} size="sm">
Click me
</Button>
</Floater>
{isOpen && <Overlay onClick={handleClick} />}
</>
);
}