Animate in

Any view, layout or component can animate itself in and out. Give its class an animations field:

animations = {
  in: {
    from: { opacity: 0, transform: 'translateY(12px)' },
    to: { opacity: 1, transform: 'translateY(0)' },
    duration: 260,
    easing: 'ease-out',
  },
};

in plays when the component is added to the page. from and to are keyframes of CSS properties, duration and an optional delay are milliseconds, and easing is any CSS easing. Puzzle runs it with the browser's Web Animations API on the component's root element, the row's <li>.

When the animation finishes, Puzzle lets go of it and the stylesheet takes over again. So to must be how the element looks at rest, or it snaps at the end.

The playlist rows are now a PlaylistRow component with a Remove button, wired with a callback prop like the card in 6.2. The fixtures start three albums in the playlist, so there are rows to watch.

Your turn

  1. Add the in animation above to PlaylistRow.pzl.
  2. Press reload in the preview's address bar: the rows rise into place. Add an album in the shop and come back to see it again.

Visitors who ask their system for reduced motion get every duration set to zero. The rows still appear, and nothing moves.

Chapters