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

Public API for creating Animation from the svelte/transition module #9911

Open
adiguba opened this issue Dec 13, 2023 · 5 comments
Open

Public API for creating Animation from the svelte/transition module #9911

adiguba opened this issue Dec 13, 2023 · 5 comments

Comments

@adiguba
Copy link
Contributor

adiguba commented Dec 13, 2023

Describe the problem

The svelte/transition module is really useful and easy to use, but it is restricted to the template and the {#if} / {#each} blocks.

It would be convenient to be able to use them manually if needed.

Describe the proposed solution

Provide a public fonction for creating animation based on the svelte/transition module.

Something like this :

import { slide } from 'svelte/transition';
import { quintOut } from 'svelte/easing';

/** @type {HTMLElement} */
let dom = ...

const anim = createAnim(dom, slide, {duration: 500, easing: quintOut});

transition will be a object Animation or TickAnimation, with method like play(), pause(), reverse(), cancel(), finish() and one onfinish handler

Example in this REPL, where transition.js mainly consists of code from internal/client/transition.js

Alternatives considered

Use duplicate code or another library

Importance

would make my life easier

@huntabyte
Copy link
Member

huntabyte commented Dec 16, 2023

Something like this would be pretty sweet, especially for SEO purposes. Think collapsible/accordion components where the content is collapsed until opened. If you use {#if} blocks to leverage svelte transitions, this prevents the non-open content from being picked up for SEO.

Justification for adding to the framework vs just having everyone create their own is some form of soft standardization/predictability across the ecosystem.

@7nik
Copy link
Contributor

7nik commented Dec 16, 2023

Working right on DOM elements isn't svelty way.

For collapsing elements, there is svelte-collapse (though it needs a fix for folding margins, padding, and borders) and svelte-collapsible build on top of the former.

For many other cases, CSS transition and animation usually provide enough flexibility. For other cases involving more complex animations, you may want to use svelte-motion or some other animation lib.

And, after all, it is possible to copy the transitions into its own library and expose them via whatever interface you want.

@huntabyte
Copy link
Member

Working right on DOM elements isn't svelty way.

For collapsing elements, there is svelte-collapse (though it needs a fix for folding margins, padding, and borders) and svelte-collapsible build on top of the former.

For many other cases, CSS transition and animation usually provide enough flexibility. For other cases involving more complex animations, you may want to use svelte-motion or some other animation lib.

And, after all, it is possible to copy the transitions into its own library and expose them via whatever interface you want.

Both of those projects work "right on DOM elements" via an action

@adiguba
Copy link
Contributor Author

adiguba commented Dec 16, 2023

It's just that Svelte offers a simple and effective transition module, but which is restricted to {#if}/{#each}.

So we have all the basic, except that we cannot invoke it directly without add/removing nodes...

It's not a "big deal", but it could be practical.

@7nik
Copy link
Contributor

7nik commented Dec 16, 2023

@huntabyte I'm about

/** @type {HTMLElement} */
let dom = ...

const anim = createAnim(dom, slide, {duration: 500, easing: quintOut});

Exposing an element into a dom or smth to then use a build-in thing isn't svelty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants