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

add asChild prop to UI components #6110

Closed
wants to merge 1 commit into from

Conversation

jnsdls
Copy link
Member

@jnsdls jnsdls commented Jan 30, 2025

TL;DR

Added asChild prop support to UI components, enabling better composition with custom elements.

What changed?

  • Added asChild prop to various UI components including SiteLink, AccountAddress, AccountAvatar, AccountBalance, AccountName, ChainIcon, ChainName, NFTDescription, NFTName, TokenIcon, TokenName, TokenSymbol, WalletIcon, and WalletName
  • Integrated Radix UI's Slot primitive to enable component polymorphism
  • Added @radix-ui/react-slot as a new dependency

How to test?

  1. Import any UI component
  2. Pass the asChild prop along with a custom element
<AccountName asChild>
  <div>Custom wrapper for account name</div>
</AccountName>
  1. Verify that the component renders with the custom element while maintaining its functionality

Why make this change?

This change provides more flexibility in component composition, allowing developers to customize the rendered elements while maintaining the core functionality. This is particularly useful for:

  • Custom styling requirements
  • Accessibility improvements
  • Integration with other UI libraries
  • Building more complex component hierarchies

PR-Codex overview

This PR focuses on allowing the asChild prop for most UI components, enabling them to render as a different component (like Slot.Root) rather than the default HTML element. This enhances flexibility in component usage.

Detailed summary

  • Added asChild prop to various components.
  • Updated rendering logic to use Slot.Root if asChild is true.
  • Modified related components: SiteLink, AccountAddress, NFTName, NFTDescription, AccountName, WalletName, ChainName, ChainIcon, AccountBalance, AccountAvatar, TokenIcon, TokenSymbol, TokenName, WalletIcon, and SocialIcon.
  • Adjusted package.json files to update @radix-ui/react-slot version to 1.1.1.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Jan 30, 2025

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

Name Status Preview Comments Updated (UTC)
docs-v2 ❌ Failed (Inspect) Jan 30, 2025 0:49am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 0:49am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 0:49am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 0:49am

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jan 30, 2025
Copy link
Member Author

jnsdls commented Jan 30, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jnsdls jnsdls marked this pull request as ready for review January 30, 2025 00:34
@jnsdls jnsdls requested review from a team as code owners January 30, 2025 00:34
Copy link
Contributor

github-actions bot commented Jan 30, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 46.6 KB (0%) 933 ms (0%) 590 ms (+62.36% 🔺) 1.6 s
thirdweb (cjs) 122.39 KB (0%) 2.5 s (0%) 991 ms (+6.48% 🔺) 3.5 s
thirdweb (minimal + tree-shaking) 5.58 KB (0%) 112 ms (0%) 104 ms (+93.12% 🔺) 215 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 26 ms (+58.07% 🔺) 36 ms
thirdweb/react (minimal + tree-shaking) 19.28 KB (0%) 386 ms (0%) 122 ms (+0.03% 🔺) 508 ms

@jnsdls jnsdls force-pushed the add_asChild_prop_to_UI_components branch from 8e0f77d to 7bda6cd Compare January 30, 2025 00:42
Copy link

changeset-bot bot commented Jan 30, 2025

🦋 Changeset detected

Latest commit: 7bda6cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard. Ecosystem Portal Involves changes to the Ecosystem Portal packages Playground Changes involving the Playground codebase. Portal Involves changes to the Portal (docs) codebase. SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant