diff --git a/packages/react/src/components/Button/index.tsx b/packages/react/src/components/Button/index.tsx index c0f08b7..cfb3b62 100644 --- a/packages/react/src/components/Button/index.tsx +++ b/packages/react/src/components/Button/index.tsx @@ -1,4 +1,4 @@ -import React, { ButtonHTMLAttributes, ReactNode } from "react"; +import React, { ButtonHTMLAttributes, forwardRef, ReactNode } from "react"; interface Props extends ButtonHTMLAttributes { color?: "primary" | "secondary" | "tertiary" | "danger"; @@ -8,30 +8,41 @@ interface Props extends ButtonHTMLAttributes { active?: boolean; } -export const Button = ({ - children, - color = "primary", - size = "medium", - iconPosition = "left", - icon, - active, - ...props -}: Props) => { - const classes = ["c__button", "c__button--" + color, "c__button--" + size]; - if (icon && children) { - classes.push("c__button--with-icon--" + iconPosition); +export const Button = forwardRef( + ( + { + children, + color = "primary", + size = "medium", + iconPosition = "left", + icon, + active, + className, + ...props + }, + ref + ) => { + const classes = [ + "c__button", + "c__button--" + color, + "c__button--" + size, + className, + ]; + if (icon && children) { + classes.push("c__button--with-icon--" + iconPosition); + } + if (icon && !children) { + classes.push("c__button--icon-only"); + } + if (active) { + classes.push("c__button--active"); + } + return ( + + ); } - if (icon && !children) { - classes.push("c__button--icon-only"); - } - if (active) { - classes.push("c__button--active"); - } - return ( - - ); -}; +);