fix: standardize icon sizing inside Badge component#1038
Conversation
|
Thank you @, for creating the PR and contributing to our UltimateHealth project 💗. |
|
/review |
🤖 Gemini AI Code ReviewSummaryThis Pull Request aims to standardize icon sizing within the The PR effectively rewrites the 🔴 High Severity
🟡 Medium Severity
🟢 Low Severity / Nits
What's Good ✅
VerdictRequest Changes The PR introduces several high-severity breaking changes by fundamentally altering the |
| className, | ||
| ...spanProps | ||
| } = props; | ||
|
|
There was a problem hiding this comment.
The icon sizing improvements look good, but this PR also removes existing Badge functionality (as, children, className, button/anchor rendering). These are API-breaking changes unrelated to the stated scope of standardizing icon sizing. Please preserve the existing Badge API and integrate the icon sizing updates into the current implementation instead. Also remove or reuse the unused interactiveClasses variable.
|
Hi @SB2318, thank you for the detailed review and merging the latest web branch into my PR! I have updated Badge.tsx to address all the feedback: ✅ Restored as prop for button/anchor/span rendering Please review the updated implementation! |
|
/review |
🤖 Gemini AI Code ReviewSummaryThis Pull Request aims to standardize icon sizing and styling within the While the refactoring significantly improves code maintainability and the icon styling is well-executed, there are critical regressions introduced in the component's core functionality and styling due to the consolidation. 🔴 High Severity1. Missing Base Layout Styles for Most Badge Variants
--- a/src/components/ui/Badge.tsx
+++ b/src/components/ui/Badge.tsx
@@ -32,6 +32,10 @@ const variantClasses: Record<BadgeVariant, string> = {
info: "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",
};
+const baseClasses =
+ "inline-flex items-center gap-1.5 rounded-full font-medium transition-colors";
+
const sizeClasses: Record<BadgeSize, string> = {
sm: "px-2.5 py-0.5 text-xs",
md: "px-3.5 py-1 text-sm",
@@ -50,7 +54,7 @@ const getBadgeClasses = (
className?: string
) =>
[
- variantClasses[variant],
+ baseClasses, // Apply common layout styles first
+ variantClasses[variant], // Then apply variant-specific styles
sizeClasses[size],
isInteractive && interactiveClasses,
className,2. Missing
--- a/src/components/ui/Badge.tsx
+++ b/src/components/ui/Badge.tsx
@@ -133,16 +75,26 @@ const Badge = (props: BadgeProps) => {
icon,
- className,
- ...spanProps
- } = props;
+ className = "",
+ ...restProps
+ } = props as BadgeSpanProps & BadgeButtonProps & BadgeAnchorProps;
+
+ const isInteractive = Component === "button" || Component === "a";
+ const isButton = Component === "button";
+
+ // Ensure type="button" for buttons if not explicitly provided
+ const finalProps = { ...restProps };
+ if (isButton && !finalProps.type) {
+ finalProps.type = "button";
+ }
return (
<Component
- className={getBadgeClasses(variant, size, false, className)}
- {...spanProps}
+ className={getBadgeClasses(variant, size, isInteractive, className)}
+ {...finalProps}
>
{icon && (
<span
className={`inline-flex items-center justify-center shrink-0 text-current ${iconSizeClasses[size]}`}
aria-hidden="true"
>
{icon}
</span>
)}
{children ?? label}
</Component>
);
};🟡 Medium Severity1. Loose Type Casting for
// Example of how BadgeProps should be structured (simplified for brevity)
type BadgeBaseProps = {
label?: string;
children?: React.ReactNode;
variant?: BadgeVariant;
size?: BadgeSize;
icon?: React.ReactNode;
className?: string;
};
type BadgeSpanProps = BadgeBaseProps & {
as?: "span"; // 'as' is optional for span, defaults to span
};
type BadgeButtonProps = BadgeBaseProps &
React.ComponentPropsWithoutRef<"button"> & {
as: "button"; // 'as' is required for button
};
type BadgeAnchorProps = BadgeBaseProps &
React.ComponentPropsWithoutRef<"a"> & {
as: "a"; // 'as' is required for anchor
};
export type BadgeProps = BadgeSpanProps | BadgeButtonProps | BadgeAnchorProps;
// Then in the component, no 'as' cast is needed:
const Badge = (props: BadgeProps) => {
const {
as: Component = "span",
// ... rest of props
} = props; // TypeScript will correctly infer types based on 'as'
// ...
};🟢 Low Severity / Nits1. Explicit
2.
What's Good ✅
VerdictRequest Changes The PR introduces critical regressions in the badge's visual layout and interactive behavior ( |
|
Congratulations, Your pull request has been successfully merged 🥳🎉 Thank you for your contribution to the project 🚀 Keep Contributing!! ✨ |
Description
Fixes inconsistent icon sizing inside the Badge component.
Followed by PR #976
Changes
iconSizeClassesmap to standardize icon sizing based on badge sizesm → w-3 h-3md → w-4 h-4<span>withinline-flex items-center justify-centertext-currentso icon inherits badge text color automaticallyshrink-0to prevent icon from being squeezedaria-hidden="true"since icon is decorativeImpact
Closes #994