-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d61b66
commit 6712492
Showing
12 changed files
with
187 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import useTooltip from "@/hooks/use-tooltip"; | ||
import { AnimatePresence, m } from "framer-motion"; | ||
import { memo } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
const MapTooltip = memo(function MapTooltip() { | ||
const { t } = useTranslation(); | ||
const { tooltipData } = useTooltip(); | ||
|
||
if (!tooltipData) return null; | ||
|
||
return ( | ||
<AnimatePresence mode="wait"> | ||
<m.div | ||
initial={{ opacity: 0, filter: "blur(10px)" }} | ||
animate={{ opacity: 1, filter: "blur(0px)" }} | ||
exit={{ opacity: 0, filter: "blur(10px)" }} | ||
className="absolute hidden lg:block bg-white dark:bg-neutral-800 px-2 py-1 rounded shadow-lg text-sm dark:border dark:border-neutral-700 z-50" | ||
key={tooltipData.country} | ||
style={{ | ||
left: tooltipData.centroid[0], | ||
top: tooltipData.centroid[1], | ||
transform: "translate(20%, -50%)", | ||
}} | ||
onMouseEnter={(e) => { | ||
e.stopPropagation(); | ||
}} | ||
> | ||
<div> | ||
<p className="font-medium"> | ||
{tooltipData.country === "China" | ||
? "Mainland China" | ||
: tooltipData.country} | ||
</p> | ||
<p className="text-neutral-600 dark:text-neutral-400 mb-1"> | ||
{tooltipData.count} {t("map.Servers")} | ||
</p> | ||
</div> | ||
<div | ||
className="border-t dark:border-neutral-700 pt-1" | ||
style={{ | ||
maxHeight: "200px", | ||
overflowY: "auto", | ||
}} | ||
> | ||
{tooltipData.servers.map((server, index: number) => ( | ||
<div key={index} className="flex items-center gap-1.5 py-0.5"> | ||
<span | ||
className={`w-1.5 h-1.5 shrink-0 rounded-full ${ | ||
server.status ? "bg-green-500" : "bg-red-500" | ||
}`} | ||
></span> | ||
<span className="text-xs">{server.name}</span> | ||
</div> | ||
))} | ||
</div> | ||
</m.div> | ||
</AnimatePresence> | ||
); | ||
}); | ||
|
||
export default MapTooltip; |
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,20 @@ | ||
import { createContext } from "react"; | ||
|
||
export interface TooltipData { | ||
centroid: [number, number]; | ||
country: string; | ||
count: number; | ||
servers: Array<{ | ||
name: string; | ||
status: boolean; | ||
}>; | ||
} | ||
|
||
interface TooltipContextType { | ||
tooltipData: TooltipData | null; | ||
setTooltipData: (data: TooltipData | null) => void; | ||
} | ||
|
||
export const TooltipContext = createContext<TooltipContextType | undefined>( | ||
undefined, | ||
); |
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,12 @@ | ||
import { ReactNode, useState } from "react"; | ||
import { TooltipContext, TooltipData } from "./tooltip-context"; | ||
|
||
export function TooltipProvider({ children }: { children: ReactNode }) { | ||
const [tooltipData, setTooltipData] = useState<TooltipData | null>(null); | ||
|
||
return ( | ||
<TooltipContext.Provider value={{ tooltipData, setTooltipData }}> | ||
{children} | ||
</TooltipContext.Provider> | ||
); | ||
} |
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,12 @@ | ||
import { useContext } from "react"; | ||
import { TooltipContext } from "@/context/tooltip-context"; | ||
|
||
export const useTooltip = () => { | ||
const context = useContext(TooltipContext); | ||
if (context === undefined) { | ||
throw new Error("useTooltip must be used within a TooltipProvider"); | ||
} | ||
return context; | ||
}; | ||
|
||
export default useTooltip; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
declare module '*.css' { | ||
const css: { [key: string]: string } | ||
export default css | ||
declare module "*.css" { | ||
const css: { [key: string]: string }; | ||
export default css; | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
/// <reference types="vite/client" /> | ||
/// <reference types="vite/client" /> |