-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
<svelte:element> proposal implementation #3928
Conversation
@erzr I can't comment on the proposal itself as I've never had need for this, but this PR could definitely use some tests. Edit: I'm beginning to understand what this is about, and if it is accepted, I think we could re-use the existing
rather than creating a slightly confusing new |
@antony Thanks for the feedback. Definitely do not disagree with the tests feedback. I didn't spend any time writing them because I was unsure if those proposal was something that Svelte was interested in as a whole. I did consider re-purposing vs Considering svelte/src/compiler/compile/nodes/Element.ts Lines 676 to 683 in ea66d52
Open to suggestions here. If this gets positive feedback and has a chance of getting merged in, I'm happy to spend the time writing tests to cover the new functionality. |
I haven't looked at the code yet but I agree that this should be its own special tag, I don't think it makes sense to use |
I am curious if this is being looked at seriously or not. This is currently an issue I keep running into when trying to build highly general purpose UI Library style component sets. Even the simple case of wanting to create a component that could be any of a number of tags (a, button, input[type=button|submit]) requires quite a bit of boilerplate where this proposal would make it mostly very trivial. If the concern is baking in special case code for things like setting attributes then possibly requiring a staticly declared list of possible tags's would suffice? <!-- is="" being a compile time only prop supporting a static set of valid tag names -->
<svelte:element tag={'a'} is="a, button, input" /> |
I keep needing this feature three times a week. |
I can see a few scenarios where this would be beneficial. Having the ability to augment some component's <Box as="article">
<Heading as="h2">
<List as="ol">
... Here's a super naive implementation of a generic Could |
The feature is highly likely to be implemented, the API and implementation are the only real topics of discussion right now. |
Need this feature +1. Is there anything I can help with? |
I definitely would reach for this, especially in the creation of component libraries for use in a design system. What is holding this PR up from approval, just the merge conflict? What is outstanding? I would love to help out as well. |
I think extending the It would also make it easier to deal with different forms of structured JSON content (from CMSs like Contentful, Primic, etc) where you can embed rich elements inside the text block/wysiwyg field types. https://www.contentful.com/developers/docs/concepts/rich-text/ |
It looks like there's another implementation of this here: #5481 |
I'm going to close this because #5481 is a more complete implementation and has been reviewed more at this point. Hopefully it'll be adopted soon. |
An implementation of the proposal described in #2324.
Problem:
There's currently no way to dynamically specify a tag for an element. This is problematic if you want the ability to add a
tag
prop to a component and have some or all of that component be wrapped in the tag specified. Workarounds for this issue result in large, incomplete wrapper components such as https://github.com/erzr/jss-svelte/blob/master/packages/jss-svelte/src/components/TagWrapper.svelte that just cover the most commonly used tags.Solution:
A new element named
svelte:element
has been implemented that accepts a single proptag
, which could be a string or variable containing the tag name.Usage:
<svelte:element tag="h1">This is an h1</svelte:element>