Skip to content
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

feat(badge): add dismissable badge #101

Merged
merged 2 commits into from
Dec 19, 2024
Merged

Conversation

MGREMY
Copy link
Collaborator

@MGREMY MGREMY commented Dec 19, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • Docs have been added/updated (for bug fixes/features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • CI-related changes
  • Documentation content changes
  • Other... Please describe:

Issue Number

Issue Number: #89

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced dismissible badges with customizable colors and dismissal behavior.
    • Added a new Angular component for dismissible badges.
  • Documentation

    • Updated documentation to include a section for the dismissible badge component with examples.
  • Bug Fixes

    • Improved styling options for the close button in the badge component.

Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-angular ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2024 1:55pm

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

This pull request introduces a new dismissible badge feature for the Flowbite Angular library. The implementation adds functionality to create badges that can be dismissed by users, with customizable colors and a close button. The changes span multiple files across the documentation and library components, adding new methods, properties, and styling options to support dismissable badges. The feature allows developers to create interactive badges with the ability to remove them dynamically.

Changes

File Change Summary
apps/docs/docs/components/badge/_dismissable.component.html Added multiple dismissible badge examples with various colors.
apps/docs/docs/components/badge/_dismissable.component.ts Created new FlowbiteDismissableComponent with onDismiss method.
apps/docs/docs/components/badge/index.md Added documentation section for dismissable badges.
apps/docs/docs/components/badge/ng-doc.page.ts Registered dismissable badge component in demos.
libs/flowbite-angular/badge/badge.component.ts Added isDismissable and onDismiss properties, implemented dismiss functionality.
libs/flowbite-angular/badge/badge.theme.service.ts Added closeButtonClass for styling close button.
libs/flowbite-angular/badge/badge.theme.ts Updated theme interface and constant to support close button styling.

Possibly related issues

Possibly related PRs

Poem

🐰 A Badge with a Hop and a Bop! 🏷️
Dismissible magic, oh what a swap!
Click the close, watch it fade away
A rabbit's delight on this coding day
Flowbite badges now dance with glee! 🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ba45e7 and 6941e5b.

📒 Files selected for processing (1)
  • apps/docs/docs/components/badge/_dismissable.component.html (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/docs/docs/components/badge/_dismissable.component.html

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MGREMY MGREMY linked an issue Dec 19, 2024 that may be closed by this pull request
Copy link
Contributor

@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: 5

🧹 Nitpick comments (6)
apps/docs/docs/components/badge/_dismissable.component.html (1)

1-49: Consider refactoring repetitive badge definitions

The current implementation has significant code duplication. Consider using an array of badge configurations and ngFor to reduce repetition.

Here's a suggested approach:

// In component class
badges = [
  { color: 'default', label: 'Default' },
  { color: 'primary', label: 'Primary' },
  { color: 'blue', label: 'Blue' },
  // ... other colors
];
<flowbite-badge
  *ngFor="let badge of badges"
  [isDismissable]="true"
  [onDismiss]="onDismiss"
  [color]="badge.color">
  {{ badge.label }}
</flowbite-badge>
libs/flowbite-angular/badge/badge.theme.service.ts (1)

44-44: LGTM! Consider adding tests for the new closeButtonClass.

The implementation correctly merges the base and color classes for the close button using twMerge, following the established pattern.

Consider adding unit tests to verify the closeButtonClass generation with different color combinations.

apps/docs/docs/components/badge/index.md (1)

76-91: LGTM! Consider enhancing the documentation.

The new dismissable badge section follows the established documentation pattern.

Consider adding:

  • Usage examples with different color variants
  • Event handling examples for the dismiss action
  • Accessibility considerations for the dismiss button
libs/flowbite-angular/badge/badge.component.ts (3)

95-109: Consider enhancing keyboard accessibility.

While the dismiss button implementation is good, consider adding keyboard event handling for better accessibility.

 <button
   type="button"
   [class]="contentClasses()!.closeButtonClass"
   aria-label="Close"
-  (click)="onDismissClick()">
+  (click)="onDismissClick()"
+  (keydown.enter)="onDismissClick()"
+  (keydown.space)="onDismissClick()">

166-177: Consider using a more specific type for onDismiss callback.

The onDismiss callback type could be more specific to better document the expected behavior.

-  public onDismiss = model(inject(FLOWBITE_BADGE_ON_DISMISS_DEFAULT_VALUE));
+  public onDismiss = model<((event: { source: BadgeComponent }) => void) | undefined>(
+    inject(FLOWBITE_BADGE_ON_DISMISS_DEFAULT_VALUE)
+  );

This would allow passing the component instance to the callback for more context.


Line range hint 1-209: Add unit tests for the dismissable badge feature.

The implementation looks solid, but test coverage is missing. Consider adding tests for:

  • Dismissable behavior
  • Callback execution
  • Icon registration
  • Accessibility features

Would you like me to help generate unit tests for this component?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a07b30 and 3ba45e7.

📒 Files selected for processing (7)
  • apps/docs/docs/components/badge/_dismissable.component.html (1 hunks)
  • apps/docs/docs/components/badge/_dismissable.component.ts (1 hunks)
  • apps/docs/docs/components/badge/index.md (1 hunks)
  • apps/docs/docs/components/badge/ng-doc.page.ts (2 hunks)
  • libs/flowbite-angular/badge/badge.component.ts (8 hunks)
  • libs/flowbite-angular/badge/badge.theme.service.ts (1 hunks)
  • libs/flowbite-angular/badge/badge.theme.ts (2 hunks)
🔇 Additional comments (4)
apps/docs/docs/components/badge/ng-doc.page.ts (1)

4-4: LGTM!

The dismissable component is properly imported and added to the demos object, following the established pattern.

Also applies to: 29-29

libs/flowbite-angular/badge/badge.theme.ts (2)

57-60: LGTM! Theme interface is well-structured.

The closeButton theme interface follows the established pattern and includes necessary properties for styling.


126-128: LGTM! Class interface is properly typed.

The BadgeClass interface correctly extends FlowbiteClass and includes the new closeButtonClass property.

libs/flowbite-angular/badge/badge.component.ts (1)

6-8: LGTM! New imports and injection tokens are well-structured.

The new imports and injection tokens are properly implemented, following the existing patterns in the codebase.

Also applies to: 19-20, 45-51

@MGREMY MGREMY merged commit da6c209 into main Dec 19, 2024
5 checks passed
@MGREMY MGREMY deleted the 89-feature-badge-dismissible branch December 19, 2024 13:57
@MGREMY
Copy link
Collaborator Author

MGREMY commented Dec 19, 2024

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

[Feature] {Badge} - Dismissible
1 participant