-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tooltip and fix time treshold
- Loading branch information
1 parent
1ebb063
commit fbf7509
Showing
8 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use client"; | ||
|
||
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react"; | ||
import { InformationCircleIcon } from "@heroicons/react/20/solid"; | ||
import { useState, useRef, useEffect } from "react"; | ||
|
||
interface ToolTipProps { | ||
text: React.ReactNode; | ||
} | ||
|
||
export default function ToolTip({ text }: ToolTipProps) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const popoverButtonRef = useRef<HTMLButtonElement>(null); | ||
|
||
const handleMouseEnter = () => { | ||
setIsOpen(true); | ||
}; | ||
|
||
const handleMouseLeave = () => { | ||
setIsOpen(false); | ||
}; | ||
|
||
useEffect(() => { | ||
const current = popoverButtonRef.current; | ||
if (!current) { | ||
return; | ||
} | ||
|
||
const observer = new MutationObserver((mutations) => { | ||
const hovered = mutations.find( | ||
({ attributeName }) => attributeName === "data-hover" | ||
); | ||
const active = current.hasAttribute("data-active"); | ||
|
||
if (hovered && !active) { | ||
current.click(); | ||
} | ||
}); | ||
|
||
observer.observe(current, { attributes: true }); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
}; | ||
}, [popoverButtonRef]); | ||
|
||
return ( | ||
<Popover className="relative" onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}> | ||
<PopoverButton ref={popoverButtonRef} className="focus:outline-none"> | ||
<InformationCircleIcon className="h-5 w-5" /> | ||
</PopoverButton> | ||
{isOpen && ( | ||
<PopoverPanel | ||
anchor="top" | ||
className="flex bg-accent/80 rounded-full py-1 px-2 text-sm mb-2 [--anchor-gap:4px]" | ||
> | ||
{text} | ||
</PopoverPanel> | ||
)} | ||
</Popover> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters