Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-bats-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zenml-io/react-component-library": patch
---

add ref to button component
28 changes: 20 additions & 8 deletions src/components/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ButtonHTMLAttributes } from "react";
import React, { ButtonHTMLAttributes, forwardRef } from "react";
import { Slot } from "@radix-ui/react-slot";
import { type VariantProps, cva } from "class-variance-authority";
import { cn } from "../../utilities/index";
Expand All @@ -18,9 +18,9 @@ const buttonVariants = cva(
danger: ""
},
size: {
sm: "py-1 px-2",
lg: "py-2 px-3",
xl: "py-3 px-5"
sm: "py-1 px-2 text-text-sm",
lg: "py-2 px-3 text-text-md",
xl: "py-3 px-5 text-text-lg"
}
},
compoundVariants: [
Expand Down Expand Up @@ -96,7 +96,19 @@ export interface ButtonProps
asChild?: boolean;
}

export function Button({ intent, size, className, asChild, emphasis, ...rest }: ButtonProps) {
const Comp = asChild ? Slot : "button";
return <Comp className={cn(buttonVariants({ intent, size, emphasis }), className)} {...rest} />;
}
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ intent, size, className, asChild, emphasis, ...rest }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
ref={ref}
className={cn(buttonVariants({ intent, size, emphasis }), className)}
{...rest}
/>
);
}
);

Button.displayName = "Button";

export { Button };