Skip to content

Comments

fix: update Badge component type safety and props#518

Closed
jdhoffa wants to merge 4 commits intomainfrom
fix_ts_errors_badge_component
Closed

fix: update Badge component type safety and props#518
jdhoffa wants to merge 4 commits intomainfrom
fix_ts_errors_badge_component

Conversation

@jdhoffa
Copy link
Collaborator

@jdhoffa jdhoffa commented Nov 5, 2025

  • Update Badge variant types to include "metric" and "keyFeature"
  • Fix type errors by replacing text prop with children
  • renderLabel returns a "string" directly

Relates to #514

@jdhoffa jdhoffa requested review from AlexAxthelm and Copilot and removed request for Copilot November 5, 2025 13:15
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Expected version change and release notes:

1.5.0-dev.18 (v1.5.0-dev.17...fix_ts_errors_badge_component ) (2025-11-05T13:26 UTC)

Fixes

  • renderLabel returns string directly (e474951)
  • update Badge component type safety and props (c21a764)

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Azure Static Web Apps: Your stage site is ready! Visit it here: https://proud-glacier-0f640931e-518.westus2.2.azurestaticapps.net

Copilot AI review requested due to automatic review settings November 5, 2025 13:24
Copy link
Contributor

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 refactors the Badge component to use children-based API instead of text prop, adds two new badge variants ("metric" and "keyFeature"), and includes code cleanup. The changes improve the component's API consistency with React conventions while removing redundant comments.

  • Removed the text prop in favor of using children prop for badge content
  • Added "metric" and "keyFeature" badge variants with corresponding styles
  • Updated the BadgeMaybeAbsent component's renderLabel return type from React.ReactNode to string | number

Reviewed Changes

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

File Description
src/components/Badge.tsx Added two new badge variants, removed redundant comments, changed renderLabel return type, and added explicit String() conversion for content rendering
src/components/Badge.test.tsx Updated all test cases to use children-based API instead of text prop, changed test element from <span> to <div> for compile-time checks, removed redundant comments

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

noneLabel?: string;
/** Optional decorator for the final label (e.g., highlight search matches). */
renderLabel?: (label: string, isAbsent: boolean) => React.ReactNode;
renderLabel?: (label: string, isAbsent: boolean) => string | number;
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

The return type change from React.ReactNode to string | number is a breaking change that restricts the flexibility of renderLabel. This prevents consumers from returning JSX elements (e.g., highlighted text with <mark> tags). Consider reverting this change or providing migration guidance if this restriction is intentional.

Copilot uses AI. Check for mistakes.
renderLabel && typeof base === "string" ? renderLabel(base, absent) : base;
return <Badge {...rest}>{content}</Badge>;

return <Badge {...rest}>{String(content)}</Badge>;
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

The explicit String(content) conversion is redundant when content is already of type string | number. Since Badge accepts children: string | number, the conversion to string is unnecessary and could mask potential type issues. Consider removing the String() wrapper.

Suggested change
return <Badge {...rest}>{String(content)}</Badge>;
return <Badge {...rest}>{content}</Badge>;

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Azure Static Web Apps: Your stage site is ready! Visit it here: https://proud-glacier-0f640931e-518.westus2.2.azurestaticapps.net

@jdhoffa jdhoffa marked this pull request as draft November 5, 2025 13:27
@jdhoffa jdhoffa closed this Nov 5, 2025
@jdhoffa jdhoffa deleted the fix_ts_errors_badge_component branch November 17, 2025 10:40
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.

1 participant