Skip to content

Commit 8ced43f

Browse files
committed
update hero badge
1 parent 0efd512 commit 8ced43f

File tree

1 file changed

+43
-32
lines changed

1 file changed

+43
-32
lines changed

apps/web/src/components/ui/hero-badge.tsx

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { motion, useAnimation, type Variants } from "framer-motion";
44
import Link from "next/link";
55
import { 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

99
interface 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

Comments
 (0)