Skip to content

Commit

Permalink
setTimeout disable click for 2000ms and then allow again
Browse files Browse the repository at this point in the history
  • Loading branch information
tomonarifeehan committed May 27, 2024
1 parent 70a9647 commit 2e42305
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions registry/components/magicui/wavy-dot-pattern.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import { anime } from 'react-anime'
import { cn } from "@/lib/utils"
import { useState } from 'react'

const handleDotClick = (e: any, width: number, height: number) => {
anime({
interface WavyDotPatternProps {
className?: string
gridWidth?: number
gridHeight?: number
dotWidth?: number,
dotHeight?: number
}

export const WavyDotPattern = ({
className,
gridWidth,
gridHeight,
dotWidth,
dotHeight
}: WavyDotPatternProps) => {

const [dotClickDisabled, setDotClickDisabled] = useState<boolean>(false);

const handleDotClick = (e: any, width: number, height: number) => {

setDotClickDisabled(true)

anime({
targets: ".dot-point",
scale: [
{ value: 1.35, easing: "easeOutSine", duration: 250 },
Expand All @@ -20,24 +42,10 @@ const handleDotClick = (e: any, width: number, height: number) => {
grid: [width, height],
from: e.target.dataset.index
})
})
}
})

interface WavyDotPatternProps {
className?: string
gridWidth?: number
gridHeight?: number
dotWidth?: number,
dotHeight?: number
}

export const WavyDotPattern = ({
className,
gridWidth,
gridHeight,
dotWidth,
dotHeight
}: WavyDotPatternProps) => {
setTimeout(() => setDotClickDisabled(false), 2000)
}

const GRID_WIDTH = gridWidth ? gridWidth : 30
const GRID_HEIGHT = gridHeight ? gridHeight : 30
Expand All @@ -53,11 +61,12 @@ export const WavyDotPattern = ({

for (let j = 0; j < GRID_HEIGHT; j++) {
dots.push(
<div
<button
className = "p-[0.8rem] rounded-[8px]"
onClick = { (e) => handleDotClick(e, GRID_WIDTH, GRID_HEIGHT) }
data-index = { index }
key = { `${i}-${j}` }
disabled = { dotClickDisabled }
>
<div
className = { cn(
Expand All @@ -68,7 +77,7 @@ export const WavyDotPattern = ({
)}
data-index = { index }
/>
</div>
</button>
);
index++;
}
Expand Down

0 comments on commit 2e42305

Please sign in to comment.