Toggle theme

Animation🔗

To apply animation to your application you can use three different strategies based on your needs and requirements.

Disclaimer: There are currently no official UX/design guidelines on how to apply animation or motion in our web applications. Once there are, we should be able to expose things like duration and easing in our theme configurations.

CSS transitions🔗

The easiest way to apply animation is by simply using the CSS transition property.

Let's explore a more elaborate example with a button that toggles the opacity of a component:

CSS Keyframe animations🔗

For more complex animation requirements you can utilise CSS @keyframes. In VCC UI this works by passing a keyframe object to the property. You can use all other props like would normally do.

Animating change in state🔗

Sometimes you want animate adding and removing to a list of items in your application state. This can be tricky because React will typically render the DOM before you get the chance to apply any transitions. To solve this you can use the package.

The Transition component lets you describe a transition from one component state to another over time with a simple declarative API. Most commonly it's used to animate the mounting and unmounting of a component, but can also be used to describe in-place transition states as well.

Inside the Transition component we can access a render prop that gives us the current state of the transition: entered, entering, exiting and exited. We can create a function that returns a style object describing what an item should render like in a given state.

This will create a bouncy zoom in effect on "entering", and a zoom out effect on "exiting".

Here's a simple application using the function together with the and components:

The above example simply renders a list of cards from an array with numbers. The add button adds a new item to the end of the array. The remove button removes the last item from the array.

CSS Reflow hack🔗

A key thing to notice here is the function which calls the property. We have to do this to force a repaint/reflow so that the browser applies the exited transition state before applying the entering state. This is a known limiation and hack when using react-transition-group and CSS-in-JS libraries

2022 © Volvo Car Corporation