forked from basetool-io/basetool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeedbackSidebarItem.tsx
52 lines (46 loc) · 1.5 KB
/
FeedbackSidebarItem.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
46
47
48
49
50
51
52
import {
ChatAltIcon,
} from "@heroicons/react/outline";
import { DataSourceItem } from "./DataSourcesSidebar";
import { useBoolean, useClickAway } from "react-use";
import FeedbackPanel from "./FeedbackPanel";
import React, { memo, useRef } from "react";
const FeedbackSidebarItem = () => {
const [feedbackPanelVisible, toggleFeedbackPanelVisible] = useBoolean(false);
const feedbackButton = useRef(null);
const feedbackPanel = useRef(null);
useClickAway(feedbackPanel, (e) => {
// When a user click the filters button to close the filters panel, the button is still outside,
// so the action triggers twice closing and opening the filters panel.
if (
feedbackButton?.current &&
!(feedbackButton?.current as any)?.contains(e.target)
) {
toggleFeedbackPanelVisible(false);
}
});
const handleShowFeedbackPanelClick = () => {
toggleFeedbackPanelVisible();
};
return (
<>
<div ref={feedbackButton}>
<DataSourceItem
active={feedbackPanelVisible}
icon={<ChatAltIcon className="h-6 w-6 text-white" />}
label={`Share any feedback or ideas`}
onClick={handleShowFeedbackPanelClick}
/>
</div>
{feedbackPanelVisible && (
<div
className="absolute right-auto left-16 bottom-16 z-50 ml-1"
ref={feedbackPanel}
>
<FeedbackPanel closePanel={() => toggleFeedbackPanelVisible(false)} />
</div>
)}
</>
);
};
export default memo(FeedbackSidebarItem);