| 1 | import * as React from "react"; |
| 2 | import { cn } from "../../util/cn"; |
| 3 | import { FontSizeModifier, useFontSize } from "./font"; |
| 4 | |
| 5 | type ButtonVariant = "ghost" | "primary" | "secondary" | "outline"; |
| 6 | |
| 7 | type ButtonProps = React.ComponentProps<"button"> & { |
| 8 | variant?: ButtonVariant; |
| 9 | fontSizeModifier?: FontSizeModifier; |
| 10 | }; |
| 11 | |
| 12 | const buttonVariants = { |
| 13 | primary: |
| 14 | "px-3 py-1.5 border-none text-background bg-foreground hover:enabled:brightness-125", |
| 15 | secondary: |
| 16 | "px-3 py-1.5 border-none text-foreground bg-input hover:enabled:bg-gray-500/20", |
| 17 | outline: |
| 18 | "px-3 py-1.5 border border-foreground text-foreground bg-transparent hover:enabled:bg-input", |
| 19 | ghost: |
| 20 | "px-2 py-1.5 border-none text-foreground bg-gray-500/40 hover:enabled:brightness-125", |
| 21 | }; |
| 22 | |
| 23 | const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| 24 | ({ variant = "primary", fontSizeModifier = 0, className, ...props }, ref) => { |
| 25 | const fontSize = useFontSize(fontSizeModifier); |
| 26 | |
| 27 | return ( |
| 28 | <button |
| 29 | ref={ref} |
| 30 | className={cn( |
| 31 | "my-1.5 cursor-pointer rounded transition-all duration-200", |
| 32 | "hover:enabled:cursor-pointer", |
| 33 | "disabled:text-description-muted disabled:pointer-events-none disabled:opacity-50", |
| 34 | buttonVariants[variant], |
| 35 | className, |
| 36 | )} |
| 37 | style={{ |
| 38 | fontSize, |
| 39 | ...props.style, |
| 40 | }} |
| 41 | {...props} |
| 42 | /> |
| 43 | ); |
| 44 | }, |
| 45 | ); |
| 46 | |
| 47 | Button.displayName = "Button"; |
| 48 | |
| 49 | export { Button }; |