11import { memo , useCallback , useEffect , useRef } from "react" ;
22
33import mapData from "@/data/costa_rica.json" ;
4+ import { cn } from "@/lib/utils" ;
45
56import type React from "react" ;
67
@@ -16,7 +17,13 @@ interface ParticleOrigin {
1617 y : number ;
1718}
1819
19- function ParticlesMap ( ) {
20+ interface ParticlesMapProps {
21+ className ?: string ;
22+ canvasClassName ?: string ;
23+ interactive ?: boolean ;
24+ }
25+
26+ function ParticlesMap ( { className, canvasClassName, interactive = true } : ParticlesMapProps ) {
2027 const canvasRef = useRef < HTMLCanvasElement > ( null ) ;
2128 const animationRef = useRef < number | undefined > ( undefined ) ;
2229 const mouseRef = useRef ( { x : - 1000 , y : - 1000 } ) ;
@@ -220,23 +227,39 @@ function ParticlesMap() {
220227 } ;
221228
222229 return (
223- < div className = "flex w-full items-center justify-center p-8" >
230+ < div className = { cn ( "flex w-full items-center justify-center p-8" , className ) } >
224231 < canvas
225232 ref = { canvasRef }
226- onMouseMove = { handleMouseMove }
227- onMouseDown = { ( ) => {
228- isMouseDownRef . current = true ;
229- } }
230- onMouseUp = { ( ) => {
231- isMouseDownRef . current = false ;
232- } }
233- onMouseLeave = { ( ) => {
234- isMouseDownRef . current = false ;
235- } }
236- onTouchStart = { handleTouchStart }
237- onTouchMove = { handleTouchMove }
238- onTouchEnd = { handleTouchEnd }
239- className = "w-full max-w-[600px]"
233+ onMouseMove = { interactive ? handleMouseMove : undefined }
234+ onMouseDown = {
235+ interactive
236+ ? ( ) => {
237+ isMouseDownRef . current = true ;
238+ }
239+ : undefined
240+ }
241+ onMouseUp = {
242+ interactive
243+ ? ( ) => {
244+ isMouseDownRef . current = false ;
245+ }
246+ : undefined
247+ }
248+ onMouseLeave = {
249+ interactive
250+ ? ( ) => {
251+ isMouseDownRef . current = false ;
252+ }
253+ : undefined
254+ }
255+ onTouchStart = { interactive ? handleTouchStart : undefined }
256+ onTouchMove = { interactive ? handleTouchMove : undefined }
257+ onTouchEnd = { interactive ? handleTouchEnd : undefined }
258+ className = { cn (
259+ "w-full max-w-[600px]" ,
260+ ! interactive && "pointer-events-none" ,
261+ canvasClassName
262+ ) }
240263 style = { { aspectRatio : "600/600" , touchAction : "none" } }
241264 />
242265 </ div >
0 commit comments