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

Allow snippet to use animate directive #14792

Open
Refzlund opened this issue Dec 20, 2024 · 1 comment
Open

Allow snippet to use animate directive #14792

Refzlund opened this issue Dec 20, 2024 · 1 comment

Comments

@Refzlund
Copy link

Refzlund commented Dec 20, 2024

Describe the problem

This is currently not allowed:

{#snippet test(item)}
    <div animate:flip>{item}</div>
{/snippet}

{#each arr as item (item)}
    {@render test(item)}
{/each}

This would be useful if you for instance, make a snippet that renders a list of items;

{#snippet test(item)}
    <div animate:flip>{item}</div>
{/snippet}

{#snippet list(array, itemSnippet)}
    {#each arr as item (item)}
        {@render itemSnippet(item)}
    {/each}
{/snippet}

{@render list(arr, test)}

As a practical example; I'm working on a drag-and-drop library runic-reorder which utilises above strategy.

This way of working with snippets expands the ease of use for design choices when creating a library.

I bring this up, as I noticed on Svelte Playground that snippets are a lot like regular elements, and attaching $.animation(div_1, () => flip, null); within a snippet might be feasable🙏

Describe the proposed solution

{#snippet test(item)}
    <div animate:flip>{item}</div>
{/snippet}

{#each arr as item (item)}
    {@render itemSnippet(item)}
{/each}

or in compiled version words

// snippet
const test = ($$anchor, item = $.noop) => {
    var div = root_1();
    var text = $.child(div, true);

    $.reset(div);
    $.template_effect(() => $.set_text(text, item()));
    $.animation(div, () => flip, null); // this
    $.append($$anchor, div);
};

Importance

would make my life easier

@Refzlund
Copy link
Author

Refzlund commented Dec 21, 2024

I've created a branch feat: enable animate directive for snippets. If this feature is a no-go, let me know🦒

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

No branches or pull requests

1 participant