File size: 1,730 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
---
title: Animation
description: Using CSS animations to animate Chakra UI components
---
We recommend using CSS animations to animate your Chakra UI components. This
approach is performant, straightforward and provides a lot of flexibility.
You can animate both the mounting and unmounting phases of your components with
better control.
## Enter animation
When a disclosure component (popover, dialog) is open, the `data-state`
attribute is set to `open`. This maps to `data-state=open` and can be styled
with `_open` pseudo prop.
```tsx
<Box
data-state="open"
_open={{
animation: "fade-in 300ms ease-out",
}}
>
This is open
</Box>
```
Here's an example that uses keyframes to create a fade-in animation:
```css
@keyframes fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
```
## Exit animation
When a disclosure component (popover, dialog) is closed, the `data-state`
attribute is set to `closed`. This maps to `data-state=closed` and can be styled
with `_closed` pseudo prop.
```tsx
<Box
data-state="closed"
_closed={{
animation: "fadeOut 300ms ease-in",
}}
>
This is closed
</Box>
```
Here's an example that uses keyframes to create a fade-out animation:
```css
@keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
```
## Composing animations
Use the `animationName` prop to compose multiple animations together. This makes
it easy to create complex animations with multiple keyframes.
```tsx
<Box
data-state="open"
_open={{
animationName: "fade-in, scale-in",
animationDuration: "300ms",
}}
_closed={{
animationName: "fade-out, scale-out",
animationDuration: "120ms",
}}
>
This is a composed animation
</Box>
```
|