-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[feature] Dynamic elements implementation <svelte:element> #6898
[feature] Dynamic elements implementation <svelte:element> #6898
Conversation
… values as tag. Throw an error when trying to bind other than this. Add more tests.
I agree with you! MEMO: complete code to reproduce this<script>
import {fade} from 'svelte/transition';
let tag = "p";
function click(newTag) {
tag = newTag;
}
</script>
tag: {tag}
<button on:click="{() => click('p')}">Click me! (-> p)</button>
<button on:click="{() => click('div')}">Click me! (-> div)</button>
<button on:click="{() => click(null)}">Click me! (-> null)</button>
<svelte:element this={tag} transition:fade style="border: 1px solid #000">
svelte:element tag
{#if tag === 'p'}
<p>foo</p>
{/if}
</svelte:element>
{#if tag === "div"}
<div transition:fade style="border: 1px solid #000">
div tag
{#if tag === 'p'}
<p>foo</p>
{/if}
</div>
{/if}
{#if tag === "p"}
<p transition:fade style="border: 1px solid #000">
p tag
{#if tag === 'p'}
<p>foo</p>
{/if}
</p>
{/if} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick response! Your code snippet doesn't play the animation but it changes the tags and the order. To me this is just as much of and edge case as the transition bug, so I'm ok with that limitation for now and therefore think we should keep the animation support I added.
I'm therefore giving my approval on this PR. I'll try to get a second pair of eyes from another maintainer on this, soon.
I was just doing something similar, do you have an approximate date when this implementation will go into production? |
@baseballyama @dummdidumm ok i've made changes, this animates now. |
Thank you so much!
I initially thought it would be better to leave it as a limitation rather than introduce a new method like |
Thank you @baseballyama, @alfredringstad, @tanhauhau and all the others for your invaluable help implementing this! |
Thank you so much for your big support too!! 💪💪 |
Tutorial after clicking "Show me": |
Does Svelte have TypeScript type for the tags like React's I want to achieve something akin to this with svelte:element: https://www.youtube.com/watch?v=uZ8GZm5KEXY |
Hi Bruno,
Please ask questions in the discord, thanks!
On Fri, 8 Apr 2022 at 22:49, bruno edoh ***@***.***> wrote:
Does Svelte have TypeScript type for the tags like React's
React.ElementType and React.ComponentProps?
I want to achieve something akin to this with svelte:element:
https://www.youtube.com/watch?v=uZ8GZm5KEXY
—
Reply to this email directly, view it on GitHub
<#6898 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABVORP53664UTXSRNKUIKLVECSWXANCNFSM5HJGWERA>
.
You are receiving this because you commented.Message ID:
***@***.***>
--
…________________________________
ꜽ . antony jones . http://www.enzy.org
|
It works fine now! |
@baseballyama Thanks. :) |
Woooh! Thank you everyone! |
Again I started to refactor therender_dom
part. I think we should implement<svelte:element>
as Element + dynamic tag completely for maintainability.=> DONE.
This is based on #5481.
I cleaned up the code and few changes.
FIx few bugs.
<svelte:element>
's tag.Return compile error if svelte:element has
animate
because<svelte:element>
doesn't support it.Stop to use
DynamicElement
classes. Because...DynamicElement
without extending makes much duplicate code, therefore I added a feature to Element which can have a tag dynamically.Add more tests
Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint