1"use client"
2
3import React from "react"
4import { motion, type MotionProps } from "motion/react"
5
6import { cn } from "@/lib/utils"
7
8const animationProps: MotionProps = {
9 initial: { "--x": "100%", scale: 0.8 },
10 animate: { "--x": "-100%", scale: 1 },
11 whileTap: { scale: 0.95 },
12 transition: {
13 repeat: Infinity,
14 repeatType: "loop",
15 repeatDelay: 1,
16 type: "spring",
17 stiffness: 20,
18 damping: 15,
19 mass: 2,
20 scale: {
21 type: "spring",
22 stiffness: 200,
23 damping: 5,
24 mass: 0.5,
25 },
26 },
27}
28
29interface ShinyButtonProps
30 extends
31 Omit<React.HTMLAttributes<HTMLElement>, keyof MotionProps>,
32 MotionProps {
33 children: React.ReactNode
34 className?: string
35}
36
37export const ShinyButton = React.forwardRef<
38 HTMLButtonElement,
39 ShinyButtonProps
40>(({ children, className, ...props }, ref) => {
41 return (
42 <motion.button
43 ref={ref}
44 className={cn(
45 "relative cursor-pointer rounded-lg border px-6 py-2 font-medium backdrop-blur-xl transition-shadow duration-300 ease-in-out hover:shadow dark:bg-[radial-gradient(circle_at_50%_0%,var(--primary)/10%_0%,transparent_60%)] dark:hover:shadow-[0_0_20px_var(--primary)/10%]",
46 className
47 )}
48 {...animationProps}
49 {...props}
50 >
51 <span
52 className="relative block size-full text-sm tracking-wide text-[rgb(0,0,0,65%)] uppercase dark:font-light dark:text-[rgb(255,255,255,90%)]"
53 style={{
54 maskImage:
55 "linear-gradient(-75deg,var(--primary) calc(var(--x) + 20%),transparent calc(var(--x) + 30%),var(--primary) calc(var(--x) + 100%))",
56 }}
57 >
58 {children}
59 </span>
60 <span
61 style={{
62 mask: "linear-gradient(rgb(0,0,0), rgb(0,0,0)) content-box exclude,linear-gradient(rgb(0,0,0), rgb(0,0,0))",
63 WebkitMask:
64 "linear-gradient(rgb(0,0,0), rgb(0,0,0)) content-box exclude,linear-gradient(rgb(0,0,0), rgb(0,0,0))",
65 backgroundImage:
66 "linear-gradient(-75deg,var(--primary)/10% calc(var(--x)+20%),var(--primary)/50% calc(var(--x)+25%),var(--primary)/10% calc(var(--x)+100%))",
67 }}
68 className="absolute inset-0 z-10 block rounded-[inherit] p-px"
69 />
70 </motion.button>
71 )
72})
73
74ShinyButton.displayName = "ShinyButton"
75