Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Animation utilities for Leptos. FLIP, in/out transitions, and helpers for custom animations.
Features
FLIP
FLIP technique is the first-class citizen in this crate. It allows you to animate elements that have been moved due to reordering or addition/removal of other nodes in the DOM.
Example:
use *;
use ;
The directive checks for changes in the DOM when a signal passed to Flip::watch is updated. Therefore, always make sure that the animated elements are provided with the same trackable primitive that powers their rendering logic.
Configuration:
view!
-
delay- self-explanatory, no delay by default. -
duration- can be either a fixed duration or a function that takes the total distance an element is going to travel and returns the move duration for that specific element. Such a function is used by default, so it may often not fit your use case. -
easing- you can pass a custom function to generate animation keyframes or use one of the provided by the library. The default iseasing::cubic_out.
Custom CSS classes on enter/leave
A common use case is to animate elements when they enter or leave the DOM. This can be done via CSS classes in combination with animations::classes module.
Example utilizing Tailwind CSS:
use *;
use ;
In this example, the element is initially rendered with opacity-0 and duration-150 classes. A frame later, opacity-0 is removed and opacity-100 takes its place. Both remaining classes (duration-150 and opacity-100) are removed once the animation is finished.
In most scenarios, specifying target is unnecessary as removing the starting class should be sufficient to transform the element to its final state.
To sum this up:
-
source- initial classes added before the element is inserted and removed one frame after. -
active- applied during the entire entering phase and removed once the animation is finished. -
target- classed added one frame after the element is inserted and removed once the animation is finished.
There are 2 more noteworthy options when defining such a behavior:
-
delay- additional time beforesourceclasses are removed andtargetclasses are added. -
duration- defines when the animation is considered finished:-
fixed duration
-
(default) hook on
transitionendevent -
hook on
animationendevent -
a custom function returning
Futurethat is being awaited -
hook on
onfinishevent on each present Animation for the element
-
Animating elements leaving the DOM works in a similar fashion:
use *;
use ;
In this case, when the element is removed from the DOM, it is being reinserted with opacity-100 and duration-150 classes. In the next frame, opacity-100 is removed and opacity-0 is added. Once the animation is done, the "zombie" element is removed.
You are free to mix multiple animations together:
use *;
use ;
Predefined animations
Common animations will be added to the crate over time, which should simplify setup in most cases.
For example, you need a simple FLIP list with fade-in/out transitions:
use *;
use ;
Check the animations module for available animations and their respective configuration.
Custom animations
The crate aims to help you define your own animation in a organized way:
use Duration;
use HtmlElement;
use ;
// Create an initializer for your animation. It can provide configuration options if needed.
;
// Once the element is being rendered, the initializer will be called and should create
// the actual animation listening for various events and operating on the node.
// Define the animation's state - usually, it will be the element and potentially some
// behavior configuration.
// Implement the animation logic - what should happen on which event.
// In this case, we want to append an animation the moment the element is rendered.
// You need to implement all of the supported listeners to fulfill the trait bounds.
// Empty implementation specifies that the event will be ignored.
// And there is also a helper macro to reduce the boilerplate.
impl_empty_animation_listeners!;
Then you can use it in combination with the animate directive:
Notes
-
The crate is in its early stages, so expect some more or less breaking changes in the future.
If you have any suggestions or ideas, feel free to open an issue or a PR. -
The recommended way to use the utilities is via custom high-level wrappers that would encapsulate common configurations across your codebase. For example:
use *; use ; use Duration; -
There are examples if you need more help with the setup.
Leptos compatibility
| Crate version | Compatible Leptos version |
|---|---|
| 0.1.x | 0.8.x |