| 55 | } |
| 56 | |
| 57 | export function Button({ |
| 58 | className, |
| 59 | variant, |
| 60 | size, |
| 61 | render, |
| 62 | children, |
| 63 | loading = false, |
| 64 | disabled: disabledProp, |
| 65 | ...props |
| 66 | }: ButtonProps): React.ReactElement { |
| 67 | const isDisabled: boolean = Boolean(loading || disabledProp); |
| 68 | const typeValue: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] = |
| 69 | render ? undefined : "button"; |
| 70 | |
| 71 | const defaultProps = { |
| 72 | children: ( |
| 73 | <> |
| 74 | {children} |
| 75 | {loading && ( |
| 76 | <Spinner |
| 77 | className="pointer-events-none absolute" |
| 78 | data-slot="button-loading-indicator" |
| 79 | /> |
| 80 | )} |
| 81 | </> |
| 82 | ), |
| 83 | className: cn(buttonVariants({ className, size, variant })), |
| 84 | "aria-disabled": loading || undefined, |
| 85 | "data-loading": loading ? "" : undefined, |
| 86 | "data-slot": "button", |
| 87 | disabled: isDisabled, |
| 88 | type: typeValue, |
| 89 | }; |
| 90 | |
| 91 | return useRender({ |
| 92 | defaultTagName: "button", |
| 93 | props: mergeProps<"button">(defaultProps, props), |
| 94 | render, |
| 95 | }); |
| 96 | } |