moved back the components

This commit is contained in:
ari committed 2021-12-01 16:38:30 -05:00
1 parent 24afb602cb
commit 0764feb432
18 files changed
+786

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { TooltipState } from "./context";
export default function Tooltip({
domrect,
searchOptions,
searchResults=[],
onSelected=()=>{},
updateState,
}: TooltipState) {
// state alias
const rootClassName = !!domrect && !!searchOptions ? "tooltip show" : "tooltip hide";
let tooltipStyle = {};
if (domrect) {
const {left=0, top=0, height=0, width=0} = domrect;
tooltipStyle = {
top: `${top + height}px`,
left: `${left}px`,
width: `${width}px`,
}
}
const unFocus = () => updateState({
updateState,
onSelected,
searchResults: [],
});
return <div className={rootClassName}>
<div className="tooltip-bg" onClick={() => unFocus()}></div>
<ul style={tooltipStyle}>
{searchResults.map((r, i) => <li key={i} onClick={() => {
onSelected(r);
unFocus();
}}>
{r}
</li>)}
{searchResults.length === 0 ? <li onClick={() => unFocus()}>No Options...</li> : ""}
</ul>
</div>
}