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: Make use of the newly refactored popper component to make the tooltip. Also, add new story. #807

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

decipher-cs
Copy link
Contributor

@decipher-cs decipher-cs commented Jan 21, 2025

Popper was refactored to be more composable. See #800. Tooltip was just wrapping around the popper component before but now it will use popper sub-components like Popper.Trigger and Popper.Content.

A new story was also added.

Summary by CodeRabbit

  • New Features

    • Enhanced Tooltip component with new configuration options, including the ability to show/hide the tooltip arrow and apply custom styles through an optional className.
    • Introduced new variations in Storybook for the Tooltip component, showcasing tooltips with and without arrows.
  • Documentation

    • Updated Storybook stories to demonstrate new Tooltip variations using button elements for interaction.

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

This pull request enhances the Tooltip component by introducing new properties and restructuring its implementation. The changes include adding showArrow and className props to the TooltipProps type, updating the component's rendering logic to use a more flexible Popper component structure, and modifying the Storybook stories to demonstrate the new functionality with and without arrows. Additionally, the Popper component has been adjusted to manage the arrow display more effectively.

Changes

File Change Summary
src/components/ui/Tooltip/Tooltip.tsx - Added showArrow and className props to TooltipProps
- Updated Tooltip function signature
- Restructured Popper component usage
- Exported TooltipProps type
src/components/ui/Tooltip/stories/Tooltip.stories.tsx - Renamed Basic story to WithArrow
- Added new WithoutArrow story
- Updated story implementations using Primitive.button
src/components/tools/Popper/Popper.tsx - Added showArrow prop to PopperRoot
- Removed showArrow from PopperContent
src/components/tools/Popper/context/PopperContext.tsx - Added showArrow property to TPopperContext type
src/components/tools/Popper/fragments/PopperContent.tsx - Removed showArrow from PopperContentProps
- Added asChild property to PopperContentProps
src/components/tools/Popper/fragments/PopperRoot.tsx - Added showArrow property to PopperRootProps
- Updated context value to include showArrow
src/components/tools/Popper/fragments/PopperTrigger.tsx - Added asChild property to PopperTriggerProps
src/components/tools/Popper/stories/Popper.stories.tsx - Updated properties passed to Popper.Content and Popper.Root

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • kotAPI

Poem

🐰 A tooltip so bright and clear,
With arrows dancing, have no fear!
Popper's magic now unfurled,
Flexible UI takes the world!
Hop along, code's delight! 🎉


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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)
src/components/ui/Tooltip/stories/Tooltip.stories.tsx (2)

20-32: LGTM! Well-structured story with clear demonstration of functionality.

The renamed story with enhanced styling provides a better demonstration of the tooltip's capabilities.

Consider adding a brief comment explaining the grid layout configuration for better maintainability:

+            {/* Grid layout to showcase all placement variations */}
             <div className="grid grid-cols-[repeat(auto-fit,minmax(200px,1fr))] justify-center gap-3">

Line range hint 34-45: LGTM! Good addition demonstrating the new showArrow prop.

The new story effectively showcases the tooltip without arrows while maintaining consistency with the WithArrow story.

Consider adding the same layout comment here for consistency:

+            {/* Grid layout to showcase all placement variations */}
             <div className="grid grid-cols-[repeat(auto-fit,minmax(200px,1fr))] justify-center gap-3">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c137123 and 0bb1e4d.

📒 Files selected for processing (2)
  • src/components/ui/Tooltip/Tooltip.tsx (1 hunks)
  • src/components/ui/Tooltip/stories/Tooltip.stories.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (5)
src/components/ui/Tooltip/Tooltip.tsx (4)

10-12: LGTM! Well-structured prop additions.

The new optional props showArrow and className enhance the component's flexibility while maintaining good TypeScript practices.


14-14: LGTM! Well-structured component signature.

The updated signature properly handles the new props with appropriate defaults.


16-27: LGTM! Excellent implementation of compound components pattern.

The refactored structure using Popper.Root, Popper.Trigger, and Popper.Content improves composability and follows best practices for compound components.


33-33: LGTM! Good practice exporting the props type.

Exporting TooltipProps enables type reuse and improves developer experience.

src/components/ui/Tooltip/stories/Tooltip.stories.tsx (1)

7-7: LGTM! Appropriate import addition.

The addition of Primitive import supports the enhanced story implementation.

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 (8)
src/components/tools/Popper/fragments/PopperTrigger.tsx (2)

8-8: Add JSDoc comment for the asChild prop.

The asChild prop is a powerful composition feature that allows the component to be rendered as a different element. Adding documentation would help other developers understand its purpose and usage.

+ /** When true, the trigger will render its child directly instead of wrapping it in a span */
  asChild?: boolean

11-20: Consider adding type safety for children when asChild is true.

When asChild is true, the children should be a valid React element to ensure proper composition.

- export default function PopperTrigger({ asChild, children, className = '', ...props }: PopperTriggerProps) {
+ export default function PopperTrigger({ asChild, children, className = '', ...props }: PopperTriggerProps) {
+     if (asChild && !isValidElement(children)) {
+         throw new Error('PopperTrigger: children must be a valid React element when asChild is true');
+     }
src/components/tools/Popper/context/PopperContext.tsx (2)

Line range hint 1-1: Create tracking issue for the TODO comment.

The TODO comment about using native floating.tsx should be tracked in an issue for future follow-up.

Would you like me to create an issue to track this TODO item?


11-11: Add JSDoc comment for the showArrow context property.

Document the purpose and usage of the showArrow property in the context.

+ /** Controls the visibility of the floating arrow element */
  showArrow: boolean;
src/components/tools/Popper/fragments/PopperContent.tsx (1)

9-10: Add JSDoc comment for the asChild prop.

Similar to PopperTrigger, document the purpose of the asChild prop.

+ /** When true, the content will render its child directly instead of wrapping it in a div */
  asChild?: boolean;
src/components/tools/Popper/stories/Popper.stories.tsx (1)

Line range hint 17-37: Enhance story coverage.

The story could be improved by:

  1. Adding examples of asChild usage for both Trigger and Content
  2. Demonstrating different arrow configurations
  3. Showing various placement options

Consider adding these additional stories:

export const WithCustomTrigger: Story = {
    render: () => (
        <Popper.Root>
            <Popper.Trigger asChild>
                <button>Custom Button</button>
            </Popper.Trigger>
            <Popper.Content>Content</Popper.Content>
        </Popper.Root>
    )
};

export const WithoutArrow: Story = {
    render: () => (
        <Popper.Root showArrow={false}>
            <Popper.Trigger>Trigger</Popper.Trigger>
            <Popper.Content>Content</Popper.Content>
        </Popper.Root>
    )
};
src/components/tools/Popper/Popper.tsx (1)

Line range hint 11-11: Address or track the TODO comment about collision issues.

The comment indicates that collisions aren't working as expected. This should be investigated and tracked properly.

Would you like me to help create an issue to track this collision-related bug?

src/components/tools/Popper/fragments/PopperRoot.tsx (1)

Line range hint 33-52: Consider optimizing middleware order for better performance.

The middleware stack is configured with arrow, offset, flip, shift, and hide. While this works, the order could be optimized:

  1. offset should typically come before arrow as it affects the base positioning
  2. flip and shift are computationally expensive and should come last

Consider reordering the middleware stack:

 middleware: [
+    offset(ARROW_HEIGHT + GAP),
     arrow({
         element: arrowRef,
         padding: 4
     }),
-    offset(ARROW_HEIGHT + GAP),
     hide({
         strategy: 'referenceHidden'
     }),
     flip({
         mainAxis: true,
         fallbackStrategy: 'initialPlacement'
     }),
     shift({
         crossAxis: false
     })
 ]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be5cc07 and 8de427e.

📒 Files selected for processing (6)
  • src/components/tools/Popper/Popper.tsx (1 hunks)
  • src/components/tools/Popper/context/PopperContext.tsx (1 hunks)
  • src/components/tools/Popper/fragments/PopperContent.tsx (1 hunks)
  • src/components/tools/Popper/fragments/PopperRoot.tsx (3 hunks)
  • src/components/tools/Popper/fragments/PopperTrigger.tsx (1 hunks)
  • src/components/tools/Popper/stories/Popper.stories.tsx (1 hunks)
🔇 Additional comments (3)
src/components/tools/Popper/fragments/PopperContent.tsx (1)

21-24: Verify portal mounting point.

The component uses document.body as a fixed portal root. Consider making this configurable to support different mounting points.

src/components/tools/Popper/Popper.tsx (1)

38-40: Verify the arrow visibility behavior across components.

The changes show that arrow visibility is now managed at the PopperRoot level instead of PopperContent. Let's verify this change is consistent across the component hierarchy.

✅ Verification successful

Arrow visibility implementation is correctly managed

The arrow visibility is properly managed through React Context, with PopperRoot as the single source of truth. The implementation is consistent across the component hierarchy:

  • PopperRoot provides the showArrow state via context
  • PopperContent correctly consumes and respects this value
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining showArrow prop usage in PopperContent
ast-grep --pattern 'showArrow' src/components/tools/Popper/fragments/PopperContent.tsx

# Check for any direct arrow-related DOM elements in PopperContent
rg -l "FloatingArrow" src/components/tools/Popper/fragments/PopperContent.tsx

Length of output: 413


Script:

#!/bin/bash
# Check PopperRoot implementation
ast-grep --pattern 'const PopperRoot' -A 30

# Look for type definitions containing showArrow
rg 'interface.*\{[^}]*showArrow[^}]*\}' --type typescript

# Find all showArrow usages across components
rg 'showArrow' --type typescript

Length of output: 208


Script:

#!/bin/bash
# Find PopperRoot implementation
rg -l "PopperRoot" src/components/tools/Popper/
cat $(rg -l "PopperRoot" src/components/tools/Popper/)

# Find showArrow usages and type definitions
rg "showArrow" src/components/tools/Popper/ -A 2

Length of output: 6535

src/components/tools/Popper/fragments/PopperRoot.tsx (1)

71-71: Ensure PopperContext type includes showArrow.

The context value now includes showArrow, but we should verify that the PopperContext type definition has been updated accordingly.

✅ Verification successful

PopperContext type definition is correctly updated

The PopperContextType interface in src/components/tools/Popper/context/PopperContext.tsx includes showArrow as a required boolean property, which matches its usage in the context provider.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if PopperContext type includes showArrow
ast-grep --pattern 'interface PopperContextType {
  $$$
  showArrow: boolean;
  $$$
}' src/components/tools/Popper/context/PopperContext.tsx

Length of output: 142


Script:

#!/bin/bash
# First verify the file exists
fd "PopperContext.tsx" --type f

# Then look for interface definition and showArrow in a more flexible way
rg -A 10 "interface PopperContextType" --type ts
rg "showArrow.*:" --type ts

Length of output: 542

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