-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickTooltip.tsx
More file actions
40 lines (37 loc) · 1.1 KB
/
ClickTooltip.tsx
File metadata and controls
40 lines (37 loc) · 1.1 KB
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
import { Box, Tooltip, ClickAwayListener, TooltipProps } from "@mui/material";
import { useState, PropsWithChildren } from "react";
type ClickTooltipProps = PropsWithChildren<{
title: TooltipProps["title"];
placement?: TooltipProps["placement"];
componentsProps?: TooltipProps["componentsProps"];
}>;
export default function ClickTooltip({
title,
placement = "right",
componentsProps,
children,
}: ClickTooltipProps) {
const [open, setOpen] = useState(false);
const toggle = () => setOpen((o) => !o);
const close = () => setOpen(false);
return (
<ClickAwayListener onClickAway={close}>
<Box sx={{ display: "inline-flex" }}>
<Tooltip
open={open}
onClose={close}
disableFocusListener
disableHoverListener
disableTouchListener
placement={placement}
componentsProps={componentsProps}
title={title}
arrow
>
{/* span to ensure Tooltip always has a single DOM child */}
<span onClick={toggle}>{children}</span>
</Tooltip>
</Box>
</ClickAwayListener>
);
}