| 1 | import * as React from "react" |
| 2 | import { cva, type |
| 3 | import { Slot } |
| 4 | import { Loader2 } |
| 5 | import { useHotkeys } |
| 6 | import { Kbd } |
| 7 | import { cn } |
| 8 | import { buttonVariants } |
| 9 | |
| 10 | |
| 11 | |
| 12 | function Button({ |
| 13 | className, |
| 14 | variant = "default" |
| 15 | size = "sm" |
| 16 | asChild = false, |
| 17 | loading = false, |
| 18 | disabled = false, |
| 19 | kbd, |
| 20 | children, |
| 21 | ...props |
| 22 | }: React. |
| 23 | VariantProps<typeof |
| 24 | asChild?: boolean |
| 25 | loading?: boolean |
| 26 | kbd?: string |
| 27 | }) { |
| 28 | const Comp = |
| 29 | |
| 30 | useHotkeys( |
| 31 | kbd ?? "", |
| 32 | (event) => |
| 33 | event.preventDefault() |
| 34 | props.onClick?.(event |
| 35 | }, |
| 36 | { |
| 37 | enabled: Boolean(kbd |
| 38 | enableOnFormTags: false, |
| 39 | enableOnContentEditable: false, |
| 40 | }, |
| 41 | [kbd, disabled, |
| 42 | ) |
| 43 | |
| 44 | return ( |
| 45 | <Comp |
| 46 | data-slot="button" |
| 47 | data-variant={variant} |
| 48 | data-size={size} |
| 49 | disabled={disabled || |
| 50 | className={cn(buttonVariants |
| 51 | {...props} |
| 52 | > |
| 53 | {loading ? ( |
| 54 | <Loader2 className=" |
| 55 | ) : asChild ? |
| 56 | children |
| 57 | ) : ( |
| 58 | <> |
| 59 | {children} |
| 60 | {kbd && ( |
| 61 | <Kbd |
| 62 | className={cn( |
| 63 | variant === "default" |
| 64 | "bg-primary-foreground/15 text-primary-foreground", |
| 65 | variant === "secondary" |
| 66 | "bg-secondary-foreground/10 text-secondary-foreground", |
| 67 | variant === "destructive" |
| 68 | "bg-destructive/15 text-destructive dark:bg-destructive/30" |
| 69 | )} |
| 70 | > |
| 71 | {kbd} |
| 72 | </Kbd> |
| 73 | )} |
| 74 | </> |
| 75 | )} |
| 76 | </Comp> |
| 77 | ) |
| 78 | } |
| 79 | |
| 80 | export { Button, buttonVariants |