Presets
A preset bundles transition styles, component defaults and composable defaults into one object, so the motion of an app comes from one place.
Pick a built-in preset
The <AnimeTransition> box (a scale transition) and the useAnimate() box
toggle every few seconds, and picking a preset toggles them immediately. Drag
the useDraggable() box to feel its release physics.
| Preset | Motion | Enter / leave (slide, scale, list) | Easing |
|---|---|---|---|
nanime/presets/formal | Calm and precise, no overshoot | 150ms / 110ms | IBM Carbon productive curves |
nanime/presets/elegant | Soft and unhurried, no overshoot | 400ms / 280ms | IBM Carbon expressive curves |
nanime/presets/playful | Bouncy, overshoots about 10% on the way in | spring / 180ms | spring(), with in(3) for exits |
fade, the default for <AnimeTransition>, is shorter than the other styles in
every preset and never overshoots.
Each preset redefines the built-in style names (fade, slide-up,
slide-down, slide-left, slide-right, scale, swap) with its own
timing, and adds a list style that <AnimeTransitionGroup> uses by
default. Each preset also sets the timing of <AnimeLayoutGroup>, the defaults of
useAnimate() and the release physics of useDraggable().
| Value | formal | elegant | playful |
|---|---|---|---|
| Slide distance | 8px | 12px | 20px |
scale starts at | 0.96 | 0.97 | 0.85 |
fade enter / leave | 110ms / 70ms | 300ms / 240ms | 200ms / 150ms |
| Moves and layout | 240ms | 500ms | spring |
useAnimate() | 240ms | 400ms | 400ms |
useDraggable() release | stiffness 300, damping 34 | stiffness 100, damping 20 | stiffness 200, damping 28 |
Each preset exports its easings by name: standard, entrance and exit from
formal, glide and settle from elegant, and pop and bounce from
playful. Pass one to any animation:
import { entrance } from 'nanime/presets/formal'
useAnimate(box, { x: 120, ease: entrance })
Set a preset for the whole app
Pass the imported preset object to nanime.preset in app.config.ts, not a
preset name:
import formal from 'nanime/presets/formal'
export default defineAppConfig({
nanime: {
preset: formal,
},
})
Component props, provideAnimeDefaults() and the rest of app.config.ts
win over the preset. The preset wins over the built-in defaults.
Write a preset
Write your own when none of the built-in presets fits.
| Key | Holds | Required |
|---|---|---|
shared | Named transition styles the preset adds, in the same shape as nanime.transitions. | No |
components | Default props for transition, transitionGroup and layoutGroup. | Yes |
composables | Default parameters for animate and draggable. | Yes |
composables can be an empty object. components needs all three entries,
and each can be an empty object.
export default defineAppConfig({
nanime: {
preset: {
shared: {
pop: {
enter: { opacity: [0, 1], scale: [0.4, 1], duration: 240, ease: 'outBack(3)' },
leave: { opacity: 0, scale: 0.4, duration: 140, ease: 'in(3)' },
move: { duration: 200, ease: 'out(3)' },
},
},
components: {
transition: { animation: 'pop' },
transitionGroup: { animation: 'pop' },
layoutGroup: { layoutOptions: { duration: 400, ease: 'out(3)' } },
},
composables: {
animate: { duration: 400, ease: 'out(3)' },
draggable: { releaseEase: 'out(3)' },
},
},
},
})
The names in shared work in the animation props of
the components, the same as a style from
app.config.ts.
A style name is looked up in nanime.transitions first, then in the preset's
shared styles, then in the built-in styles. enter-animation and
leave-animation each look up their own name, so
<AnimeTransition enter-animation="pop" leave-animation="fade"> takes pop
from the preset and fade from wherever fade is defined.
Scope a preset to part of the app
Use provideAnimeDefaults({ preset }) when one part of the app needs a
different preset. It replaces the app-wide preset, and any preset from a
parent component's call, for everything inside the calling component.
<script setup lang="ts">
import playful from 'nanime/presets/playful'
provideAnimeDefaults({ preset: playful })
</script>