-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Gurubase/task/analytics
Task/analytics
- Loading branch information
Showing
3 changed files
with
84 additions
and
88 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
63 changes: 63 additions & 0 deletions
63
src/gurubase-frontend/src/components/ui/header-tooltip.jsx
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,63 @@ | ||
"use client"; | ||
|
||
import { useState, useEffect } from "react"; | ||
import { SolarInfoCircleBold } from "@/components/Icons"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger | ||
} from "@/components/ui/tooltip"; | ||
|
||
export const HeaderTooltip = ({ text }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleClickOutside = (event) => { | ||
if (!event.target.closest("[data-tooltip-trigger]")) { | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
// Handle both touch and click events | ||
document.addEventListener("click", handleClickOutside); | ||
document.addEventListener("touchend", handleClickOutside); | ||
|
||
return () => { | ||
document.removeEventListener("click", handleClickOutside); | ||
document.removeEventListener("touchend", handleClickOutside); | ||
}; | ||
}, []); | ||
|
||
const handleInteraction = (e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
// Check if it's a mobile device | ||
const isMobile = window.matchMedia("(max-width: 768px)").matches; | ||
if (isMobile) { | ||
setIsOpen(!isOpen); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="ml-2"> | ||
<TooltipProvider> | ||
<Tooltip open={isOpen} onOpenChange={setIsOpen}> | ||
<TooltipTrigger | ||
asChild | ||
data-tooltip-trigger | ||
onClick={handleInteraction} | ||
onTouchEnd={handleInteraction}> | ||
<div> | ||
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" /> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent side="top" align="center" className="z-50"> | ||
<p className="text-[12px] font-medium max-w-[400px]">{text}</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</div> | ||
); | ||
}; |