#leptos

leptos_animation

Create animated signals in the Leptos framework

7 releases (4 breaking)

0.5.2 May 15, 2024
0.5.1 May 5, 2024
0.5.0 Mar 12, 2024
0.4.0 Nov 10, 2023
0.1.0 Jun 29, 2023

#105 in #leptos

Download history 43/week @ 2024-07-23 12/week @ 2024-07-30 15/week @ 2024-08-06 2/week @ 2024-09-03 10/week @ 2024-09-10 7/week @ 2024-09-17 28/week @ 2024-09-24 4/week @ 2024-10-01 13/week @ 2024-10-08 8/week @ 2024-10-15

55 downloads per month

WTFPL license

36KB
590 lines

Docs | Demo

Create derived signals that are animated versions of the original signal

use leptos::*;
use leptos_animation::*;

#[component]
pub fn Counter() -> impl IntoView {
    AnimationContext::provide();

    let (value, set_value) = create_signal(0.0);

    let animated_value = create_animated_signal(move || value.get().into(), tween_default);

    let clear = move |_| set_value.set(0.0);
    let decrement = move |_| set_value.update(|value| *value -= 1.0);
    let increment = move |_| set_value.update(|value| *value += 1.0);

    view! {
        <main class="simple">
            <button on:click=clear>"Clear"</button>
            <button on:click=decrement>"-1"</button>
            <button on:click=increment>"+1"</button>
            <div>"Value: " {value} <br/> "Animated value: " {animated_value}</div>
        </main>
    }
}

Features

  • Allows for multiple animations playing simultaneously
  • Efficiently calls window.request_animation_frame(): only when there are animations playing and only once per frame even if there are multiple animated signals running.
  • Allows for custom durations, easing functions, target updates and tween methods. Can be made to work for any type.
  • Animated signals are all updated simultaneously per frame. Effects that use multiple animated signals are called only once per frame.

Dependencies

~20–32MB
~504K SLoC