Elffuss BraidHub

kikocis/continue public

main · 1.8 KiBRawPermalink
1import * as React from "react";
2import { cn } from "../../util/cn";
3
4type ButtonVariant = "ghost" | "primary" | "secondary" | "outline" | "icon";
5type ButtonSize = "sm" | "lg";
6
7type ButtonProps = React.ComponentProps<"button"> & {
8 variant?: ButtonVariant;
9 size?: ButtonSize;
10};
11
12const buttonVariants = {
13 primary:
14 "border-none text-primary-foreground bg-primary hover:enabled:brightness-125",
15 secondary:
16 "border-none text-foreground bg-border hover:enabled:brightness-125",
17 outline:
18 "border border-solid border-description text-foreground bg-transparent hover:enabled:bg-input",
19 ghost:
20 "border-none text-foreground bg-inherit hover:enabled:brightness-125 hover:enabled:bg-input",
21 icon: "border border-solid border-description text-description bg-transparent hover:enabled:text-foreground hover:enabled:bg-input hover:enabled:border-description rounded-full p-0 flex items-center justify-center",
22};
23
24const buttonSizes = {
25 sm: "px-1.5 py-0.5 text-2xs",
26 lg: "px-2 py-1 text-sm",
27};
28
29const iconButtonSizes = {
30 sm: "h-4 w-4",
31 lg: "h-5 w-5",
32};
33
34const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
35 ({ variant = "primary", size = "lg", className, ...props }, ref) => {
36 const isIcon = variant === "icon";
37 return (
38 <button
39 ref={ref}
40 className={cn(
41 "cursor-pointer transition-all duration-200",
42 "hover:enabled:cursor-pointer",
43 "disabled:cursor-not-allowed disabled:opacity-50",
44 buttonVariants[variant],
45 isIcon
46 ? iconButtonSizes[size]
47 : `my-1.5 rounded ${buttonSizes[size]}`,
48 className,
49 )}
50 style={{
51 fontFamily: "system-ui, -apple-system, sans-serif",
52 ...props.style,
53 }}
54 {...props}
55 />
56 );
57 },
58);
59
60Button.displayName = "Button";
61
62export { Button };