1import * as React from "react"
2import { Slot } from "@radix-ui/react-slot"
3import { cva } from "class-variance-authority"
4
5import { cn } from "@/lib/utils"
6
7const outerDivVariants = cva("relative inline-block overflow-hidden ", {
8 variants: {
9 size: {
10 sm: "",
11 default: "",
12 lg: "",
13 },
14 rounded: {
15 full: "rounded-full before:rounded-full",
16 xl: "rounded-xl before:rounded-xl",
17 "2xl": "rounded-2xl before:rounded-2xl",
18 "3xl": "rounded-3xl before:rounded-3xl",
19 sm: "rounded-sm before:rounded-sm",
20 xs: "rounded-xs before:rounded-xs",
21 base: "rounded before:rounded",
22 },
23 },
24 defaultVariants: {
25 size: "default",
26 },
27})
28
29const innerSpanVariants = cva(
30 [
31 "absolute inset-[-1000%] m-auto block ", // Base styles for positioning and display
32 ],
33 {
34 variants: {
35 animation: {
36 pulse: "animate-pulse", // Pulsating effect
37 "spin-fast": "animate-[spin_2s_linear_infinite]", // Continuous rotation
38 "spin-slow": "animate-[spin_8s_linear_infinite]", // Bouncing effect
39 spin: "animate-[spin_4s_linear_infinite]", // Bouncing effect
40 // Add more animations here
41 },
42 gradient: {
43 sunrise: "text-black font-bold",
44 ocean:
45 "bg-[conic-gradient(from_90deg_at_50%_50%,#a1c4fd_0%,#c2e9fb_50%,#a1c4fd_100%)] ",
46 candy:
47 "bg-[conic-gradient(from_90deg_at_50%_50%,#ff9a9e_0%,#fad0c4_50%,#fad0c4_90%,#ff9a9e_100%)] ",
48 forest:
49 "bg-[conic-gradient(from_90deg_at_50%_50%,#85d797_0%,#1a806b_50%,#85d797_100%)] ",
50 sunset:
51 "bg-[conic-gradient(from_90deg_at_50%_50%,#fe5d75_0%,#f5af19_50%,#fe5d75_100%)] ",
52 nebula:
53 "bg-[conic-gradient(from_90deg_at_50%_50%,#A77BFE_0%,#8860D0_50%,#A77BFE_100%)] ",
54 default:
55 "bg-[conic-gradient(from_90deg_at_50%_50%,#E2CBFF_0%,#393BB2_50%,#E2CBFF_100%)] ",
56 },
57 },
58 compoundVariants: [
59 {
60 animation: "spin",
61 gradient: "sunrise",
62 className: "duration-4s ease-linear", // Customizes the animation duration and easing for a specific variant
63 },
64 ],
65 defaultVariants: {
66 animation: "spin",
67 gradient: "forest",
68 },
69 }
70)
71
72const buttonVariants = cva(
73 "relative px-6 py-2 transition-all duration-150 ease-in-out disabled:pointer-events-none disabled:opacity-50 text-sm overflow-hidden",
74 {
75 variants: {
76 size: {
77 sm: "text-xs px-4 py-1",
78 default: "text-sm px-6 py-2",
79 lg: "text-base px-8 py-3",
80 },
81 shadow: {
82 flat: "",
83 soft: "shadow-[0_2px_4px_rgba(0,0,0,0.15),inset_0_1px_1px_rgba(255,255,255,0.15),inset_0_-1px_2px_rgba(0,0,0,0.3)] dark:shadow-[0_2px_4px_rgba(0,0,0,0.25),inset_0_1px_1px_rgba(0,0,0,0.2),inset_0_-1px_2px_rgba(0,0,0,0.5)]",
84 base: "shadow-[0_3px_5px_rgba(0,0,0,0.2),inset_0_0.5px_1px_rgba(255,255,255,0.1),inset_0_-2px_3px_rgba(0,0,0,0.4)] dark:shadow-[0_3px_5px_rgba(0,0,0,0.3),inset_0_0.5px_1px_rgba(0,0,0,0.2),inset_0_-2px_3px_rgba(0,0,0,0.6)]",
85 deep: "shadow-[0_4px_6px_rgba(0,0,0,0.25),inset_0_1px_2px_rgba(255,255,255,0.2),inset_0_-2px_4px_rgba(0,0,0,0.5)] dark:shadow-[0_4px_6px_rgba(0,0,0,0.35),inset_0_1px_2px_rgba(0,0,0,0.3),inset_0_-2px_4px_rgba(0,0,0,0.7)]",
86 deeper:
87 "shadow-[0_6px_8px_rgba(0,0,0,0.3),inset_0_2px_3px_rgba(255,255,255,0.25),inset_0_-3px_6px_rgba(0,0,0,0.6)] dark:shadow-[0_6px_8px_rgba(0,0,0,0.4),inset_0_2px_3px_rgba(0,0,0,0.35),inset_0_-3px_6px_rgba(0,0,0,0.8)]",
88 },
89 gradient: {
90 sunrise: "text-black font-bold",
91 ocean: "text-black font-bold",
92 candy: "text-black font-bold",
93 forest: "text-black font-bold",
94 sunset: "text-black font-bold",
95 nebula: "text-white font-bold",
96 default: "text-white font-bold",
97 },
98 rounded: {
99 full: "rounded-full before:rounded-full",
100 xl: "rounded-xl before:rounded-xl",
101 "2xl": "rounded-2xl before:rounded-2xl",
102 "3xl": "rounded-3xl before:rounded-3xl",
103 sm: "rounded-sm before:rounded-sm",
104 xs: "rounded-xs before:rounded-xs",
105 base: "rounded before:rounded",
106 },
107 },
108 defaultVariants: {
109 size: "default",
110 shadow: "base",
111 rounded: "xl",
112 },
113 }
114)
115
116export interface UnifiedButtonProps
117 extends React.ButtonHTMLAttributes<HTMLButtonElement> {
118 variant?: "primary" | "success" | "secondary" | "destructive" | "ghost"
119 size?: "sm" | "lg" | "default"
120 shadow?: "flat" | "soft" | "base" | "deep" | "deeper"
121 rounded?: "full" | "xl" | "2xl" | "3xl" | "sm" | "xs" | "base"
122 asChild?: boolean
123 showBackground?: boolean
124 animation?: "spin" | "pulse" | "spin-slow" | "spin-fast" | "spin"
125 gradient?:
126 | "sunrise"
127 | "ocean"
128 | "candy"
129 | "default"
130 | "forest"
131 | "sunset"
132 | "nebula"
133}
134
135const BgAnimateButton = React.forwardRef<HTMLButtonElement, UnifiedButtonProps>(
136 (
137 {
138 variant = "primary",
139 size = "default",
140 showBackground = false,
141 rounded = "full",
142 shadow = "soft",
143 gradient = null,
144 animation = null,
145 className,
146 asChild = false,
147 ...props
148 },
149 ref
150 ) => {
151 const Comp = asChild ? Slot : "button"
152
153 return (
154 <Comp
155 className={cn(outerDivVariants({ size, rounded }), className)}
156 ref={ref}
157 {...props}
158 >
159 {gradient && (
160 <span className={cn(innerSpanVariants({ gradient, animation }))} />
161 )}
162
163 <div
164 className={cn(buttonVariants({ shadow, rounded, size, gradient }))}
165 >
166 {props.children || "Button"}
167 </div>
168 </Comp>
169 )
170 }
171)
172
173BgAnimateButton.displayName = "BgAnimateButton"
174
175export { BgAnimateButton }
176export default BgAnimateButton
177