Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit 7ca4347

Browse files
committed
chore(docs): improves docs
1 parent 1d31e94 commit 7ca4347

8 files changed

Lines changed: 86 additions & 74 deletions

File tree

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# yubaba 🧙✨
22

3-
/juːba:ba/ out of the box animated experiences for React.js 🧙✨
3+
/juːba:ba/ out of the box animated experiences for [React.js](https://reactjs.org/) 🧙✨
44

55
[![npm](https://img.shields.io/npm/v/yubaba.svg)](https://www.npmjs.com/package/yubaba) [![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/yubaba.svg)](https://bundlephobia.com/result?p=yubaba)
66

@@ -35,17 +35,15 @@ or
3535
yarn add yubaba react@^16.4.x react-dom@^16.4.x emotion@^10.x.x
3636
```
3737

38-
### Usage
39-
40-
[Function as children](https://reactpatterns.com/#function-as-children) is a common pattern in `yubaba`!
41-
Here's the most basic usage which will animate between `small` and `large`:
38+
[Function as children](https://reactpatterns.com/#function-as-children) is a common pattern here.
39+
The most basic usage could animate an element between `small` and `large` states.
4240

4341
```js
4442
import Baba, { Move } from 'yubaba';
4543

4644
({ isLarge }) => (
4745
<Baba name="my-first-baba" key={isLarge}>
48-
{baba => <div {...baba} className={isLarge ? 'large' : 'small'} />}
46+
<Move>{baba => <div {...baba} className={isLarge ? 'large' : 'small'} />}</Move>
4947
</Baba>
5048
);
5149
```

packages/yubaba/src/Baba/__docs__/docs.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import Baba from '../index';
88

99
# Baba
1010

11-
This is the primary component in yubaba.
12-
When rendering it will be given all of the animation data from its children.
11+
This is the brains component.
1312
When unmounting or flipping the `in` prop from `true` to `false`,
14-
it will execute all the animations **top to bottom** if a matching Baba pair is found within `50ms`.
13+
it will execute all the animations **top to bottom** if a matching Baba pair (either itself or another Baba element) is found within `50ms`.
1514

1615
> **Tip -** See [Getting started](/getting-started) for more information on how to use this component.
1716

packages/yubaba/src/BabaManager/__docs__/docs.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
name: BabaManager
33
route: /baba-manager
4+
menu: Utility helpers
45
---
56

67
import { Playground, PropsTable } from 'docz';

packages/yubaba/src/__docs__/1-introduction/docs.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ or
4242
yarn add yubaba react@^16.4.x react-dom@^16.4.x emotion@^10.x.x
4343
```
4444

45-
### Usage
46-
47-
[Function as children](https://reactpatterns.com/#function-as-children) is a common pattern in `yubaba`!
48-
Here's the most basic usage which will animate between `small` and `large`.:
45+
[Function as children](https://reactpatterns.com/#function-as-children) is a common pattern here.
46+
The most basic usage could animate an element between `small` and `large` states.
4947

5048
```js
5149
import Baba, { Move } from 'yubaba';
5250

5351
({ isLarge }) => (
5452
<Baba name="my-first-baba" key={isLarge}>
55-
{baba => <div {...baba} className={isLarge ? 'large' : 'small'} />}
53+
<Move>{baba => <div {...baba} className={isLarge ? 'large' : 'small'} />}</Move>
5654
</Baba>
5755
);
5856
```

packages/yubaba/src/__docs__/2-getting-started/docs.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,9 @@ To do that we can abuse how `key`'s work in react - we just update the key at th
175175
</Styled.Container>
176176
</Playground>
177177

178-
> **Tip -** You may be thinking why not just use regular CSS transitions for this?
179-
> Well under the hood that's what `yubaba` is using!
180-
> Using `yubaba` you can animate between different css `position`s,
181-
> the above goes from `static` to `fixed` while increasing in size - and it works with very little effort!
178+
> **Tip -** The beauty of using `yubaba` is that all the animations are dynamic.
179+
> Elements can be positioned in an infinite amount of states and we can animate between them all -
180+
> no hard coding.
182181
183182
## Moving to another distinct element
184183

packages/yubaba/src/__docs__/3-advanced-usage/docs.mdx

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,24 @@ import EmailChain from './EmailChain';
4141

4242
## Controlling in what order animations should execute
4343

44+
> **Tip -** Animations have three phases,
45+
> `beforeAnimate`,
46+
> `animate` and `afterAnimate`.
47+
> Don't worry if you're confused we will go over them in detail in [Custom Animations](/custom-animations).
48+
4449
Animations are executed from top to bottom.
4550
The parent-most animation will be executed first and then continue execution inwards.
4651

4752
So if we had two animations, Move and CrossFade:
4853

4954
```js
50-
<Baba name="move-first">
51-
<Move>
52-
<CrossFade>{props => <div {...props} />}</CrossFade>
53-
</Move>
54-
</Baba>
55+
() => (
56+
<Baba name="move-first">
57+
<Move>
58+
<CrossFade>{props => <div {...props} />}</CrossFade>
59+
</Move>
60+
</Baba>
61+
);
5562
```
5663

5764
When executed the order would look like:
@@ -68,11 +75,13 @@ When executed the order would look like:
6875
If we placed CrossFade first:
6976

7077
```js
71-
<Baba name="cross-fade-first">
72-
<CrossFade>
73-
<Move>{props => <div {...props} />}</Move>
74-
</CrossFade>
75-
</Baba>
78+
() => (
79+
<Baba name="cross-fade-first">
80+
<CrossFade>
81+
<Move>{props => <div {...props} />}</Move>
82+
</CrossFade>
83+
</Baba>
84+
);
7685
```
7786

7887
Then their order would be inversed:
@@ -95,13 +104,15 @@ if we introduce the Wait component:
95104
```js
96105
import { Wait } from 'yubaba';
97106

98-
<Baba name="wait">
99-
<CrossFade>
100-
<Wait>
101-
<Move>{props => <div {...props} />}</Move>
102-
</Wait>
103-
</CrossFade>
104-
</Baba>;
107+
() => (
108+
<Baba name="wait">
109+
<CrossFade>
110+
<Wait>
111+
<Move>{props => <div {...props} />}</Move>
112+
</Wait>
113+
</CrossFade>
114+
</Baba>
115+
);
105116
```
106117

107118
Then the Move animation will wait for the CrossFade animation to complete finish before starting,
@@ -125,19 +136,21 @@ Make it a parent of any [Baba](/baba) and it will show its content only when the
125136
```js
126137
import { BabaManager } from 'yubaba';
127138

128-
<BabaManager>
129-
{manager => (
130-
<div>
131-
<Baba name="hide-children-until-animations-have-finished">
132-
<CrossFade>
133-
<Move>{props => <div {...props} />}</Move>
134-
</CrossFade>
135-
</Baba>
136-
137-
<span {...manager}>Children content</span>
138-
</div>
139-
)}
140-
</BabaManager>;
139+
() => (
140+
<BabaManager>
141+
{manager => (
142+
<div>
143+
<Baba name="hide-children-until-animations-have-finished">
144+
<CrossFade>
145+
<Move>{props => <div {...props} />}</Move>
146+
</CrossFade>
147+
</Baba>
148+
149+
<span {...manager}>Children content</span>
150+
</div>
151+
)}
152+
</BabaManager>
153+
);
141154
```
142155

143156
Children content will be shown after **all** animations have completed.

packages/yubaba/src/__docs__/4-custom-animations/SupportingAnimation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class SupportingAnimation extends React.Component<CollectorChildr
3838
left: 0,
3939
right: 0,
4040
bottom: 0,
41-
backgroundColor: 'black',
41+
backgroundColor: '#468cee',
4242
zIndex: 9999999,
4343
transform: 'none',
4444
transition: 'transform 400ms',

packages/yubaba/src/__docs__/4-custom-animations/docs.mdx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ import * as Styled from './styled';
1414

1515
# Custom animations
1616

17-
Everything is a custom animation in `yubaba` - all animations available out of the box will use the same methods to make them as you will.
18-
There are two types of animations you can build with `yubaba`.
17+
Everything is a custom animation in `yubaba` -
18+
all animations that come with `yubaba` are built in exactly the same way you will build yours.
1919

2020
## Lifecyle of an animation
2121

22-
There are three lifecycles of an animation which you will see in the next few examples.
22+
There are three phases of an animation:
2323

24-
1. `beforeAnimate()` - useful for prepping any animations or elements.
25-
2. `animate()` - primary step for an animation.
26-
3. `afterAnimate()` - useful for performing any extra animations after all primary animations have completed.
24+
1. `beforeAnimate()` used for any initial work needed for an animation, e.g. moving the destination ontop of the origin
25+
2. `animate()` used for the primary animation, e.g. moving from origin to destination
26+
3. `afterAnimate()` used for any supplementary post-animation animation, e.g. fading out
2727

28-
Each lifecyle method has the same type signature:
28+
<br />
29+
30+
Each phase method has the same type signature:
2931

3032
```js
3133
(elements, onFinish, setChildProps) => JSX.Element | void;
3234
```
3335

3436
> **Tip -** Notice you can return JSX elements.
35-
> If you do it will be created for that lifecycle - and reconciled from the result of every following lifecycle.
36-
> This means if you return JSX elements in `beforeAnimate()`, but not in `animate()` or `afterAnimate()` - it will be removed!
37+
> If you do it will be created for that phase - and reconciled from the result of the following phases.
38+
> This means if you return JSX elements in `beforeAnimate()` but not in `animate()` or `afterAnimate()` it will be removed!
3739
38-
### elements
40+
### What is `elements`
3941

4042
This contains snapshot data for the origin and destination elements.
4143
Use this for doing any dynamic calculation for your animation.
4244

45+
> **Tip -** Notice there is a `render` property in origin and destination -
46+
> this is the render prop that consumers pass through which you can use to create the same element if needed!
47+
4348
```js
4449
{
4550
origin: {
@@ -59,16 +64,15 @@ Use this for doing any dynamic calculation for your animation.
5964
}
6065
```
6166

62-
> **Tip -** You'll notice there is a `render` prop in there - this is the render prop
63-
> that consumers pass through which you can use to create the same element if needed!
64-
> You can also use the destination `element` to set style/classNames directly if needing that extra perf boost.
67+
> **Tip -** You can use the destination `element` to set style/classNames directly for better performance -
68+
> but remember you'll be doing it outside of the React lifecycle.
6569
66-
### onFinish() arg
70+
### What is `onFinish()`
6771

68-
Call this method when you've completed the lifecycle.
69-
Animations will not continue to the next stage until all animations finish the current lifecycle.
72+
Call this method when you've completed the phase.
73+
Animations will not continue to the next stage until all animations finish the current phase.
7074

71-
### setChildProps() arg
75+
### What is `setChildProps()`
7276

7377
This will set the wrapped child props.
7478

@@ -81,7 +85,7 @@ setChildProps({
8185

8286
## Focal animations
8387

84-
The first is a focal animation - which means animating the wrapped element.
88+
The first is a [focal animation](/focal-animations).
8589
We are going to make a custom animation that makes the target element _do one full 360deg rotation_.
8690

8791
```js
@@ -177,7 +181,7 @@ export default class OneFullRotation extends Component {
177181
178182
### Composing animations
179183

180-
Another amazing feature of `yubaba` is the ability to compose animations - with a small change we can compose the two.
184+
Composability is a primary feature of `yubaba` - with a small change we can compose the two animations together.
181185
If we introduce [Move](/move) we can make the element rotate and move to the new destination.
182186

183187
```diff
@@ -221,11 +225,11 @@ beforeAnimate = (elements, onFinish, setChildProps) => {
221225

222226
## Supporting animations
223227

224-
Sometimes we want _extra_ things to happen during an animation,
228+
Sometimes we want to [support the primary focal animation](/supporting-animation),
225229
for example the [Swipe](/swipe) animation creates a new element that swipes over the screen.
226230

227231
This is different to a regular focal animation because it _creates_ new elements through the animation lifecycle.
228-
We can do this by _returning elements_ from the animation lifecycle methods.
232+
We can do this by _returning elements_ from an animation phase.
229233

230234
For this example let's make something similar to swipe except it starts from the middle of the screen.
231235

@@ -249,7 +253,7 @@ export default class SupportingAnimation extends React.Component {
249253
left: 0,
250254
right: 0,
251255
bottom: 0,
252-
backgroundColor: 'black',
256+
backgroundColor: '#468cee',
253257
zIndex: 9999999,
254258
transform: 'scaleX(0)',
255259
}}
@@ -271,7 +275,7 @@ export default class SupportingAnimation extends React.Component {
271275
left: 0,
272276
right: 0,
273277
bottom: 0,
274-
backgroundColor: 'black',
278+
backgroundColor: '#468cee',
275279
zIndex: 9999999,
276280
transform: 'none',
277281
transition: 'transform 400ms',
@@ -284,7 +288,7 @@ export default class SupportingAnimation extends React.Component {
284288
setTimeout(onFinish, 200);
285289

286290
// After animations have finished we "fade out" the supplementary animation.
287-
// It will be cleaned up (removed) after this lifecycle event.
291+
// It will be cleaned up (removed) after this phase.
288292
return (
289293
<div
290294
aria-hidden="true"
@@ -294,7 +298,7 @@ export default class SupportingAnimation extends React.Component {
294298
left: 0,
295299
right: 0,
296300
bottom: 0,
297-
backgroundColor: 'black',
301+
backgroundColor: '#468cee',
298302
zIndex: 9999999,
299303
transform: 'none',
300304
transition: 'opacity 200ms',

0 commit comments

Comments
 (0)