💫 List-rendering component utilizing FLIP position transitions for Leptos

Overview

<AnimatedFor /> component for Leptos

FLIP animations for element and component groups inspired by Vue's <TransitionGroup>.

This crate exports a component similar to Leptos' built-in <For /> with additional properties for applying specific CSS classes to nodes that:

  • are rendered for the first time

  • represent already removed items

  • have their positions changed due to reorder or other elements being added / removed

Each node has to be uniquely keyed, since the original <For />'s logic is used under the hood. Additionally, animations will break for unstable or duplicate keys. You can refer to the official <For /> guide for more detailed information.

Usage

view! {
    <AnimatedFor
        each=items
        key=|item| item.unique_key
        children=|item| view! { /* ... */ }
        enter_from_class="before-enter-animation"
        enter_class="enter-animation"
        move_class="move-animation"
        leave_class="leave-animation"
        appear=true
    />
}
  • enter_from_class - class applied to each new element for a single tick. Then the class is removed and enter_class is inserted instead. This is useful for defining the initial state of an element (e.g. full transparency) before the enter animation starts.

  • enter_class - appended to entering elements. The class is removed on a transitionend or animationend event, or if move transition is triggered before this one ends.

  • move_class - active class for elements moving to their new positions. The class is removed on a transitionend or animationend event (same as enter_class). Reordering items again before they reach their destinations will overwrite the target positions.

  • leave_class - removed items have their "zombie" elements present in the DOM with this class applied. The nodes are finally deleted on a transitionend or animationend event.

  • appear - if true, the enter transition triggers for all children on initial <AnimatedFor /> render.

Example usage with TailwindCSS:

view! {
     <AnimatedFor
        each=items
        key=|item| item.id
        children=|item| item.view
        enter_from_class="opacity-0"
        enter_class="duration-800"
        move_class="duration-1200"
        leave_class="opacity-0 duration-500"
        appear=true
    />
}

Check out examples directory for a complete code.

SSR support

You need to utilize the ssr feature for the crate to work properly in a SSR project. See the example Cargo.toml configuration.

Known issues

  • Given a child element with always present transition or transition-duration style property, move transition breaks if triggered before the previous move transition has finished.
    Unless the children are reordered frequently, this should not be a problem.
    To prevent the glitch from occurring, make sure that the transition-related properties are applied only via enter_class, move_class, or leave_class props. In case you need the transitions for e.g. hover animations, you can wrap the elements in additional <div> nodes, so <AnimatedFor /> can work on them instead.
    As of writing this, I'm not sure how to fix this, but I will investigate this in the future.

  • Elements rendered on server-side have no enter_from_class applied initially. In combination with appear prop, the nodes may be visible for a short time before the enter animation starts.
    If you care about the initial entering transition, make sure that the list is rendered only in the browser.

TODO

  • Tests
  • Investigate the known issues
  • Detect duplicate keys for better developer experience
  • Add ability to define custom handlers when an element enters "before enter" / "enter" / "move" / "leave" state
  • Optional properties for explicit animation durations
  • Optional bool prop for assigning a static z-index to each child, so triggering a move transition before the previous one has finished doesn't cause overlapping elements to be chaotically moved from front to back and vice versa.

License

MIT License

Copyright (c) 2023-PRESENT Kajetan Welc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
A website for the Leptos Web Framework!

Leptos Website A Repo for the public facing Leptos website. Still a WIP. Client Side Rendering This example cannot be built as a trunk standalone CSR-

A Nix template for full-stack web apps in Rust using Leptos

leptos-fullstack A Nix template for full-stack web apps in Rust using Leptos. Tech used: Leptos full-stack framework server functions ssr + hydration

Experimental integration of `fedimint-client` with the Leptos web frontend framework
Experimental integration of `fedimint-client` with the Leptos web frontend framework

CAUTION: highly experimental, the Database implementation is likely horribly broken Fedimint Client built with Leptos This repo contains a proof-of-co

Leptos server signals synced through Server-Sent-Events (SSE)

Leptos Server Sent Events Server signals are leptos signals kept in sync with the server through server-sent-events (SSE). The signals are read-only o

Leptos integration with Golden Layout.

Leptos Golden Layout Leptos integration with Golden Layout. This has many features missing but covers the basics for integrating leptos with golden la

Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev

Tailwind-Leptos-Tauri Template Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev Just clone the rep

A fully extensible command interface to navigate around your leptos application.

leptos-kbar A fully extensible command interface to navigate around your leptos application. See demo: https://leptos-kbar.vercel.app/ Roadmap leptos-

A Cli to generate React Component and Hooks.

React Cli A cli to create React Components and Hooks. Instructions: Download the binary. To Create A React Component ./react -n Component Name T

Process Injection via Component Object Model (COM) IRundown::DoCallback().
Process Injection via Component Object Model (COM) IRundown::DoCallback().

COM PROCESS INJECTION for RUST Process Injection via Component Object Model (COM) IRundown::DoCallback(). 该技术由 @modexpblog 挖掘发现,在我对该技术进行深入研究过程中,将原项目 m

Releases(v0.0.4)
Owner
Kajetan Welc
Kajetan Welc
A zero-config leptos component to display markdown

A port of yew-markdown using leptos ! Usage You can use this component to render both static and dynamic markdown. Static markdown use leptos::*; {

Antonin Peronnet 4 Aug 4, 2023
A UI component library for Leptos, based on Tailwind Elements.

leptos-twelements A UI component library for Leptos, based on Tailwind Elements. Installation (for projects using cargo leptos) Use the nightly rust c

Sebastian Meßmer 4 Oct 20, 2023
A binary that bootstraps a Leptos application with client side rendering, tailwind, and vercel

create-leptos-csr-tw This CLI provides a quick setup to start building web applications using the Leptos web framework integrated with TailwindCSS. It

Matthew 3 Nov 3, 2023
A rust binary that will flip one or more bits of a file (mostly for messing with images for fun).

file-bitflipper A rust binary that will flip one or more bits of a file (mostly for messing with images for fun). Example (bitflipped bentley) Usage $

null 1 Aug 31, 2022
A small Rust library that let's you get position and size of the active window on Windows and MacOS

active-win-pos-rs A small Rust library that let's you get position and size of the active window on Windows and MacOS Build % git clone https://github

Dmitry Malkov 21 Jan 6, 2023
Rusty Shellcode Reflective DLL Injection (sRDI) - A small reflective loader in Rust 4KB in size for generating position-independent code (PIC) in Rust.

Shellcode Reflective DLL Injection (sRDI) Shellcode reflective DLL injection (sRDI) is a process injection technique that allows us to convert a given

null 242 Jul 5, 2023
git-cliff can generate changelog files from the Git history by utilizing conventional commits as well as regex-powered custom parsers.⛰️

git-cliff can generate changelog files from the Git history by utilizing conventional commits as well as regex-powered custom parsers. The changelog template can be customized with a configuration file to match the desired format.

Orhun Parmaksız 5k Jan 9, 2023
auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.

Auto Rust auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, util

Minsky 6 May 14, 2023
A simple solution for scoped styles in Leptos

Styled: Easy Styling for Leptos Components If you're looking for an easy way to apply scoped styles to your Leptos components, Styled is the Leptos ma

Eran Boodnero 8 Mar 5, 2023
A formatter for the leptos view! macro

leptosfmt A formatter for the leptos view! macro All notable changes are documented in: CHANGELOG.md Install cargo install leptosfmt or for trying out

Bram 13 Apr 4, 2023