From b42a7b6efb7e295a9ac33813223fc1b9bbe3bf3e Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 5 Aug 2025 23:00:58 +0000 Subject: [PATCH] Add ripple effect to button component cgen-dd64fbd8a4444fc9af3358d3cd41469c --- client/components/ui/button.tsx | 52 +++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/client/components/ui/button.tsx b/client/components/ui/button.tsx index 803df5a8..811e085c 100644 --- a/client/components/ui/button.tsx +++ b/client/components/ui/button.tsx @@ -40,14 +40,54 @@ export interface ButtonProps } const Button = React.forwardRef( - ({ className, variant, size, asChild = false, ...props }, ref) => { + ({ className, variant, size, asChild = false, onClick, ...props }, ref) => { const Comp = asChild ? Slot : "button"; + + const handleClick = (e: React.MouseEvent) => { + // Create ripple effect + const button = e.currentTarget; + const rect = button.getBoundingClientRect(); + const x = e.clientX - rect.left; + const y = e.clientY - rect.top; + + const ripple = document.createElement('span'); + ripple.style.position = 'absolute'; + ripple.style.borderRadius = '50%'; + ripple.style.transform = 'scale(0)'; + ripple.style.animation = 'ripple 0.6s linear'; + ripple.style.backgroundColor = 'rgba(255, 255, 255, 0.3)'; + + const size = Math.max(rect.width, rect.height); + ripple.style.width = ripple.style.height = size + 'px'; + ripple.style.left = x - size / 2 + 'px'; + ripple.style.top = y - size / 2 + 'px'; + + button.appendChild(ripple); + + setTimeout(() => { + ripple.remove(); + }, 600); + + if (onClick) onClick(e); + }; + return ( - + <> + + + ); }, );