Defaults
Set a default once instead of passing the same prop or parameter to every
component and call. A prop or parameter you pass wins over
provideAnimeDefaults(), which wins over app.config.ts, then the
preset, then the built-in value.
Set app-wide defaults
export default defineAppConfig({
nanime: {
components: {
transition: { animation: 'slide-up', mode: 'out-in' },
transitionGroup: { animation: 'swap', moveAnimation: { duration: 600, ease: 'out(4)' } },
layoutGroup: { layoutOptions: { duration: 500 } },
},
composables: {
animate: { duration: 500, ease: 'out(3)' },
draggable: { releaseEase: 'out(3)', dragSpeed: 2 },
},
},
})
What can be a default
| Entry | Props that can be defaults | Built-in value when unset |
|---|---|---|
components.transition | waapi, animation, enterAnimation, leaveAnimation, mode, appear, completeOnTabHidden | fade (enter 300ms, leave 200ms), mode: 'default', appear: false |
components.transitionGroup | tag, waapi, animation, enterAnimation, leaveAnimation, moveAnimation, appear, absoluteLeave, shallow, completeOnTabHidden | enter 250ms with out(3), leave 150ms with in(3), move 350ms with out(3), tag: 'div', absoluteLeave: true |
components.layoutGroup | tag, shallow, layoutOptions, elements (selector string or list of strings), completeOnTabHidden | spring({ bounce: 0.15, duration: 300 }), tag: 'div' |
composables.animate | any AnimationParams | none |
composables.draggable | any DraggableParams except trigger and container | none |
deps cannot be a default, because every group watches different values.
Element refs and component instances exist only inside a component, so
they cannot be defaults either.
A composable parameter passed as undefined keeps the default, as it does
in AnimeJS, so { duration: props.duration } works when the prop is not
set.
Scope defaults to part of the app
Use provideAnimeDefaults() when one part of the app needs different
defaults from the rest.
<script setup lang="ts">
provideAnimeDefaults({
transition: { animation: 'scale' },
composables: { animate: { duration: 300 } },
rebuild: 'keepTime',
})
</script>
| Key | Type | Notes |
|---|---|---|
transition, transitionGroup, layoutGroup | same as the components entries | Replaces the same entry from a parent component's call, so repeat any of the parent's keys you still need, such as mode. |
composables | { animate?, draggable? } | animate and draggable each replace the same entry from a parent component's call. |
preset | AnimationPreset | Replaces the app-wide preset for the components and composables inside. |
rebuild | 'restart', 'keepTime' or 'keepValue' | Default rebuild for useAnimate, useScrambleText and useAnimeTimeline inside. 'keepValue' applies to useAnimate only, and the other two composables use 'restart' instead. |
The argument can also be a ref or a getter. A key passed as undefined,
such as transition: undefined, keeps the value from a parent component's
call.
transitions and reducedMotion can only be set app-wide, so
provideAnimeDefaults() does not accept them.