| 1 | import * as React from "react"; |
| 2 | import { cn } from "../../util/cn"; |
| 3 | |
| 4 | type ButtonVariant = "ghost" | "primary" | "secondary" | "outline"; |
| 5 | type ButtonSize = "sm" | "lg"; |
| 6 | |
| 7 | type ButtonProps = React.ComponentProps<"button"> & { |
| 8 | variant?: ButtonVariant; |
| 9 | size?: ButtonSize; |
| 10 | }; |
| 11 | |
| 12 | const buttonVariants = { |
| 13 | primary: |
| 14 | "border-none text-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-badge border-border 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 | }; |
| 22 | |
| 23 | const buttonSizes = { |
| 24 | sm: "px-1.5 py-0.5 text-2xs", |
| 25 | lg: "px-2 py-1 text-sm", |
| 26 | }; |
| 27 | |
| 28 | const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| 29 | ({ variant = "primary", size = "lg", className, ...props }, ref) => { |
| 30 | return ( |
| 31 | <button |
| 32 | ref={ref} |
| 33 | className={cn( |
| 34 | "my-1.5 cursor-pointer rounded transition-all duration-200", |
| 35 | "hover:enabled:cursor-pointer", |
| 36 | "disabled:text-description-muted disabled:pointer-events-none disabled:opacity-50", |
| 37 | buttonVariants[variant], |
| 38 | buttonSizes[size], |
| 39 | className, |
| 40 | )} |
| 41 | style={{ |
| 42 | fontFamily: "system-ui, -apple-system, sans-serif", |
| 43 | ...props.style, |
| 44 | }} |
| 45 | {...props} |
| 46 | /> |
| 47 | ); |
| 48 | }, |
| 49 | ); |
| 50 | |
| 51 | Button.displayName = "Button"; |
| 52 | |
| 53 | export { Button }; |