-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathAnnotationMarker.tsx
71 lines (65 loc) · 2.36 KB
/
AnnotationMarker.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { ReactNode, useState } from "react";
import classNames from "classnames";
import LocationIcon from "@vector-im/compound-design-tokens/assets/web/icons/location-pin-solid";
const OptionalTooltip: React.FC<{
tooltip?: React.ReactNode;
annotationKey: string;
children: React.ReactNode;
onDelete: (key: string) => void; // Optional delete function
}> = ({ tooltip, children, onDelete, annotationKey }) => {
const [isHovered, setIsHovered] = useState(false);
return (
<div
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
style={{ position: "relative" }} // Set position for proper tooltip alignment
>
{tooltip && (
<div style={{ display: "flex", alignItems: "center" }}>
{tooltip}
{isHovered && (
<button
onClick={() => onDelete(annotationKey)}
style={{
marginLeft: "8px", // Space between tooltip and button
backgroundColor: "red", // Customize button style
color: "white",
border: "none",
borderRadius: "3px",
cursor: "pointer"
}}
>
X
</button>
)}
</div>
)}
{children}
</div>
);
};
/**
* Generic location marker
*/
interface Props {
id: string;
useColor?: string;
tooltip?: ReactNode;
onDelete: (annotationKey: string) => void;
}
const AnnotationMarker = React.forwardRef<HTMLDivElement, Props>(({ id, useColor, tooltip, onDelete}, ref) => {
return (
<div
ref={ref}
id={id}
className={classNames("mx_Marker", useColor ? `mx_Marker_${useColor}` : "mx_Marker_defaultColor" )}
>
<OptionalTooltip tooltip={tooltip} annotationKey={id} onDelete={onDelete}>
<div className="mx_AnnotationMarker_border">
<LocationIcon className="mx_Marker_icon" />
</div>
</OptionalTooltip>
</div>
);
});
export default AnnotationMarker;