-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte 5: Allow passing use
and transition
to components
#11452
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
Comments
I think the major difference is that now there is a non-breaking way to implement it (using runes), instead of the ways proposed before (props with special names). It's fitting to add something like this in a major version, and I think the fact it was proposed so many times (once with a lot of likes too) means it would be a loved feature.
I think that having a standardized way to do this would be great, and it would motivate component library authors to actually allow transitions/actions, or even animations on their components (I can't find even one that allows all three). I also think it reduces boilerplate, especially if it's implemented using a single rune, like so: <script>
const { in, out, actions, animation } = $directives()
</script>
<div in:in out:out use:actions animate:animation>...</div> or even like this if you want to allow/forward all directives <script>
const directives = $directives()
</script>
<div apply:directives>...</div> (but I think this is getting a little out of scope and has more issues - the idea is the same) It really reduces the amount of code needed for both the component author and the user, especially if you want to use transitions or animations with props, multiple actions, etc. |
The dev team repeatedly demonstrated that they aren't interested in this feature, especially when a simple workaround exists. Another problem is that it can be used only on components where authors declared the forwarding, while the wrapper approach works with any component. |
We have some ideas for how to tackle this problem post-5.0, but it won't look like this. Will share more when we can, but in the meantime I'll close this to save people from spending energy on something we're not going to pursue. |
Describe the problem
It's difficult to apply transitions/animations/actions to components. Sometimes libraries offer support for applying transitions - like Skeleton with dynamic transitions, but this requires quite some work for every component library author, and many times it's not there. More often than not you end up having to use a wrapper div:
This isn't ideal (might cause issues with layouts, selectors or such) and the transition/action would work perfectly fine applied to the root component element.
Describe the proposed solution
Add a standardized way to pass transitions/animations/actions to components, which can then apply them on an element (or even another component). An idea of how that might look like:
For example, when a component is used like so:
Then
$transitions()
would return an object constructed like so:And actions like so:
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: