Skip to content

Conversation

@GoldGroove06
Copy link
Contributor

@GoldGroove06 GoldGroove06 commented Apr 4, 2025

closes #580

Summary by CodeRabbit

  • New Features

    • The Avatar component now includes an optional asChild property, allowing for more flexible rendering options.
  • Tests

    • Added test coverage to ensure the Avatar component renders correctly with the new asChild property in different scenarios.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

Walkthrough

The changes introduce an optional asChild property to the Avatar component and its primitive subcomponents. This property is added with a default value of false and is propagated to modify rendering behavior. Additionally, a new test case verifies the correct behavior when asChild is provided. The updates span the main Avatar component, its test suite, and the underlying primitive components, all ensuring a consistent implementation of the new property.

Changes

Files Change Summary
src/components/ui/Avatar/Avatar.tsx, src/core/primitives/Avatar/…/AvatarPrimitiveFallback.tsx, src/core/primitives/Avatar/…/AvatarPrimitiveRoot.tsx Added optional asChild?: boolean (default false) to Avatar props and primitives; updated components to use <Primitive.span> with the asChild prop for conditional rendering.
src/components/ui/Avatar/tests/Avatar.test.tsx Added a test verifying that rendering yields a <div> when asChild is true.

Sequence Diagram(s)

sequenceDiagram
    participant A as Avatar Component
    participant AP as Avatar Primitive Component
    participant PS as Primitive.span

    A->>AP: Pass asChild flag (default: false)
    AP->>PS: Render using asChild prop
Loading

Assessment against linked issues

Objective Addressed Explanation
Add asChild support for Avatar and its components [#580]
Add tests to verify asChild behavior in the Avatar component [#580]

Suggested labels

automerge

Suggested reviewers

  • kotAPI

Poem

I'm a bunny coding with delight,
Adding props to make our Avatar just right.
With asChild guiding every render so neat,
My hops dance through each new feature beat.
Cheers to changes that make our code complete! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4237023 and f4ad5e3.

📒 Files selected for processing (1)
  • src/components/ui/Avatar/tests/Avatar.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/ui/Avatar/tests/Avatar.test.tsx

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 (1)
src/core/primitives/Avatar/fragments/AvatarPrimitiveFallback.tsx (1)

14-14: Missing space after comma in parameter list.

There should be a space after the comma between color = '' and asChild = false for consistent formatting.

-const AvatarPrimitiveFallback = ({ children, className = '', color = '',asChild = false }: AvatarPrimitiveFallbackProps) => {
+const AvatarPrimitiveFallback = ({ children, className = '', color = '', asChild = false }: AvatarPrimitiveFallbackProps) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between da886ae and 4237023.

📒 Files selected for processing (4)
  • src/components/ui/Avatar/Avatar.tsx (1 hunks)
  • src/components/ui/Avatar/tests/Avatar.test.tsx (1 hunks)
  • src/core/primitives/Avatar/fragments/AvatarPrimitiveFallback.tsx (1 hunks)
  • src/core/primitives/Avatar/fragments/AvatarPrimitiveRoot.tsx (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/core/primitives/Avatar/fragments/AvatarPrimitiveFallback.tsx (1)
src/core/primitives/Avatar/contexts/AvatarPrimitiveContext.tsx (1)
  • AvatarPrimitiveContext (13-13)
🔇 Additional comments (11)
src/components/ui/Avatar/tests/Avatar.test.tsx (1)

41-45: Good addition to test the asChild functionality.

This test appropriately verifies that when asChild is set to true, the Avatar.Root component correctly renders as the provided child element (a div) instead of its default element. The verification checks both the content and the element type, which is a thorough approach.

src/components/ui/Avatar/Avatar.tsx (3)

18-18: Well-typed property addition.

The asChild property has been correctly added to the AvatarProps type definition as an optional boolean, which aligns with how this property is typically used in component libraries.


22-22: Proper default value for asChild.

Setting the default value of asChild to false ensures backward compatibility with existing code that doesn't explicitly pass this prop.


27-27: Correctly passing the asChild prop to the primitive component.

The asChild prop is appropriately passed down to AvatarPrimitive.Root where it will be used to modify the rendering behavior.

src/core/primitives/Avatar/fragments/AvatarPrimitiveFallback.tsx (3)

5-5: Necessary import for asChild functionality.

The import of the Primitive component is required to enable the asChild functionality.


11-11: Well-typed property addition.

The asChild property has been correctly added to the AvatarPrimitiveFallbackProps interface as an optional boolean.


21-21: Correctly using Primitive.span with asChild prop.

The implementation properly uses Primitive.span instead of a regular span element, passing along the asChild prop to enable the polymorphic component behavior.

src/core/primitives/Avatar/fragments/AvatarPrimitiveRoot.tsx (4)

6-6: Necessary import for asChild functionality.

The import of the Primitive component is required to enable the asChild functionality.


13-13: Well-typed property addition.

The asChild property has been correctly added to the AvatarPrimitiveRootProps interface as an optional boolean.


16-16: Proper default value for asChild.

Setting the default value of asChild to false ensures backward compatibility with existing usage of this component.


44-44: Correctly using Primitive.span with asChild prop.

The implementation properly uses Primitive.span instead of a regular span element, passing along the asChild prop to enable the polymorphic component behavior.

@kotAPI kotAPI added the automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met label Apr 4, 2025
@kodiakhq kodiakhq bot merged commit df05128 into rad-ui:main Apr 4, 2025
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[New Feature] Add asChild support for Avatar and it's components

2 participants