1import * as React from "react";
2import { Slot } from "@radix-ui/react-slot";
3import { cn } from "@/lib/utils";
4
5type Color =
6 | "default"
7 | "blue"
8 | "purple"
9 | "pink"
10 | "red"
11 | "orange"
12 | "yellow"
13 | "green"
14 | "teal"
15 | "cyan"
16 | "indigo"
17 | "violet"
18 | "rose"
19 | "amber"
20 | "lime"
21 | "sky"
22 | "slate"
23 | "gray"
24 | "zinc"
25 | "neutral"
26 | "stone"
27 | "fuchsia"
28 | "emerald";
29
30type SizeVariant = "sm" | "default" | "lg";
31
32interface RichButtonProps
33 extends React.ButtonHTMLAttributes<HTMLButtonElement> {
34 children: React.ReactNode;
35 color?: Color;
36 size?: SizeVariant;
37 className?: string;
38 asChild?: boolean;
39}
40
41const colorMap: Record<Color, string> = {
42 default:
43 "from-zinc-900/85 to-zinc-900 dark:from-zinc-100/85 dark:to-zinc-100",
44 emerald: "from-emerald-600/85 to-emerald-600 dark:from-emerald-600/75",
45 blue: "from-blue-600/85 to-blue-600 dark:from-blue-600/75",
46 purple: "from-purple-600/85 to-purple-600 dark:from-purple-600/75",
47 pink: "from-pink-600/85 to-pink-600 dark:from-pink-600/75",
48 red: "from-red-600/85 to-red-600 dark:from-red-600/75",
49 orange: "from-orange-600/85 to-orange-600 dark:from-orange-600/75",
50 yellow: "from-yellow-600/85 to-yellow-600 dark:from-yellow-600/75",
51 green: "from-green-600/85 to-green-600 dark:from-green-600/75",
52 teal: "from-teal-600/85 to-teal-600 dark:from-teal-600/75",
53 cyan: "from-cyan-600/85 to-cyan-600 dark:from-cyan-600/75",
54 indigo: "from-indigo-600/85 to-indigo-600 dark:from-indigo-600/75",
55 violet: "from-violet-600/85 to-violet-600 dark:from-violet-600/75",
56 rose: "from-rose-600/85 to-rose-600 dark:from-rose-600/75",
57 amber: "from-amber-600/85 to-amber-600 dark:from-amber-600/75",
58 lime: "from-lime-600/85 to-lime-600 dark:from-lime-600/75",
59 sky: "from-sky-600/85 to-sky-600 dark:from-sky-600/75",
60 slate: "from-slate-600/85 to-slate-600 dark:from-slate-600/75",
61 gray: "from-gray-600/85 to-gray-600 dark:from-gray-600/75",
62 zinc: "from-zinc-700/85 to-zinc-700 dark:from-zinc-700/75",
63 neutral: "from-neutral-600/85 to-neutral-600 dark:from-neutral-600/75",
64 stone: "from-stone-600/85 to-stone-600 dark:from-stone-600/75",
65 fuchsia: "from-fuchsia-600/85 to-fuchsia-600 dark:from-fuchsia-600/75",
66};
67
68const textShadowMap: Record<Color, string> = {
69 default:
70 "[text-shadow:0_1px_0_rgb(0,0,0)] dark:[text-shadow:0_1px_0_rgb(255,255,255)]",
71 emerald: "[text-shadow:0_1px_0_var(--color-emerald-800)]",
72 blue: "[text-shadow:0_1px_0_var(--color-blue-800)]",
73 purple: "[text-shadow:0_1px_0_var(--color-purple-800)]",
74 pink: "[text-shadow:0_1px_0_var(--color-pink-800)]",
75 red: "[text-shadow:0_1px_0_var(--color-red-800)]",
76 orange: "[text-shadow:0_1px_0_var(--color-orange-800)]",
77 yellow: "[text-shadow:0_1px_0_var(--color-yellow-800)]",
78 green: "[text-shadow:0_1px_0_var(--color-green-800)]",
79 teal: "[text-shadow:0_1px_0_var(--color-teal-800)]",
80 cyan: "[text-shadow:0_1px_0_var(--color-cyan-800)]",
81 indigo: "[text-shadow:0_1px_0_var(--color-indigo-800)]",
82 violet: "[text-shadow:0_1px_0_var(--color-violet-800)]",
83 rose: "[text-shadow:0_1px_0_var(--color-rose-800)]",
84 amber: "[text-shadow:0_1px_0_var(--color-amber-800)]",
85 lime: "[text-shadow:0_1px_0_var(--color-lime-800)]",
86 sky: "[text-shadow:0_1px_0_var(--color-sky-800)]",
87 slate: "[text-shadow:0_1px_0_var(--color-slate-800)]",
88 gray: "[text-shadow:0_1px_0_var(--color-gray-800)]",
89 zinc: "[text-shadow:0_1px_0_var(--color-zinc-800)]",
90 neutral: "[text-shadow:0_1px_0_var(--color-neutral-800)]",
91 stone: "[text-shadow:0_1px_0_var(--color-stone-800)]",
92 fuchsia: "[text-shadow:0_1px_0_var(--color-fuchsia-800)]",
93};
94
95const sizeMap: Record<SizeVariant, string> = {
96 sm: "h-8 rounded-md gap-1.5 px-3 text-sm",
97 default: "h-9 px-4 py-2 text-sm rounded-md",
98 lg: "h-10 rounded-md px-6 text-base",
99};
100
101const RichButton = React.forwardRef<HTMLButtonElement, RichButtonProps>(
102 (
103 {
104 children,
105 color = "default",
106 size = "default",
107 className,
108 asChild = false,
109 ...props
110 },
111 ref,
112 ) => {
113 const Comp = asChild ? Slot : "button";
114 const colorClasses = colorMap[color];
115 const textShadowClasses = textShadowMap[color];
116 const sizeClasses = sizeMap[size];
117 const textColor = color === "default"
118 ? "text-white dark:text-zinc-900"
119 : "text-white";
120
121 return (
122 <Comp
123 ref={ref}
124 className={cn(
125 "cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 inset-shadow-2xs inset-shadow-white/25 bg-linear-to-b dark:bg-linear-to-t border border-zinc-950/35 shadow-md shadow-zinc-950/20 ring-0 transition-[filter] duration-200 hover:brightness-110 active:brightness-95 dark:border-0 dark:border-zinc-950/50",
126 colorClasses,
127 sizeClasses,
128 textColor,
129 className,
130 )}
131 {...props}
132 >
133 {asChild
134 ? children
135 : typeof children === "string"
136 ? (
137 <span className={cn("relative", textShadowClasses)}>
138 {children}
139 </span>
140 )
141 : (
142 <div
143 className={cn(
144 "relative flex items-center gap-2",
145 textShadowClasses,
146 )}
147 >
148 {children}
149 </div>
150 )}
151 </Comp>
152 );
153 },
154);
155
156RichButton.displayName = "RichButton";
157
158export { RichButton };
159