Skip to content

Commit

Permalink
feat(global): tooltip animation
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Nov 25, 2024
1 parent f043f5e commit e6cd4da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/(main)/ClientComponents/Global.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default async function ServerGlobal() {
}
});

countrytList.push("TW");
countrytList.push("SG");
countrytList.push("RU");

const width = 900;
const height = 500;

Expand Down
36 changes: 21 additions & 15 deletions app/(main)/ClientComponents/InteractiveMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { countryCodeMapping } from "@/lib/geo";
import { geoEqualEarth, geoPath } from "d3-geo";
import { AnimatePresence, m } from "framer-motion";
import { useTranslations } from "next-intl";
import { useState } from "react";

Expand Down Expand Up @@ -88,21 +89,26 @@ export function InteractiveMap({
})}
</g>
</svg>
{tooltipData && (
<div
className="absolute pointer-events-none bg-white dark:bg-neutral-800 px-2 py-1 rounded shadow-lg text-sm"
style={{
left: tooltipData.centroid[0],
top: tooltipData.centroid[1],
transform: "translate(-50%, -50%)",
}}
>
<p className="font-medium">{tooltipData.country}</p>
<p className="text-neutral-600 dark:text-neutral-400">
{tooltipData.count} {t("Servers")}
</p>
</div>
)}
<AnimatePresence mode="wait">
{tooltipData && (
<m.div
initial={{ opacity: 0, filter: "blur(10px)", scale: 0.8 }}
animate={{ opacity: 1, filter: "blur(0px)", scale: 1 }}
className="absolute pointer-events-none bg-white dark:bg-neutral-800 px-2 py-1 rounded shadow-lg text-sm dark:border dark:border-neutral-700"
key={tooltipData.country}
style={{
left: tooltipData.centroid[0],
top: tooltipData.centroid[1],
transform: "translate(-50%, -50%)",
}}
>
<p className="font-medium">{tooltipData.country}</p>
<p className="text-neutral-600 dark:text-neutral-400">
{tooltipData.count} {t("Servers")}
</p>
</m.div>
)}
</AnimatePresence>
</div>
);
}

0 comments on commit e6cd4da

Please sign in to comment.