@@ -4,7 +4,7 @@ import { motion, useAnimation, type Variants } from "framer-motion";
44import Link from "next/link" ;
55import { cn } from "@/lib/utils" ;
66
7- const ease = [ 0.16 , 1 , 0.3 , 1 ] ;
7+ const ease : [ number , number , number , number ] = [ 0.16 , 1 , 0.3 , 1 ] ;
88
99interface HeroBadgeProps {
1010 href ?: string ;
@@ -46,45 +46,56 @@ export default function HeroBadge({
4646} : HeroBadgeProps ) {
4747 const controls = useAnimation ( ) ;
4848
49- const BadgeWrapper = href ? Link : motion . button ;
50- const wrapperProps = href ? { href } : { onClick } ;
51-
5249 const baseClassName = cn (
5350 "inline-flex items-center rounded-full border transition-colors" ,
5451 badgeVariants [ variant ] ,
5552 sizeVariants [ size ] ,
5653 className
5754 ) ;
55+ const wrapperClassName = cn ( "group" , href ? "cursor-pointer" : undefined ) ;
56+
57+ const content = (
58+ < motion . div
59+ className = { baseClassName }
60+ initial = { { opacity : 0 , y : - 20 } }
61+ animate = { { opacity : 1 , y : 0 } }
62+ transition = { { duration : 0.8 , ease } }
63+ onHoverStart = { ( ) => controls . start ( "hover" ) }
64+ onHoverEnd = { ( ) => controls . start ( "initial" ) }
65+ >
66+ { icon && (
67+ < motion . div
68+ className = "text-foreground/60 transition-colors group-hover:text-primary"
69+ variants = { iconAnimationVariants }
70+ initial = "initial"
71+ animate = { controls }
72+ transition = { { type : "spring" , stiffness : 300 , damping : 10 } }
73+ >
74+ { icon }
75+ </ motion . div >
76+ ) }
77+ < span > { text } </ span >
78+ { endIcon && (
79+ < motion . div className = "text-foreground/60" > { endIcon } </ motion . div >
80+ ) }
81+ </ motion . div >
82+ ) ;
83+
84+ if ( href ) {
85+ return (
86+ < Link href = { href } className = { wrapperClassName } >
87+ { content }
88+ </ Link >
89+ ) ;
90+ }
5891
5992 return (
60- < BadgeWrapper
61- { ...wrapperProps }
62- className = { cn ( "group" , href && "cursor-pointer" ) }
93+ < motion . button
94+ type = "button"
95+ onClick = { onClick }
96+ className = { wrapperClassName }
6397 >
64- < motion . div
65- className = { baseClassName }
66- initial = { { opacity : 0 , y : - 20 } }
67- animate = { { opacity : 1 , y : 0 } }
68- transition = { { duration : 0.8 , ease } }
69- onHoverStart = { ( ) => controls . start ( "hover" ) }
70- onHoverEnd = { ( ) => controls . start ( "initial" ) }
71- >
72- { icon && (
73- < motion . div
74- className = "text-foreground/60 transition-colors group-hover:text-primary"
75- variants = { iconAnimationVariants }
76- initial = "initial"
77- animate = { controls }
78- transition = { { type : "spring" , stiffness : 300 , damping : 10 } }
79- >
80- { icon }
81- </ motion . div >
82- ) }
83- < span > { text } </ span >
84- { endIcon && (
85- < motion . div className = "text-foreground/60" > { endIcon } </ motion . div >
86- ) }
87- </ motion . div >
88- </ BadgeWrapper >
98+ { content }
99+ </ motion . button >
89100 ) ;
90101}
0 commit comments