Skip to content

feat: button component #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: button component #26

wants to merge 2 commits into from

Conversation

rfaria107
Copy link

@rfaria107 rfaria107 commented Jul 8, 2025

closes #2

Some usage examples:

exampleButtons image

@rfaria107 rfaria107 requested review from nunom27 and joaodiaslobo July 8, 2025 21:43
@rfaria107 rfaria107 self-assigned this Jul 8, 2025
@deployum
Copy link

deployum bot commented Jul 8, 2025

The preview deployment is ready. 🟢

Open Preview | Open Build Logs

Last updated at: 2025-07-10 22:28:26 CET

Copy link
Contributor

@enricoprazeres enricoprazeres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there could be cases when there is only an icon with no text, and for screen readers it is bad because they rely on the text to narrate the content of the page to the user. Consider adding another prop for the ariaLabel, and add it to the button/link directly.

aria-label={ariaLabel}

@rfaria107 rfaria107 requested a review from enricoprazeres July 10, 2025 22:27
import { ReactNode } from "react";
import Link from "next/link";

interface IButtonProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface IButtonProps {
interface IButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {

By doing this we could remove the props from lines 19-22. Consider changing it so we can clean up the code a bit.

Comment on lines +49 to +53
const variantMap: Record<"filled" | "outline" | "text", string> = {
filled: `${bgColor} ${textColor} ${borderColor}`,
outline: `bg-transparent ${textColor} ${borderColor}`,
text: `bg-transparent ${textColor} border-transparent`,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove these props, remove also the variantMap.

Comment on lines +39 to +42
onClick,
className = "",
ariaLabel,
type = "button",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may remove this since you'll have the button props extended into the interface, and it already includes everything.

Suggested change
onClick,
className = "",
ariaLabel,
type = "button",

Comment on lines +28 to +34
variant = "filled",
bgColor = "bg-white",
textColor = "text-black",
borderColor = "transparent",
borderRadius = "rounded",
borderWidth = "border",
padding = "px-4 py-2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these props are replaceable for the className

Comment on lines +19 to +22
onClick?: () => void;
className?: string;
ariaLabel?: string;
type?: "button" | "submit" | "reset";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you follow the precious suggestion, you'll want to remove this.

Suggested change
onClick?: () => void;
className?: string;
ariaLabel?: string;
type?: "button" | "submit" | "reset";

Comment on lines +57 to +62
sizeMap[size],
variantMap[variant],
padding,
borderRadius,
borderWidth,
className,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sizeMap[size],
variantMap[variant],
padding,
borderRadius,
borderWidth,
className,
sizeMap[size],

};

const baseStyle = [
"inline-flex items-center justify-center font-medium",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"inline-flex items-center justify-center font-medium",
"font-medium rounded-md transition-colors duration-200 cursor-pointer border",

padding = "px-4 py-2",
icon,
iconPosition = "left",
as = "button",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need that as I will explain later

Suggested change
as = "button",

Comment on lines +82 to +115
const isExternalLink =
href.startsWith("http") ||
href.startsWith("mailto:") ||
href.startsWith("tel:");
return (
<Link
href={href}
className={baseStyle}
aria-label={ariaLabel}
{...(isExternalLink
? { target: "_blank", rel: "noopener noreferrer" }
: {})}
>
{content}
</Link>
);
}

if (as === "button") {
return (
<button
type={type}
onClick={onClick}
className={baseStyle}
aria-label={ariaLabel}
>
{content}
</button>
);
}

return null;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isExternalLink =
href.startsWith("http") ||
href.startsWith("mailto:") ||
href.startsWith("tel:");
return (
<Link
href={href}
className={baseStyle}
aria-label={ariaLabel}
{...(isExternalLink
? { target: "_blank", rel: "noopener noreferrer" }
: {})}
>
{content}
</Link>
);
}
if (as === "button") {
return (
<button
type={type}
onClick={onClick}
className={baseStyle}
aria-label={ariaLabel}
>
{content}
</button>
);
}
return null;
};
if (href) {
const isExternalLink =
href.startsWith("http") ||
href.startsWith("mailto:") ||
href.startsWith("tel:");
return (
<Link
href={href}
className={baseStyle}
aria-label={ariaLabel}
{...(isExternalLink
? { target: "_blank", rel: "noopener noreferrer" }
: {})}
>
{content}
</Link>
);
} else {
return (
<button
type={type}
onClick={onClick}
className={baseStyle}
aria-label={ariaLabel}
>
{content}
</button>
);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: button component
2 participants