|
1 | 1 | import { mergeProps, useRender } from "@base-ui-components/react"; |
2 | | -import type * as React from "react"; |
| 2 | +import * as React from "react"; |
3 | 3 | import { cn } from "../lib/cn"; |
4 | 4 | import { cva, cx, type VariantProps } from "../lib/cva"; |
5 | 5 |
|
@@ -55,29 +55,26 @@ export interface ButtonProps |
55 | 55 | extends useRender.ComponentProps<"button">, |
56 | 56 | VariantProps<typeof buttonVariants> {} |
57 | 57 |
|
58 | | -const Button = ({ |
59 | | - className, |
60 | | - variant, |
61 | | - size, |
62 | | - iconStyle, |
63 | | - render, |
64 | | - ...props |
65 | | -}: ButtonProps) => { |
66 | | - const typeValue: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] = |
67 | | - render ? undefined : "button"; |
| 58 | +const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| 59 | + ({ className, variant, size, iconStyle, render, ...props }, ref) => { |
| 60 | + const typeValue: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] = |
| 61 | + render ? undefined : "button"; |
68 | 62 |
|
69 | | - const defaultProps = { |
70 | | - "data-slot": "button", |
71 | | - "data-disabled": props.disabled, |
72 | | - className: cn(buttonVariants({ variant, size, iconStyle, className })), |
73 | | - type: typeValue, |
74 | | - }; |
| 63 | + const defaultProps = { |
| 64 | + "data-slot": "button", |
| 65 | + "data-disabled": props.disabled, |
| 66 | + className: cn(buttonVariants({ variant, size, iconStyle, className })), |
| 67 | + type: typeValue, |
| 68 | + }; |
75 | 69 |
|
76 | | - return useRender({ |
77 | | - defaultTagName: "button", |
78 | | - render, |
79 | | - props: mergeProps<"button">(defaultProps, props), |
80 | | - }); |
81 | | -}; |
| 70 | + return useRender({ |
| 71 | + ref, |
| 72 | + defaultTagName: "button", |
| 73 | + render, |
| 74 | + props: mergeProps<"button">(defaultProps, props), |
| 75 | + }); |
| 76 | + }, |
| 77 | +); |
| 78 | +Button.displayName = "Button"; |
82 | 79 |
|
83 | 80 | export { Button, buttonVariants }; |
0 commit comments