vael-ui v0.5.7

Directives

v-animate

Animates any element: in as it mounts, out as it leaves, to a new look when its values change, and to its new place when layout moves it. It plays on the same motion system as the components, so a ConfigProvider's spring, motion: false and reduced motion apply to it too. The Motion section covers it in depth, with examples for each case. It comes from vael-ui/motion; in a Vapor component, import vAnimateVapor from there instead (as vAnimate, or write v-animate-vapor).

Install

import { vAnimate } from 'vael-ui/motion'

Examples

  • Item 1
  • Item 2
  • Item 3

Names

The word after the colon, as in v-animate:rows, is a name. An element on its own doesn't need one. Name elements when they belong together: elements under one name that come in at the same time are one group, so stagger plays them one after another. Inside a vael-ui component, such as a Dialog, its motion.targets.rows sets how the elements named rows move, and they come and go with the component. after: 'rows' lets another element wait for them, and pages under one name can wait for each other with swap: 'wait'.

<li v-for="row in rows" >

Name: elements with the same name are one group, so stagger plays them one after another and after: 'rows' lets another element wait for them.

Add a name only when something else has to point at the element: a stagger group, after, or a component's motion.targets. Otherwise leave it off.

<!-- On its own: no name. -->
<p v-animate.rise>Saved</p>

<!-- One group: they come in one after another. -->
<li
  v-for="row in rows"
  :key="row.id"
  v-animate:rows.rise="{ stagger: true }"
>…</li>

<!-- In a component: they move with the dialog. -->
<Dialog :motion="{ targets: { rows: { initial: { y: 6 } } } }">
  <li v-for="row in rows" :key="row.id" v-animate:rows>…</li>
</Dialog>

Value

NameTypeDescription
stringstringThe name of a preset from the presets of a ConfigProvider motion style around it.
initialMotionValues | ((where) => MotionValues)Where it comes in from as it mounts: { opacity: 0, y: 8 }. It plays to its own style.
exitMotionValues | ((where) => MotionValues | false) | falseWhere it leaves to, inside a v-if or v-for. Unset, it leaves back the way it came, quicker. false leaves at once, and a function can return false to leave at once that time. On a spring, it carries on at the speed the element was moving: a card thrown with useDrag keeps going.
animateAnimateValuesA look it holds while bound, moving to each new one from wherever it is on screen: { rotate: open ? 180 : 0 }. Keyframe arrays play once per change, or loop with repeat. A getter or ref is followed every frame without re-rendering: { rotate: () => mapRange(drag.x.value, [-300, 300], [-20, 20]) }. { value: getter, spring } follows it on a spring instead, and spring: true uses the spring of the app.
spring / duration / easingSpringName | Spring / number | string / stringIts timing: a spring by name ('snappy', 'smooth', 'bouncy', 'gentle') or { damping, response }, or a duration in ms with any CSS easing or a token by name ('out', 'pop'). Unset, it uses the ConfigProvider's spring. A single value can carry its own: { y: { value: 8, duration: 200 } }.
delaynumberSeconds before it starts: its entrance, and a layout slide, which holds its old place meanwhile.
staggerboolean | 'end' | 'center' | 'edges' | 'random' | number | ((index, count) => number)Elements that share a name (v-animate:rows) come in one after another, in page order. true spaces them by the stagger token (40 ms); 'end', 'center' or 'edges' start the wave there, and 'random' shuffles the order. A number is the seconds between them; a function gives each its own start.
afterstring | string[]Starts after a moment in another named element's motion: 'summary', 'summary:start', 'summary:60%' or 'summary:settle'. Inside a component, or among elements that appear together.
stepsMotionStep[]A series of stops, each with its own to, timing and after moment.
replayunknownPlays initial again whenever this value changes, without remounting: a count going up, a failed copy.
appearboolean | 'later' | 'once'false: no entrance on mount; replay and its exit still play. 'later': no entrance for what's there at the first render, one for anything added after. 'once': a name's entrance plays once per page load, the first time the name has elements to show; rows that arrive in the next 600 ms join it, and later mounts under the name show without it. Default true.
layoutboolean | 'position'Slides to wherever layout puts it, such as when a list reorders or a sibling grows. 'position' moves it without resizing on the way.
layoutIdstringElements that share one are a single element moving between places: when one leaves and another arrives together, the newcomer slides from the old one's box.
states{ hover?, active?, focus? }Looks it holds while hovered (a mouse), pressed (pointer, Space or Enter) or focused, as a component's states: { hover: { scale: 1.03 }, active: { scale: 0.97 } }.
when'mount' | 'visible''visible' waits until it's scrolled into view, then plays once. Default 'mount'.
progressnumber | (() => number)With keyframe arrays in animate: holds them at this point, from 0 to 1, so a swipe or a scroll scrubs them.

Modifiers

NameTypeDescription
.fade / .rise / .drop / .pop / .blur—A built-in entrance: v-animate.rise. A value tunes it (v-animate.rise="{ delay: 0.1 }"), and your own presets work the same way once listed in MotionPresets.
.snappy / .smooth / .bouncy / .gentle—The spring it moves on: v-animate.pop.bouncy.
.stagger—With a name, stagger: true: v-animate:rows.rise.stagger.
:name—Names the element, as v-animate:rows: elements that share a name stagger together, after can wait for it, inside a component it marks one of the targets its motion animates, and pages under one name can wait for each other with swap: 'wait'. An element on its own needs no name.
.size—Eases the element to its content's new size instead of jumping. On its own (v-animate.size), it takes no value.