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(scroll-top): add support for icon customisation #96

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

MGREMY
Copy link
Collaborator

@MGREMY MGREMY commented Dec 16, 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: #85

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced a scroll-to-top component for improved navigation.
    • Added support for dynamic icons in the scroll-to-top feature.
  • Bug Fixes

    • Ensured that existing functionality and layout remain unaffected by the new component integration.

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

vercel bot commented Dec 16, 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 16, 2024 1:46pm

@MGREMY MGREMY self-assigned this Dec 16, 2024
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

The pull request introduces a new scroll-to-top feature to the Angular application by adding the ScrollTopComponent from the flowbite-angular library. The component is integrated into the main application component's template and supports dynamic icon rendering. A new injection token is created to allow customization of the scroll-top icon, with a default fallback to a predefined chevron-up icon.

Changes

File Change Summary
apps/docs/src/app/app.component.html Added <flowbite-scroll-top /> component after <router-outlet />
apps/docs/src/app/app.component.ts Imported ScrollTopComponent from flowbite-angular/scroll-top and added to component imports
libs/flowbite-angular/scroll-top/scroll-top.component.ts Added FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE injection token, new icon property, and updated template to support dynamic icon rendering

Possibly related PRs

  • docs: add inherit component documentation #73: This PR discusses the documentation for inheriting components from the flowbite-angular library, which is relevant as the main PR introduces a new component (ScrollTopComponent) from the same library, indicating a connection in terms of component usage and documentation.

Poem

🐰 Hop to the top, with a scroll so light,
A button that leaps with digital might!
Chevron icon dancing, custom or plain,
Bringing users back, again and again!
Flowbite's magic, a rabbit's delight! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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: 0

🧹 Nitpick comments (2)
libs/flowbite-angular/scroll-top/scroll-top.component.ts (1)

111-114: Enhance property documentation

The icon property documentation could be more descriptive. Consider adding:

  • Default value information
  • Usage example with TemplateRef
  • Type information

Example documentation:

/**
 * Set the scroll top icon
 * @description Allows customization of the scroll-to-top button icon using a TemplateRef
 * @default undefined - Falls back to chevron-up icon
 * @example
 * <ng-template #customIcon>
 *   <your-custom-icon />
 * </ng-template>
 * <flowbite-scroll-top [icon]="customIcon" />
 */
public icon = model(inject(FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE));
apps/docs/src/app/app.component.html (1)

116-116: Consider adding icon customization example

While the basic integration is correct, this would be a good place to showcase the new icon customization feature for documentation purposes.

Example implementation:

-    <flowbite-scroll-top />
+    <ng-template #customScrollTopIcon>
+      <flowbite-icon
+        svgIcon="outline:arrow-up"
+        class="w-5 h-5" />
+    </ng-template>
+    <flowbite-scroll-top [icon]="customScrollTopIcon" />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3ea9a8 and bc3a60f.

📒 Files selected for processing (3)
  • apps/docs/src/app/app.component.html (1 hunks)
  • apps/docs/src/app/app.component.ts (2 hunks)
  • libs/flowbite-angular/scroll-top/scroll-top.component.ts (5 hunks)
🔇 Additional comments (4)
libs/flowbite-angular/scroll-top/scroll-top.component.ts (3)

35-37: LGTM: Well-structured injection token implementation

The injection token implementation follows Angular's best practices and provides good flexibility with optional template references.

Also applies to: 52-55


69-77: LGTM: Clean template implementation with proper fallback

The template elegantly handles both custom icons and fallback to default icon using modern Angular syntax.


Line range hint 64-78: LGTM: Well-structured component with performance optimizations

The component implementation follows Angular best practices:

  • Uses OnPush change detection
  • Proper encapsulation
  • Clean inheritance hierarchy
apps/docs/src/app/app.component.ts (1)

17-17: LGTM: Clean component integration

The ScrollTopComponent is properly imported and integrated into the AppComponent.

Also applies to: 48-48

@MGREMY
Copy link
Collaborator Author

MGREMY commented Dec 16, 2024

@coderabbitai generate docstrings

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

✅ Actions performed

Docstrings generation started.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Caution

No docstrings were generated.

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: 1

🧹 Nitpick comments (2)
libs/flowbite-angular/scroll-top/scroll-top.component.ts (2)

35-37: Consider adding JSDoc comment for the injection token.

The injection token is well-implemented, but adding documentation would improve maintainability.

+/**
+ * Injection token for customizing the scroll-top icon template.
+ * When not provided, falls back to the default chevron-up icon.
+ */
export const FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE = new InjectionToken<
  TemplateRef<unknown> | undefined
>('FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE');

111-116: Enhance icon property documentation.

While the basic documentation is present, it would be helpful to add more details about usage and examples.

   /**
    * Set the scroll top icon
+   * 
+   * @description
+   * Accepts a template reference to customize the scroll-to-top icon.
+   * When not provided, a default chevron-up icon will be displayed.
+   * 
+   * @example
+   * ```html
+   * <flowbite-scroll-top>
+   *   <ng-template #customIcon>
+   *     <your-custom-icon />
+   *   </ng-template>
+   * </flowbite-scroll-top>
+   * ```
    *
    * @default undefined
    */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc3a60f and 3e2b89c.

📒 Files selected for processing (1)
  • libs/flowbite-angular/scroll-top/scroll-top.component.ts (5 hunks)
🔇 Additional comments (3)
libs/flowbite-angular/scroll-top/scroll-top.component.ts (3)

14-15: LGTM! Import changes are appropriate.

The addition of NgTemplateOutlet and type imports are correctly implemented for the new icon customization feature.


52-55: LGTM! Provider configuration is correct.

The default value of undefined is appropriate, allowing the component to fall back to the default icon when no custom icon is provided.


Line range hint 135-141: Verify signal cleanup and icon registration.

Please ensure:

  1. The icon signal is properly cleaned up when the component is destroyed
  2. The icon registration in init() is only done once
✅ Verification successful

No cleanup needed for icon registration

The implementation is correct as is. Here's why:

  1. The icon registration is handled by the IconRegistry service which is provided at root level and manages its own cleanup in ngOnDestroy.
  2. The init() method in ScrollTopComponent only registers the icon once during component initialization, and duplicate registrations are handled internally by the registry.
  3. Individual components don't need to clean up registered icons as they are managed centrally by the IconRegistry service which properly cleans up when the application is destroyed.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for signal cleanup in component
ast-grep --pattern 'class $_ implements OnDestroy {
  $$$
  ngOnDestroy() {
    $$$
    this.icon.destroy();
    $$$
  }
  $$$
}'

# Check for duplicate icon registration prevention
ast-grep --pattern 'class $_ {
  $$$
  init() {
    if (this.iconRegistry.has("flowbite-angular", "chevron-up")) {
      return;
    }
    $$$
  }
  $$$
}'

Length of output: 289


Script:

#!/bin/bash
# Let's try a broader search for the component implementation
rg -l "ScrollTopComponent" --type ts

# Check for any icon registration patterns
rg "addRawSvgIconInNamepsace" --type ts -A 2 -B 2

# Check for OnDestroy implementation
rg "implements OnDestroy" --type ts -A 5 "scroll-top"

# Check for init method implementation
rg "init\(\)" --type ts -A 5 "scroll-top"

# Look for the component file content
fd "scroll-top.component.ts" -t f -x cat {}

Length of output: 9885


Script:

#!/bin/bash
# Let's check the BaseComponent implementation for cleanup patterns
rg "class BaseComponent" --type ts -A 10

# Check if there are any icon cleanup patterns in the codebase
rg "destroy.*icon" --type ts -A 2 -B 2

# Look for the icon registry implementation
fd "icon-registry.ts" -t f -x cat {}

Length of output: 8204

@MGREMY MGREMY merged commit fe25ed8 into main Dec 16, 2024
5 checks passed
@MGREMY MGREMY deleted the feat(scroll-top)-add-support-for-icon-customisation branch December 16, 2024 13:53
@MGREMY
Copy link
Collaborator Author

MGREMY commented Dec 18, 2024

🎉 This PR is included in version 1.2.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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] ScrollTop - Customize icon
1 participant