From c0c6b67710fa13951d2b4fa8b9f83acee7a9fc81 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 25 Mar 2026 23:36:52 +0000 Subject: [PATCH 1/2] Update src/components/button/ButtonBounceEffect/ButtonBounceEffect.tsx --- .../ButtonBounceEffect/ButtonBounceEffect.tsx | 111 +++++++----------- 1 file changed, 43 insertions(+), 68 deletions(-) diff --git a/src/components/button/ButtonBounceEffect/ButtonBounceEffect.tsx b/src/components/button/ButtonBounceEffect/ButtonBounceEffect.tsx index 1df6162..2c75820 100644 --- a/src/components/button/ButtonBounceEffect/ButtonBounceEffect.tsx +++ b/src/components/button/ButtonBounceEffect/ButtonBounceEffect.tsx @@ -1,74 +1,49 @@ -"use client"; +import React, { forwardRef } from "react"; +import { cn } from "@/lib/utils"; +import { useButtonClick } from "@/components/button/useButtonClick"; +import { ButtonProps } from "@/components/button/button.types"; -import { useRef, memo } from "react"; -import { useCharAnimation } from "../useCharAnimation"; -import { useButtonClick } from "../useButtonClick"; -import { cls } from "@/lib/utils"; -import "./BounceButton.css"; +export const ButtonBounceEffect = forwardRef( + ( + { + text, + onClick, + href, + className, + bgClassName, + textClassName, + iconClassName, + disabled = false, + ariaLabel, + type = "button", newTab, + ...props + }, + ref + ) => { + const clickHandler = useButtonClick(href, onClick, newTab); -interface ButtonBounceEffectProps { - text: string; - onClick?: () => void; - href?: string; - className?: string; - bgClassName?: string; - textClassName?: string; - disabled?: boolean; - ariaLabel?: string; - type?: "button" | "submit" | "reset"; - scrollToSection?: boolean; -} - -const ButtonBounceEffect = ({ - text, - onClick, - href, - className = "", - bgClassName = "", - textClassName = "", - disabled = false, - ariaLabel, - type = "button", - scrollToSection, -}: ButtonBounceEffectProps) => { - const buttonRef = useRef(null); - const handleClick = useButtonClick(href, onClick, scrollToSection); - - useCharAnimation(buttonRef, text); - - return ( - - ); -}; + + {text} + + + ); + } +); ButtonBounceEffect.displayName = "ButtonBounceEffect"; - -export default memo(ButtonBounceEffect); -- 2.49.1 From 99daeff82c6b6f64ff1cc99e085fe8f678404a97 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 25 Mar 2026 23:36:52 +0000 Subject: [PATCH 2/2] Update src/components/button/useButtonClick.ts --- src/components/button/useButtonClick.ts | 40 +++++++++++-------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/components/button/useButtonClick.ts b/src/components/button/useButtonClick.ts index 2d2b89b..88ce15b 100644 --- a/src/components/button/useButtonClick.ts +++ b/src/components/button/useButtonClick.ts @@ -1,58 +1,54 @@ import { useRouter } from "next/navigation"; +import React from "react"; -export const useButtonClick = () => { +export const useButtonClick = ( + href?: string, + onClickProp?: () => void, + newTab?: boolean +) => { const router = useRouter(); - const handleClick = ( - href?: string, - onClick?: () => void, - newTab?: boolean - ) => { - return (event: React.MouseEvent) => { + const handleClick = React.useCallback( + (event: React.MouseEvent) => { if (href) { - // Prevent default behavior if an href is provided, as we will handle navigation manually - // This is crucial for hash links and internal Next.js navigation event.preventDefault(); } - if (onClick) { - onClick(); + if (onClickProp) { + onClickProp(); } if (href) { if (href.startsWith("http") || href.startsWith("mailto:") || href.startsWith("tel:")) { - // External link, mailto, or tel if (newTab) { window.open(href, "_blank", "noopener,noreferrer"); } else { window.location.href = href; } } else if (href.startsWith("#")) { - // Scroll to section for hash links const targetId = href.substring(1); - // Use getElementById for robust targeting of elements by ID const targetElement = document.getElementById(targetId); if (targetElement) { targetElement.scrollIntoView({ - behavior: "smooth"}); - // Optionally update URL hash without a full page reload for better UX + behavior: "smooth" + }); window.history.pushState(null, "", href); } else if (targetId === '') { - // Handle `href="#"` to scroll to top (or do nothing if preferred for placeholder) window.scrollTo({ top: 0, - behavior: "smooth"}); - window.history.pushState(null, '', '/'); // Clear hash + behavior: "smooth" + }); + window.history.pushState(null, '', '/'); } else { console.warn(`Element with ID "${targetId}" not found for smooth scroll.`); } } else { - // Internal page navigation using Next.js router router.push(href); } } - }; - }; + }, + [router, href, onClickProp, newTab] + ); return handleClick; }; -- 2.49.1