Transitions
CSS-based enter/leave animations using snabbdom hooks. Sygnal uses a Vue-style transition system where a single name prop generates six CSS classes for fine-grained control over enter and leave animations.
import { Transition } from 'sygnal'
function AnimatedList({ state }) { return ( <div> <Transition name="fade"> {state.visible && <div className="content">Animated!</div>} </Transition> </div> )}| Prop | Type | Default | Description |
|---|---|---|---|
name | string | 'v' | Base name for generated CSS classes |
duration | number | — | Explicit timeout in ms. If omitted, listens for transitionend event |
CSS Class Lifecycle
Section titled “CSS Class Lifecycle”Given name="fade", the following classes are applied automatically:
On enter (element inserted):
fade-enter-from+fade-enter-activeadded simultaneously- Next frame:
fade-enter-fromremoved,fade-enter-toadded - On transition end:
fade-enter-activeandfade-enter-toremoved
On leave (element removed):
fade-leave-from+fade-leave-activeadded simultaneously- Next frame:
fade-leave-fromremoved,fade-leave-toadded - On transition end:
fade-leave-activeandfade-leave-toremoved, then element is removed from DOM
CSS Example
Section titled “CSS Example”/* Active classes define the transition properties */.fade-enter-active,.fade-leave-active { transition: opacity 0.3s ease;}
/* "from" classes define the starting state */.fade-enter-from,.fade-leave-to { opacity: 0;}Slide Example
Section titled “Slide Example”.slide-enter-active,.slide-leave-active { transition: transform 0.3s ease;}
.slide-enter-from { transform: translateX(-100%);}
.slide-leave-to { transform: translateX(100%);}<Transition name="slide"> {state.showPanel && <div className="panel">Slides in and out</div>}</Transition>Explicit Duration
Section titled “Explicit Duration”If your animation doesn’t use CSS transitions (or you want a fixed timeout), pass duration:
<Transition name="fade" duration={500}> {state.visible && <div>Uses setTimeout instead of transitionend</div>}</Transition>