-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(Badge): make BadgeProps readonly for better immutability #43
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,23 +9,19 @@ import type {BadgeProps} from "./BadgeProps.ts"; | |||||||||||||
| * @example | ||||||||||||||
| * <Badge text="New" variant="primary" removable onRemove={() => console.log('removed')} /> | ||||||||||||||
| */ | ||||||||||||||
| export function Badge(props: BadgeProps) { | ||||||||||||||
| const variant = props.variant ?? 'primary'; | ||||||||||||||
| const removable = props.removable ?? false; | ||||||||||||||
| // Note: The 'color' prop from BadgeProps is ignored in favor of the 'variant' | ||||||||||||||
| // prop, which aligns with DaisyUI's class-based styling. | ||||||||||||||
| const badgeClasses = [ | ||||||||||||||
| 'badge', | ||||||||||||||
| `badge-${variant}`, | ||||||||||||||
| 'gap-2' | ||||||||||||||
| ].join(' '); | ||||||||||||||
| export function Badge(props: Readonly<BadgeProps>) { | ||||||||||||||
| const variant = props.variant ?? 'primary'; | ||||||||||||||
| const removable = props.removable ?? false; | ||||||||||||||
| // Note: The 'color' prop from BadgeProps is ignored in favor of the 'variant' | ||||||||||||||
| // prop, which aligns with DaisyUI's class-based styling. | ||||||||||||||
| const badgeClasses = ['badge', `badge-${variant}`, 'gap-2'].join(' '); | ||||||||||||||
|
Comment on lines
+15
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: The PR description states: "The Additionally, the comment on lines 15-16 acknowledges that the Apply this diff to conditionally apply - // Note: The 'color' prop from BadgeProps is ignored in favor of the 'variant'
- // prop, which aligns with DaisyUI's class-based styling.
- const badgeClasses = ['badge', `badge-${variant}`, 'gap-2'].join(' ');
+ const badgeClasses = ['badge', `badge-${variant}`, removable ? 'gap-2' : ''].filter(Boolean).join(' ');Additionally, remove the 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <div className={badgeClasses}> | ||||||||||||||
| <span className="whitespace-pre-wrap">{props.text}</span> | ||||||||||||||
| {removable && (<button onClick={props.onRemove} className="btn btn-ghost btn-xs"> | ||||||||||||||
| ✕ | ||||||||||||||
| </button>)} | ||||||||||||||
| </div> | ||||||||||||||
| ); | ||||||||||||||
| return ( | ||||||||||||||
| <div className={badgeClasses}> | ||||||||||||||
| <span className="whitespace-pre-wrap">{props.text}</span> | ||||||||||||||
| {removable && (<button onClick={props.onRemove} className="btn btn-ghost btn-xs"> | ||||||||||||||
| ✕ | ||||||||||||||
| </button>)} | ||||||||||||||
|
Comment on lines
+22
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Missing The PR description states: "Accessibility improved by adding Apply this diff to add the - {removable && (<button onClick={props.onRemove} className="btn btn-ghost btn-xs">
+ {removable && (<button onClick={props.onRemove} className="btn btn-ghost btn-xs" aria-label="Remove badge">
✕
</button>)}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| </div> | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Good use of
Readonly<BadgeProps>for immutability, but verify thecolorprop removal.The
Readonlywrapper enforces immutability at the type level, which aligns with the PR objectives. However, the PR description states that "an unusedcolorprop was removed fromBadgeProps," yet theBadgePropsinterface inBadgeProps.ts(lines 1-6) still includes thecolor: stringproperty.Run the following script to verify that the
colorproperty has been removed from theBadgePropsinterface:🏁 Script executed:
Length of output: 172
Remove the unused
colorproperty fromBadgePropsinterface.The
colorproperty still exists inBadgeProps.ts(line 3), contradicting the PR description which claims it was removed. If this property is truly unused, it should be removed from the interface to avoid confusion and reduce surface area.Edit
src/components/ui/Badge/BadgeProps.tsto remove thecolor: string,line.🤖 Prompt for AI Agents