react-core-ts 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/ExpandableAutoComplete.d.ts +4 -0
- package/dist/ExpandableAutoComplete.js +335 -0
- package/dist/ExpandableAutoComplete.js.map +1 -0
- package/dist/commontypes.d.ts +5 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/styles/components/autocomplete.css +60 -5
- package/dist/styles/styles/components/autocomplete.css +578 -0
- package/dist/styles/styles/global.css +1 -0
- package/dist/utilities/expandableTootltip.d.ts +3 -0
- package/dist/utilities/expandableTootltip.js +155 -0
- package/dist/utilities/expandableTootltip.js.map +1 -0
- package/dist/utilities/filterSuggestions.js +1 -0
- package/dist/utilities/filterSuggestions.js.map +1 -1
- package/docs/App.tsx +31 -1
- package/package.json +1 -1
- package/src/ExpandableAutoComplete.tsx +545 -0
- package/src/commontypes.ts +5 -2
- package/src/index.tsx +2 -0
- package/src/styles/components/autocomplete.css +60 -5
- package/src/utilities/expandableTootltip.tsx +149 -0
- package/src/utilities/filterSuggestions.ts +1 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React, { useState, useRef, useLayoutEffect, useEffect } from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
|
|
4
|
+
const ExpandableToolTip: React.FC<any> = ({ title, children, enabled }) => {
|
|
5
|
+
const [dropdownPosition, setDropdownPosition] = useState("bottom-position");
|
|
6
|
+
const dropRef = useRef(null);
|
|
7
|
+
const menuButtonRef = useRef<HTMLDivElement>(null);
|
|
8
|
+
const [visible, setVisible] = useState(false);
|
|
9
|
+
const [tooltipStyle, setTooltipStyle] = useState({
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
width: 0,
|
|
13
|
+
});
|
|
14
|
+
const adjustDropdownPosition = (): string => {
|
|
15
|
+
if (menuButtonRef.current) {
|
|
16
|
+
const inputBoxRect = menuButtonRef.current?.getBoundingClientRect();
|
|
17
|
+
const viewportHeight = window.innerHeight;
|
|
18
|
+
|
|
19
|
+
const spaceAbove = inputBoxRect.top;
|
|
20
|
+
const spaceBelow = viewportHeight - inputBoxRect.bottom;
|
|
21
|
+
if (spaceAbove > spaceBelow) {
|
|
22
|
+
if (spaceAbove > 90 && spaceBelow < 120) {
|
|
23
|
+
return "top-position";
|
|
24
|
+
} else {
|
|
25
|
+
return "bottom-position";
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
const diff: number = spaceBelow - spaceAbove;
|
|
29
|
+
if (spaceAbove > 90 && spaceBelow > 90 && diff < 90) {
|
|
30
|
+
return "top-position";
|
|
31
|
+
} else {
|
|
32
|
+
return "bottom-position";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const handleMouseEnter = (e: React.MouseEvent) => {
|
|
39
|
+
if (menuButtonRef.current) {
|
|
40
|
+
const dropPosition = adjustDropdownPosition();
|
|
41
|
+
setDropdownPosition(dropPosition);
|
|
42
|
+
const rect = (e.target as HTMLElement).getBoundingClientRect();
|
|
43
|
+
let top = rect.bottom + window.scrollY;
|
|
44
|
+
let left = rect.left + window.scrollX;
|
|
45
|
+
const height = rect.height;
|
|
46
|
+
const width = dropRef?.current?.offsetWidth;
|
|
47
|
+
if (dropPosition === "bottom-position") {
|
|
48
|
+
top = top + height / 2 - 5;
|
|
49
|
+
} else {
|
|
50
|
+
top = top - height * 2 + 15;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setTooltipStyle({
|
|
54
|
+
top: top,
|
|
55
|
+
left: left,
|
|
56
|
+
width: width,
|
|
57
|
+
});
|
|
58
|
+
setVisible(true);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const handleMouseLeave = () => {
|
|
63
|
+
setVisible(false);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
const updateTooltipPosition = () => {
|
|
68
|
+
if (dropRef.current && visible && tooltipStyle) {
|
|
69
|
+
const tooltipHeight = dropRef.current.offsetHeight;
|
|
70
|
+
const tooltipWidth = dropRef.current.offsetWidth;
|
|
71
|
+
const boxWidth = menuButtonRef.current.offsetWidth;
|
|
72
|
+
setTooltipStyle((prevStyle) => ({
|
|
73
|
+
...prevStyle,
|
|
74
|
+
left:
|
|
75
|
+
prevStyle.left + boxWidth / 2 - tooltipWidth / 2 < 0
|
|
76
|
+
? 20
|
|
77
|
+
: prevStyle.left + boxWidth / 2 - tooltipWidth / 2,
|
|
78
|
+
width: tooltipWidth,
|
|
79
|
+
top:
|
|
80
|
+
dropdownPosition === "bottom-position"
|
|
81
|
+
? prevStyle.top
|
|
82
|
+
: prevStyle.top - tooltipHeight,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (visible) {
|
|
88
|
+
updateTooltipPosition();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
window.addEventListener("resize", updateTooltipPosition);
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
window.removeEventListener("resize", updateTooltipPosition);
|
|
95
|
+
};
|
|
96
|
+
}, [visible, dropdownPosition]);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
100
|
+
if (dropRef.current && !dropRef.current.contains(event.target as Node)) {
|
|
101
|
+
setVisible(false);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
106
|
+
return () => {
|
|
107
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
108
|
+
};
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<div
|
|
114
|
+
onMouseEnter={handleMouseEnter}
|
|
115
|
+
onMouseLeave={handleMouseLeave}
|
|
116
|
+
ref={menuButtonRef}
|
|
117
|
+
style={{ display: "flex" }}
|
|
118
|
+
>
|
|
119
|
+
{children}
|
|
120
|
+
|
|
121
|
+
{visible &&
|
|
122
|
+
enabled &&
|
|
123
|
+
tooltipStyle &&
|
|
124
|
+
ReactDOM.createPortal(
|
|
125
|
+
<span
|
|
126
|
+
ref={(node) => (dropRef.current = node)}
|
|
127
|
+
className={`tooltiptext ${
|
|
128
|
+
dropdownPosition == "bottom-position" ? "down" : "up"
|
|
129
|
+
}`}
|
|
130
|
+
style={{
|
|
131
|
+
top: tooltipStyle.top,
|
|
132
|
+
left: tooltipStyle.left,
|
|
133
|
+
opacity: 1,
|
|
134
|
+
width: tooltipStyle.width,
|
|
135
|
+
minWidth: "60px",
|
|
136
|
+
maxWidth: "200px",
|
|
137
|
+
visibility: "visible",
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{title}
|
|
141
|
+
</span>,
|
|
142
|
+
document.body
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default ExpandableToolTip;
|