Skip to content

Commit 85f8fe7

Browse files
committed
add animation docs
1 parent 7ce1fd6 commit 85f8fe7

File tree

7 files changed

+133
-13
lines changed

7 files changed

+133
-13
lines changed

Diff for: src/content/reference/css/audio.md renamed to src/content/reference/animations/audio.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Audio
33
layout: API
44
---
55

6-
Plays audio in certain situations. This property is unique to React Unity and does not exist in web CSS.
6+
Plays audio in certain situations. This property is unique to React Unity and does not exist in standard CSS.
77

88
The property must have the format `<url> <delay> <iteration-count | infinite>`
99
- Example: `url(res:click) 400ms 1` - Meaning to play the resource named `click` after 400ms delay once

Diff for: src/content/reference/animations/enter-leave.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Enter/Leave Animations
3+
layout: API
4+
---
5+
6+
The CSS `:enter` and `:leave` pseudo selectors can be used with the `transition` property to animate the insertion and removal of elements.
7+
8+
When an element is inserted into the DOM, the `:enter` pseudo-class is applied to it. When an element is removed from the DOM, the `:leave` pseudo-class is applied to it. The duration these classes are applied can be controlled with the `state-duration` property.
9+
10+
<Sandpack>
11+
12+
```js
13+
export default function App() {
14+
const [count, setCount] = React.useState(0);
15+
16+
return <>
17+
<button onClick={() => setCount(x => x + 1)}>
18+
Add element
19+
</button>
20+
21+
<button onClick={() => setCount(x => x - 1)}>
22+
Remove element
23+
</button>
24+
25+
{Array.from({ length: count }).map((_, i) => (
26+
<view key={i} className="item">
27+
Element {i}
28+
</view>
29+
))}
30+
</>;
31+
}
32+
```
33+
34+
```css active
35+
:root {
36+
gap: 10px;
37+
}
38+
39+
.item {
40+
flex-direction: row;
41+
align-items: center;
42+
transition: all 0.5s;
43+
44+
state-duration: 0.5s;
45+
}
46+
47+
.item:enter {
48+
state-duration: 0s;
49+
translate: -100px 0;
50+
opacity: 0;
51+
}
52+
53+
.item:leave {
54+
translate: 100px 0;
55+
opacity: 0;
56+
}
57+
```
58+
59+
</Sandpack>

Diff for: src/content/reference/animations/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Animations
3+
layout: API
4+
---
5+
6+
There are several ways to animate elements in ReactUnity:
7+
8+
- With CSS `keyframes` and `animation` to create custom animations
9+
- With CSS `transition` property to animate changes in properties
10+
- With CSS `:enter` and `:leave` pseudo-classes with `transition` property to animate element insertion and removal
11+
- With CSS `motion` property to animate changes to rect transform
12+
- With CSS `audio` property to play audio clips

Diff for: src/content/reference/animations/motion.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Rect Transform Animations (motion)
3+
layout: API
4+
---
5+
6+
The `motion` property is used to animate changes to the rect transform of an element. This property is unique to React Unity and does not exist in standard CSS.
7+
8+
The property must have the format `<duration> <delay> <timing-function>`. The properties can also be set individually as `motion-duration`, `motion-delay`, and `motion-timing-function`.
9+
10+
<Sandpack>
11+
12+
```js
13+
export default function App() {
14+
const [big, setBig] = React.useState(false);
15+
16+
return <>
17+
Click the button to toggle its size
18+
<button onClick={() => setBig(x => !x)} style={{ width: big ? 300 : 'auto' }}>
19+
Click
20+
</button>
21+
</>;
22+
}
23+
```
24+
25+
```css active
26+
:root {
27+
align-items: flex-start;
28+
}
29+
30+
button, button :text {
31+
motion: 0.6s 0.1s ease-in-out;
32+
}
33+
```
34+
35+
</Sandpack>

Diff for: src/sidebarReference.json

+26-12
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,10 @@
103103
"title": "CSS Properties",
104104
"path": "/reference/css",
105105
"routes": [
106-
{
107-
"title": "Animation",
108-
"path": "/reference/css/animation"
109-
},
110106
{
111107
"title": "Appearance",
112108
"path": "/reference/css/appearance"
113109
},
114-
{
115-
"title": "Audio",
116-
"path": "/reference/css/audio"
117-
},
118110
{
119111
"title": "Background Color",
120112
"path": "/reference/css/background-color"
@@ -175,10 +167,6 @@
175167
"title": "Transform Origin",
176168
"path": "/reference/css/transform-origin"
177169
},
178-
{
179-
"title": "Transition",
180-
"path": "/reference/css/transition"
181-
},
182170
{
183171
"title": "Translate",
184172
"path": "/reference/css/translate"
@@ -193,6 +181,32 @@
193181
}
194182
]
195183
},
184+
{
185+
"title": "Animations",
186+
"path": "/reference/animations",
187+
"routes": [
188+
{
189+
"title": "CSS Keyframes",
190+
"path": "/reference/animations/animation"
191+
},
192+
{
193+
"title": "CSS Transition",
194+
"path": "/reference/animations/transition"
195+
},
196+
{
197+
"title": "Enter/Leave Animations",
198+
"path": "/reference/animations/enter-leave"
199+
},
200+
{
201+
"title": "Rect Transform Animations (motion)",
202+
"path": "/reference/animations/motion"
203+
},
204+
{
205+
"title": "Audio",
206+
"path": "/reference/animations/audio"
207+
}
208+
]
209+
},
196210
{
197211
"title": "CSS Media Queries",
198212
"path": "/reference/media-queries"

0 commit comments

Comments
 (0)