-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Slot component vs useRender hook #1315
Comments
Can I work on this? I prob will follow a similar implementation with radix. |
I landed here reading https://adamfratino.com/notes/base-ui-vs-radix-ui from @adamfratino that says
Makes sense. For example, I could imagine all the Material UI components supporting this |
Off-topic. I see potential for @samuelsycamore to help with the docs around this feature. I landed on https://base-ui.com/react/handbook/composition and read: ![]() I had to pause and focus to understand. Maybe it's because I have some level of dyslexia or autism. I don't know, something about it made it hard for me. To compare with https://ariakit.org/guide/composition#changing-the-html-element that documents the same concept: ![]() I didn't feel this struggle. "The render prop lets you specify a different HTML element to be rendered instead of the default element" connected instantly for me. I wasn't 100% aware of what the prop was doing until now, so I experienced this closer to what a pristine user would. |
Sure @seloner! I have already added it to the roadmap for our January cycle, so feel free to take it. Thanks! |
@oliviertassinari that's the first and only article i've written 🫣, glad it made some sense! and thanks for tagging me. +1 the ability to easily apply a for example, our team uses a few polymorphic layout primitives (box, stack, group, layer, etc.), currently leveraging |
@adamfratino If you are interested in trying this out, there's now an open PR with a POC and a sandbox for a |
We have two options on how to provide this feature, hook based and component based. You can check the difference in usage here: https://deploy-preview-1418--base-ui.netlify.app/react/utils/use-renderer#usage Which API would you prefer? |
I think the hook is nice. There's also nothing to stop us from naming the prop I wish I'd had the time to look at this more closely but, is it correct to assume that this... const { renderElement } = useRenderer({
render: render ?? <p />,
state,
className,
props: otherProps,
}); ... will correctly merge / combined props from both the container component - Also I may be wrong, but the component approach would require some clever types and typed refs to play nicely with a polymorphic Slot component? So overall, I think +1 for the hook. Although we've used the |
Yes exactly.
True, if we want to allow just spreading props on the component we will have to either have more complex types, which may cause some issues with TS compilation time (we had that in the past in Material UI), or we could make theм looser, we'll see. For now, let's just focus on DX, to see what makes most sense. |
Feature request
Summary
There is interest from users in having a helper to create their own polymorphic components using
render
.Examples in other libraries
https://www.radix-ui.com/primitives/docs/utilities/slot
https://github.com/radix-ui/primitives/tree/main/packages/react/slot/src
Motivation
It's quite a common need when creating a styled component library.
The text was updated successfully, but these errors were encountered: