Skip to content

feat(ui): add Badge component#119

Merged
noe-charmet merged 3 commits intomainfrom
feat/add-badge
Nov 11, 2025
Merged

feat(ui): add Badge component#119
noe-charmet merged 3 commits intomainfrom
feat/add-badge

Conversation

@kylengn
Copy link
Contributor

@kylengn kylengn commented Nov 11, 2025

Summary by CodeRabbit

  • New Features

    • Added Badge, IconBadge, StatusBadge, and UserBadge components with multiple styling variants
    • Added homeSmile icon
    • Added Storybook stories demonstrating badge variants and interactive behavior
  • Style

    • Updated warning tag text color styling

@kylengn kylengn self-assigned this Nov 11, 2025
Copilot AI review requested due to automatic review settings November 11, 2025 09:23
@vercel
Copy link

vercel bot commented Nov 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
react-ui Ready Ready Preview Comment Nov 11, 2025 4:35pm

@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR introduces a complete Badge component system for the React UI library, featuring four badge variants (Badge, IconBadge, StatusBadge, UserBadge) with comprehensive styling, interactive capabilities, and Storybook documentation. Additionally, it updates a CSS design token for warning tag text color and adds a new homeSmile icon to the icon registry.

Changes

Cohort / File(s) Summary
CSS Design Token Update
libs/react/ui/index.css
Updated the --tag-warning-text CSS design token from var(--color-orange-200) to var(--color-orange-800), changing the warning tag text color.
Badge Components
libs/react/ui/src/components/badge/badge.tsx, icon-badge.tsx, status-badge.tsx, user-badge.tsx
Added four new badge components: Badge (variant-driven with interactive left/right icons), IconBadge (renders a colored icon), StatusBadge (colored dot with text), and UserBadge (avatar with name). Each uses variant-based styling via cva.
Badge Exports & Storybook
libs/react/ui/src/components/badge/index.ts, badge.stories.tsx, libs/react/ui/src/components/index.ts
Created barrel file consolidating badge component exports; added comprehensive Storybook stories demonstrating AllVariants and InteractiveBadges; updated main components index to export the badge module.
Icon Registry
libs/react/ui/src/components/icon/icon.tsx
Added RiHomeSmileFill Remix Icon import and registered as homeSmile in the iconsMap, expanding the IconName type surface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Badge component implementations: Four distinct badge variants, each with different styling patterns and interactive capabilities—ensure variant logic, prop handling, and accessibility labels (ARIA) are correct across all components
  • Interactive elements: Badge and UserBadge include click handlers and conditional icon rendering—verify event propagation, state management in Storybook stories, and accessibility considerations
  • Styling consistency: Multiple uses of cva and cn utilities across components—confirm consistent sizing, spacing, and color application

Possibly related PRs

Suggested reviewers

  • dvxam
  • EnzalRad
  • noe-charmet

Poem

🐰 A badge of honor, shining bright,
Four variants in CSS delight,
From icon dots to user frames,
Each component stakes its claims!
With Storybook's stories told,
Your UI components are bold!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat(ui): add Badge component' clearly and specifically describes the main change—introducing a new Badge component to the UI library.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
libs/react/ui/src/components/badge/status-badge.tsx (2)

28-28: Remove redundant variable assignment.

Line 28 assigns variantKey = variant ?? 'neutral', but variant already defaults to 'neutral' in the function parameters (Line 23). This assignment is unnecessary.

Apply this diff:

-  const variantKey = variant ?? 'neutral';
   return (
     <span
-      className={cn(badgeVariants({variant, size: '2xs', radius: 'default'}), 'gap-6', className)}
+      className={cn(badgeVariants({variant, size: '2xs', radius: 'default'}), 'gap-6', className)}
       {...props}
     >
       <span
-        className={cn('size-8.5 rounded-2 shrink-0', dotVariantStyles[variantKey], dotClassName)}
+        className={cn('size-8.5 rounded-2 shrink-0', dotVariantStyles[variant], dotClassName)}
       />
       {children}
     </span>

10-10: Consider exporting or aligning StatusVariant type.

The StatusVariant type defined here is essentially a subset of BadgeVariant (missing 'warning' support based on the variants). Consider either:

  1. Using BadgeVariant directly (imported from './badge')
  2. Exporting StatusVariant if it's intentionally constrained

Currently, consumers cannot reference this type, which may limit type safety when using the component.

libs/react/ui/src/components/badge/badge.tsx (1)

121-121: Consider using theme-aware focus ring color.

The focus ring uses focus-visible:ring-blue-500 which is a hardcoded color. Consider using a design token like focus-visible:ring-border-highlights-interactive to maintain consistency with the theme system and support dark mode.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a808a32 and da46bfb.

📒 Files selected for processing (9)
  • libs/react/ui/index.css (1 hunks)
  • libs/react/ui/src/components/badge/badge.stories.tsx (1 hunks)
  • libs/react/ui/src/components/badge/badge.tsx (1 hunks)
  • libs/react/ui/src/components/badge/icon-badge.tsx (1 hunks)
  • libs/react/ui/src/components/badge/index.ts (1 hunks)
  • libs/react/ui/src/components/badge/status-badge.tsx (1 hunks)
  • libs/react/ui/src/components/badge/user-badge.tsx (1 hunks)
  • libs/react/ui/src/components/icon/icon.tsx (2 hunks)
  • libs/react/ui/src/components/index.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*

⚙️ CodeRabbit configuration file

We handle errors at the edge of our applications in most cases. Do not recommend to add error handling around every single function. We prefer them to bubble up and be handled at upper layers.

Files:

  • libs/react/ui/src/components/index.ts
  • libs/react/ui/src/components/badge/badge.tsx
  • libs/react/ui/index.css
  • libs/react/ui/src/components/badge/icon-badge.tsx
  • libs/react/ui/src/components/badge/status-badge.tsx
  • libs/react/ui/src/components/badge/user-badge.tsx
  • libs/react/ui/src/components/badge/badge.stories.tsx
  • libs/react/ui/src/components/badge/index.ts
  • libs/react/ui/src/components/icon/icon.tsx
🧬 Code graph analysis (5)
libs/react/ui/src/components/badge/badge.tsx (1)
libs/react/ui/src/components/icon/icon.tsx (2)
  • IconName (59-59)
  • Icon (65-68)
libs/react/ui/src/components/badge/icon-badge.tsx (1)
libs/react/ui/src/components/icon/icon.tsx (2)
  • IconName (59-59)
  • Icon (65-68)
libs/react/ui/src/components/badge/status-badge.tsx (1)
libs/react/ui/src/components/badge/badge.tsx (2)
  • BadgeVariant (41-41)
  • badgeVariants (7-39)
libs/react/ui/src/components/badge/user-badge.tsx (1)
libs/react/ui/src/components/avatar/avatar.tsx (1)
  • Avatar (117-217)
libs/react/ui/src/components/badge/badge.stories.tsx (4)
libs/react/ui/src/components/badge/badge.tsx (1)
  • Badge (84-139)
libs/react/ui/src/components/badge/status-badge.tsx (1)
  • StatusBadge (21-40)
libs/react/ui/src/components/badge/user-badge.tsx (1)
  • UserBadge (11-34)
libs/react/ui/src/components/badge/icon-badge.tsx (1)
  • IconBadge (30-43)
🔇 Additional comments (13)
libs/react/ui/src/components/icon/icon.tsx (1)

7-7: LGTM!

The new homeSmile icon is correctly imported and registered following the existing pattern.

Also applies to: 56-56

libs/react/ui/index.css (1)

271-271: LGTM!

The warning text color token update from --color-orange-200 to --color-orange-800 improves contrast and readability for warning badges in light mode.

libs/react/ui/src/components/index.ts (1)

3-3: LGTM!

The badge barrel export is correctly positioned and follows the existing pattern.

libs/react/ui/src/components/badge/user-badge.tsx (1)

11-34: LGTM!

The UserBadge component is well-structured with proper button semantics, avatar integration, and text handling. The use of type="button" prevents unintended form submissions, and whitespace-nowrap ensures consistent layout.

libs/react/ui/src/components/badge/badge.tsx (3)

7-39: LGTM!

The badgeVariants definition is comprehensive with well-structured variant options for different badge styles, sizes, and radii. The use of design tokens ensures consistency with the theme system.


50-82: Excellent type safety for accessibility.

The union type pattern enforces ARIA labels when click handlers are provided, ensuring interactive icons have proper accessibility attributes. This is a strong design that prevents common accessibility issues at compile time.


109-115: LGTM!

The development-time accessibility warning helps developers remember to add ARIA labels for interactive icons, improving the overall accessibility of components using this Badge.

libs/react/ui/src/components/badge/badge.stories.tsx (2)

18-375: LGTM!

The AllVariants story provides comprehensive visual documentation of all badge types, sizes, variants, and configurations. The organization by badge type and clear labeling makes it easy to understand the component's capabilities.


377-468: Excellent interactive examples.

The InteractiveBadges story effectively demonstrates stateful behavior with removable tags and shows proper usage of ARIA labels for accessibility. The examples serve as good reference implementations for consumers.

libs/react/ui/src/components/badge/index.ts (1)

1-4: LGTM!

The barrel export cleanly consolidates all badge components and their types into a single entry point, following best practices for library API design.

libs/react/ui/src/components/badge/icon-badge.tsx (3)

1-10: LGTM!

The imports and type definitions are clean and appropriate. The component extends ComponentProps<'span'>, which is suitable for an inline badge element.


12-28: Verify the semantic mismatch between "primary" variant and "warning" design tokens.

The primary variant (lines 17, 26) is mapped to warning design tokens (bg-tag-warning-bg, border-tag-warning-border, text-tag-warning-icon), while all other variants use semantically matching tokens. This naming inconsistency may confuse developers and lead to incorrect usage.

Please verify if this is intentional. If not, consider either:

  • Renaming the variant from primary to warning to align with the design tokens
  • Or mapping primary to appropriate primary design tokens if they exist

30-43: LGTM!

The component implementation is clean and well-structured. The conditional rendering ensures the Icon only appears when name is provided, and the className composition properly merges variant styles with any custom classes.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive Badge component system with multiple variants to support different use cases across the UI library.

Key Changes

  • Added a flexible Badge component with support for interactive icons, multiple variants (neutral, info, feature, success, warning, error), customizable sizes and border radius
  • Created specialized badge variants: IconBadge, StatusBadge, and UserBadge components for specific use cases
  • Fixed CSS variable for warning text color to improve contrast (--color-orange-200--color-orange-800)

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libs/react/ui/src/components/badge/badge.tsx Core Badge component with variant system, interactive icon support, and accessibility features
libs/react/ui/src/components/badge/icon-badge.tsx Icon-only badge variant with squared container
libs/react/ui/src/components/badge/status-badge.tsx Status badge with colored dot indicator
libs/react/ui/src/components/badge/user-badge.tsx User badge combining avatar and name display
libs/react/ui/src/components/badge/index.ts Barrel exports for all badge components and types
libs/react/ui/src/components/badge/badge.stories.tsx Comprehensive Storybook stories showcasing all badge variants and use cases
libs/react/ui/src/components/index.ts Added badge component to main exports
libs/react/ui/src/components/icon/icon.tsx Added RiHomeSmileFill icon for badge examples
libs/react/ui/index.css Fixed warning text color CSS variable for better contrast

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants