Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/compose_svelted/llms.txt
Use this file to discover all available pages before exploring further.
AnimatedContent watches a targetState value and animates the transition whenever that value changes. While the outgoing state plays its exit CSS animation the incoming state is already mounted, creating a smooth crossfade between two pieces of UI. The transition style is controlled by a ContentTransition value, which encodes enter and exit inline styles together with a shared duration.
This component is the foundation for declarative state-driven animations in Compose Svelted. It is also used internally by NavHost to animate screen-to-screen navigation.
Props
The value that determines which content is currently active. Whenever this value changes,
AnimatedContent triggers its transition sequence — playing the exit style on the outgoing content, then swapping to the new state and playing the enter style.The
ContentTransition object that defines the enter inline style, the exit inline style, and how long the transition lasts in milliseconds. Defaults to a simple 300 ms opacity crossfade.The default value
fade() is applied internally. The fade factory function accepts any duration you pass; fade() without arguments uses 300 ms.How it works
AnimatedContent renders its slot inside a positioned container that fills its parent:
<div> carries the inline CSS transition for opacity and transform using transition.duration. When targetState changes:
exitingis set totrue— the inner div switches totransition.exitstyles.- After
transition.durationmilliseconds,currentKeyis updated to the new state andexitingresets tofalse, restoringtransition.enterstyles.
targetState (which in the slot content you control via {#if} or similar), the new UI is painted with the enter style as soon as the transition completes.
ContentTransition factory functions
All three factories are exported from@danielito1996/compose-svelted.
fade(duration?)
Crossfades between states using opacity only. Accepts an optional
duration in ms. Default 300 ms.scaleFade()
Combines a subtle scale (
0.95 → 1) with an opacity crossfade. Fixed duration 220 ms.slideHorizontal()
Slides the outgoing content to the left (
translateX(-100%)) while the incoming content fades in at its natural position. Fixed duration 300 ms.ContentTransition type reference
Examples
Switching between two views
Default fade transition
Horizontal slide (navigation-style)
Extended fade with custom duration
Usage with NavHost
NavHost uses AnimatedContent internally to animate transitions between registered screens. You do not need to wrap NavHost in AnimatedContent yourself — the transition is already applied. You can however configure which ContentTransition NavHost uses by passing a transition prop.