Skip to content

Commit 702d098

Browse files
committed
docs: update readme, add useSwitchTransition doc, add more examples
1 parent 4b629f8 commit 702d098

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,41 @@
1616

1717
<p align="center">
1818
<a href="https://tqgdj.csb.app/">
19-
<img src="./example.gif" width="400" alt="example">
19+
<img src="./example.gif" width="300" alt="example">
2020
</a>
2121
<br>
2222
<a href="https://tqgdj.csb.app/">See Example</a> |
2323
<a href="https://codesandbox.io/s/transition-hook-example-tqgdj">See Example in Codesandbox</a>
2424
</p>
25+
<p align="center">
26+
<a href="https://o3f41.csb.app/basic">
27+
<img src="./gifs/basic.gif" height="150" alt="example">
28+
</a>
29+
<a href="https://o3f41.csb.app/emoji-switch-transition">
30+
<img src="./gifs/emoji-switch-transition.gif" height="150" alt="example">
31+
</a>
32+
</p>
33+
<p align="center">
34+
<a href="https://o3f41.csb.app/basic-switch-transition">
35+
<img src="./gifs/basic-switch-transition.gif" height="200" alt="example">
36+
</a>
37+
<a href="https://o3f41.csb.app/transition-with-key">
38+
<img src="./gifs/transition-with-key.gif" height="200" alt="example">
39+
</a>
40+
</p>
41+
<p align="center">
42+
<a href="https://codesandbox.io/s/transition-hook-examples-o3f41">See More Examples in Codesandbox</a>
43+
</p>
2544
<br>
2645

2746
- [Installation](#installation)
2847
- [Usage](#usage)
2948
- [useTransition](#usetransition)
49+
- [useSwitchTransition](#useswitchtransition)
3050
- [Transition](#transition)
3151
- [API Reference](#api-reference)
3252
- [useTransition(state, timeout)](#usetransitionstate-timeout)
53+
- [useSwitchTransition(state, timeout, mode)](#useswitchtransitionstate-timeout-mode)
3354
- [Transition](#transition-1)
3455
- [License](#license)
3556

@@ -51,7 +72,7 @@ npm install transition-hook --save
5172

5273
### useTransition
5374

54-
This hook transform a boolean state into transition stage('from' | 'enter' | 'leave'), and unmount the component after timeout.
75+
This hook transforms a boolean state into transition stage('from' | 'enter' | 'leave'), and unmount the component after timeout.
5576

5677
```jsx
5778
const [onOff, setOnOff] = useState(true)
@@ -70,6 +91,30 @@ return <div>
7091
</div>
7192
```
7293
94+
### useSwitchTransition
95+
96+
This hook transforms when the state changes.
97+
98+
```jsx
99+
const [count, setCount] = useState(0)
100+
const transition = useSwitchTransition(count, 300, 'default') // (state, timeout, mode)
101+
102+
return <div>
103+
<button onClick={()=>setCount(count+1)}>add</button>
104+
{transition((state, stage)=>(
105+
<p style={{
106+
transition: '.3s',
107+
opacity: stage === 'enter' ? 1 : 0,
108+
transform: {
109+
from: 'translateX(-100%)',
110+
enter: 'translateX(0%)',
111+
leave: 'translateX(100%)',
112+
}[stage]
113+
}}>{state}</p>
114+
))}
115+
</div>
116+
```
117+
73118
### Transition
74119
75120
If you prefer FaCC pattern usage, there it is!
@@ -112,6 +157,18 @@ return <div>
112157
| `stage` | Stage: `from` \| `enter` \| `leave` | Use three different stage to perform your animation |
113158
| `shouldMount` | `boolean` | Whether the component should be mounted |
114159

160+
### useSwitchTransition(state, timeout, mode)
161+
162+
```js
163+
const transition = useSwitchTransition(onOff, 300, default)
164+
```
165+
166+
| Parameters | Type | Description |
167+
| :--------- | :--------------------------------- | :------------------------------------------------------------ |
168+
| `state` | `any` | **Required**. Your state, which triggers animation |
169+
| `timeout` | `number` | **Required**. How long before the animation ends and unmounts |
170+
| `mode` | `default` \| `out-in` \| `int-out` | **Optional**. Default to `default` mode |
171+
115172
### Transition
116173

117174
```jsx

gifs/basic-switch-transition.gif

524 KB
Loading

gifs/basic.gif

692 KB
Loading

gifs/emoji-switch-transition.gif

550 KB
Loading

gifs/emoji-transition.gif

387 KB
Loading

gifs/transition-with-key.gif

149 KB
Loading

0 commit comments

Comments
 (0)