-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescriptionPopover.js
50 lines (47 loc) · 1.28 KB
/
DescriptionPopover.js
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
46
47
48
49
50
import React, { useEffect, useState } from "react";
import { Popover, PopoverPosition } from "@blueprintjs/core";
export const DescriptionPopover = ({ description, children }) => {
const [open, setOpen] = useState(false);
useEffect(() => {
const listener = e => {
if (e.keyCode === 27) {
setOpen(false);
}
};
document.body.addEventListener("keydown", listener);
return () => {
document.body.removeEventListener("keydown", listener);
};
}, []);
return (
<Popover
content={<Description description={description} />}
position={PopoverPosition.RIGHT_BOTTOM}
canEscapeKeyClose={true}
isOpen={open}
onInteraction={setOpen}
boundary="viewport"
>
{children}
</Popover>
);
};
export const SettingDescriptionInline = ({ description }) => {
return (
<div className="SettingDescriptionInline">
<Description description={description} />
</div>
);
};
const Description = ({ description }) => {
return typeof description === "string" ? (
<div
className="SettingDescription"
dangerouslySetInnerHTML={{ __html: description }}
/>
) : (
<div className="SettingDescription">
{Array.isArray(description) ? description.join(" ") : description}
</div>
);
};