1import React, { type ComponentPropsWithoutRef, type CSSProperties } from "react"
2
3import { cn } from "@/lib/utils"
4
5export interface ShimmerButtonProps extends ComponentPropsWithoutRef<"button"> {
6 shimmerColor?: string
7 shimmerSize?: string
8 borderRadius?: string
9 shimmerDuration?: string
10 background?: string
11 className?: string
12 children?: React.ReactNode
13}
14
15export const ShimmerButton = React.forwardRef<
16 HTMLButtonElement,
17 ShimmerButtonProps
18>(
19 (
20 {
21 shimmerColor = "#ffffff",
22 shimmerSize = "0.05em",
23 shimmerDuration = "3s",
24 borderRadius = "100px",
25 background = "rgba(0, 0, 0, 1)",
26 className,
27 children,
28 ...props
29 },
30 ref
31 ) => {
32 return (
33 <button
34 style={
35 {
36 "--spread": "90deg",
37 "--shimmer-color": shimmerColor,
38 "--radius": borderRadius,
39 "--speed": shimmerDuration,
40 "--cut": shimmerSize,
41 "--bg": background,
42 } as CSSProperties
43 }
44 className={cn(
45 "group relative z-0 flex cursor-pointer items-center justify-center overflow-hidden [border-radius:var(--radius)] border border-white/10 px-6 py-3 whitespace-nowrap text-white [background:var(--bg)]",
46 "transform-gpu transition-transform duration-300 ease-in-out active:translate-y-px",
47 className
48 )}
49 ref={ref}
50 {...props}
51 >
52 {/* spark container */}
53 <div
54 className={cn(
55 "-z-30 blur-[2px]",
56 "@container-[size] absolute inset-0 overflow-visible"
57 )}
58 >
59 {/* spark */}
60 <div className="animate-shimmer-slide absolute inset-0 aspect-[1] h-[100cqh] rounded-none [mask:none]">
61 {/* spark before */}
62 <div className="animate-spin-around absolute -inset-full w-auto [translate:0_0] rotate-0 [background:conic-gradient(from_calc(270deg-(var(--spread)*0.5)),transparent_0,var(--shimmer-color)_var(--spread),transparent_var(--spread))]" />
63 </div>
64 </div>
65 {children}
66
67 {/* Highlight */}
68 <div
69 className={cn(
70 "absolute inset-0 size-full",
71
72 "rounded-2xl px-4 py-1.5 text-sm font-medium shadow-[inset_0_-8px_10px_#ffffff1f]",
73
74 // transition
75 "transform-gpu transition-all duration-300 ease-in-out",
76
77 // on hover
78 "group-hover:shadow-[inset_0_-6px_10px_#ffffff3f]",
79
80 // on click
81 "group-active:shadow-[inset_0_-10px_10px_#ffffff3f]"
82 )}
83 />
84
85 {/* backdrop */}
86 <div
87 className={cn(
88 "absolute inset-(--cut) -z-20 [border-radius:var(--radius)] [background:var(--bg)]"
89 )}
90 />
91 </button>
92 )
93 }
94)
95
96ShimmerButton.displayName = "ShimmerButton"
97