|
3 | 3 | </p> |
4 | 4 |
|
5 | 5 | <br /> |
6 | | -<h1 align="center">📦 qhlab-library-template</h1> |
| 6 | +<h1 align="center">🎁 qhlab-library-template</h1> |
7 | 7 |
|
8 | 8 | <p align="center"> |
9 | 9 | <a href="https://github.com/iamyoki/transition-hook/actions/workflows/test.yml"><img src="https://github.com/iamyoki/transition-hook/actions/workflows/test.yml/badge.svg" alt="🧪 Run Tests"></a> |
|
16 | 16 | </a> |
17 | 17 | </p> |
18 | 18 |
|
19 | | -<p align="center">An extremely light-weight<strong>(1kb)</strong> react transition animation hook which is simpler and easier to use than <a href="https://github.com/reactjs/react-transition-group" target="_blank">react-transition-group</a></p> |
20 | 19 | <br> |
21 | | -<p align="center">!!!(This template is forked from transition-hook, edit your own content later on)</p> |
22 | | - |
23 | | -<p align="center"> |
24 | | - <a href="https://o3f41.csb.app/ripple-effect"> |
25 | | - <img src="./gifs/ripple-effect.gif" height="150" alt="example"> |
26 | | - </a> |
27 | | - <a href="https://o3f41.csb.app/emoji-switch-transition"> |
28 | | - <img src="./gifs/emoji-switch-transition.gif" height="150" alt="example"> |
29 | | - </a> |
30 | | -</p> |
31 | | - |
32 | | -<p align="center"> |
33 | | - <a href="https://o3f41.csb.app/radio-transition"> |
34 | | - <img src="./gifs/radio-transition.gif" height="150" alt="example"> |
35 | | - </a> |
36 | | - <a href="https://o3f41.csb.app/painter"> |
37 | | - <img src="./gifs/painter.gif" height="150" alt="example"> |
38 | | - </a> |
39 | | -</p> |
40 | | - |
41 | | -<p align="center"> |
42 | | - <a href="https://o3f41.csb.app/basic"> |
43 | | - <img src="./gifs/basic.gif" height="120" alt="example"> |
44 | | - </a> |
45 | | - <a href="https://o3f41.csb.app/basic-switch-transition"> |
46 | | - <img src="./gifs/basic-switch-transition.gif" height="120" alt="example"> |
47 | | - </a> |
48 | | - <a href="https://o3f41.csb.app/transition-with-key"> |
49 | | - <img src="./gifs/transition-with-key.gif" height="120" alt="example"> |
50 | | - </a> |
51 | | -</p> |
52 | | - |
53 | | -<p align="center"> |
54 | | - <a href="https://codesandbox.io/s/transition-hook-examples-o3f41">See More Examples in Codesandbox</a> |
55 | | -</p> |
| 20 | +<p align="center"><strong>A template make make open-source library never been so easy.</strong></p> |
56 | 21 | <br> |
57 | 22 |
|
58 | 23 | - [Installation](#installation) |
59 | 24 | - [Usage](#usage) |
60 | | - - [useTransition](#usetransition) |
61 | | - - [useSwitchTransition](#useswitchtransition) |
62 | | - - [Transition](#transition) |
63 | | - - [SwitchTransition](#switchtransition) |
64 | 25 | - [API Reference](#api-reference) |
65 | | - - [useTransition(state, timeout)](#usetransitionstate-timeout) |
66 | | - - [useSwitchTransition(state, timeout, mode)](#useswitchtransitionstate-timeout-mode) |
67 | | - - [Transition](#transition-1) |
68 | | - - [SwitchTransition](#switchtransition-1) |
69 | 26 | - [License](#license) |
70 | 27 |
|
71 | 28 | ## Installation |
72 | 29 |
|
73 | 30 | Install with yarn |
74 | 31 |
|
75 | 32 | ```bash |
76 | | -yarn add transition-hook |
| 33 | +yarn add qhlab-library-template |
77 | 34 | ``` |
78 | 35 |
|
79 | 36 | Or install with npm |
80 | 37 |
|
81 | 38 | ```bash |
82 | | -npm install transition-hook --save |
| 39 | +npm install qhlab-library-template --save |
83 | 40 | ``` |
84 | 41 |
|
85 | 42 | ## Usage |
86 | 43 |
|
87 | | -### useTransition |
88 | | - |
89 | | -This hook transforms a boolean state into transition stage('from' | 'enter' | 'leave'), and unmount the component after timeout. |
90 | | - |
91 | | -```jsx |
92 | | -const [onOff, setOnOff] = useState(true) |
93 | | -const {stage, shouldMount} = useTransition(onOff, 300) // (state, timeout) |
94 | | - |
95 | | -return <div> |
96 | | - <button onClick={()=>setOnOff(!onOff)}>toggle</button> |
97 | | - {shouldMount && ( |
98 | | - <p style={{ |
99 | | - transition: '.3s', |
100 | | - opacity: stage === 'enter' ? 1 : 0 |
101 | | - }}> |
102 | | - Hey guys, I'm fading |
103 | | - </p> |
104 | | - )} |
105 | | -</div> |
106 | | -``` |
107 | | -
|
108 | | -### useSwitchTransition |
109 | | -
|
110 | | -This hook transforms when the state changes. |
111 | | -
|
112 | | -```jsx |
113 | | -const [count, setCount] = useState(0) |
114 | | -const transition = useSwitchTransition(count, 300, 'default') // (state, timeout, mode) |
115 | | -
|
116 | | -return <div> |
117 | | - <button onClick={()=>setCount(count+1)}>add</button> |
118 | | - {transition((state, stage)=>( |
119 | | - <p style={{ |
120 | | - transition: '.3s', |
121 | | - opacity: stage === 'enter' ? 1 : 0, |
122 | | - transform: { |
123 | | - from: 'translateX(-100%)', |
124 | | - enter: 'translateX(0%)', |
125 | | - leave: 'translateX(100%)', |
126 | | - }[stage] |
127 | | - }}>{state}</p> |
128 | | - ))} |
129 | | -</div> |
130 | | -``` |
131 | | -
|
132 | | -### Transition |
133 | | -
|
134 | | -If you prefer FaCC pattern usage, there it is! |
135 | | -
|
136 | | -```jsx |
137 | | -const [onOff, setOnOff] = useState(true) |
138 | | -
|
139 | | -return <div> |
140 | | - <button onClick={()=>setOnOff(!onOff)}>toggle</button> |
141 | | - <Transition state={onOff} timeout={300}> |
142 | | - {(stage, shouldMount)=>shouldMount &&( |
143 | | - <p style={{ |
144 | | - transition: '.3s', |
145 | | - opacity: stage === 'enter' ? 1 : 0 |
146 | | - }}> |
147 | | - Hey guys, I'm fading |
148 | | - </p> |
149 | | - )} |
150 | | - </Transition> |
151 | | -</div> |
152 | | -``` |
153 | | - |
154 | | -### SwitchTransition |
155 | | - |
156 | | -FaCC pattern version of useSwitchTransition |
157 | | - |
158 | | -```jsx |
159 | | - <SwitchTransition state={count} timeout={300} mode='default'> |
160 | | - {(state, stage) => ( |
161 | | - <h1 |
162 | | - style={{ |
163 | | - transition: '.3s', |
164 | | - opacity: stage === 'enter' ? 1 : 0, |
165 | | - transform: { |
166 | | - from: 'translateX(-100%) scale(1.2)', |
167 | | - enter: 'translateX(0)', |
168 | | - leave: 'translateX(100%) scale(0)' |
169 | | - }[stage] |
170 | | - }}> |
171 | | - {state} {stage} hello |
172 | | - </h1> |
173 | | - )} |
174 | | - </SwitchTransition> |
175 | | -``` |
| 44 | +> Write some thing nice. |
176 | 45 |
|
177 | 46 | ## API Reference |
178 | 47 |
|
179 | | -### useTransition(state, timeout) |
180 | | - |
181 | | -```js |
182 | | - const {stage, shouldMount} = useTransition(onOff, 300) |
183 | | -``` |
184 | | - |
185 | | -| Parameters | Type | Description | |
186 | | -| :--------- | :-------- | :-------------------------------------------------------------------- | |
187 | | -| `state` | `boolean` | **Required**. Your boolean state, which controls animation in and out | |
188 | | -| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | |
189 | | - |
190 | | -<br> |
191 | | - |
192 | | -| Returns | Type | Description | |
193 | | -| :------------ | :---------------------------------- | :-------------------------------------------------- | |
194 | | -| `stage` | Stage: `from` \| `enter` \| `leave` | Use three different stage to perform your animation | |
195 | | -| `shouldMount` | `boolean` | Whether the component should be mounted | |
196 | | - |
197 | | -### useSwitchTransition(state, timeout, mode) |
198 | | - |
199 | | -```js |
200 | | - const transition = useSwitchTransition(onOff, 300, 'default') |
201 | | -``` |
202 | | - |
203 | | -| Parameters | Type | Description | |
204 | | -| :--------- | :-------------------------------- | :------------------------------------------------------------ | |
205 | | -| `state` | `any` | **Required**. Your state, which triggers animation | |
206 | | -| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | |
207 | | -| `mode` | `default` \| `out-in` \| `in-out` | **Optional**. Default to `default` mode | |
208 | | - |
209 | | -### Transition |
210 | | - |
211 | | -```jsx |
212 | | - <Transition state={onOff} timeout={300}> |
213 | | - {(stage, shouldMount) => shouldMount && <div style={{...}}>hello</div>} |
214 | | - </Transition> |
215 | | -``` |
216 | | - |
217 | | -| Props | Type | Description | |
218 | | -| :--------- | :------------------------------------------------------ | :-------------------------------------------------------------------- | |
219 | | -| `state` | `boolean` | **Required**. Your boolean state, which controls animation in and out | |
220 | | -| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | |
221 | | -| `children` | `(stage: Stage, shouldMount: boolean)=>React.ReactNode` | **Required**. FaCC pattern. | |
222 | | - |
223 | | -### SwitchTransition |
224 | | - |
225 | | -```jsx |
226 | | - <SwitchTransition state={count} timeout={300}> |
227 | | - {(state, stage) => <div style={{...}}>{state} hello</div>} |
228 | | - </SwitchTransition> |
229 | | -``` |
230 | | - |
231 | | -| Props | Type | Description | |
232 | | -| :--------- | :-------------------------------------------- | :-------------------------------------------------------------------- | |
233 | | -| `state` | `any` | **Required**. Your boolean state, which controls animation in and out | |
234 | | -| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | |
235 | | -| `mode` | `default` \| `out-in` \| `in-out` | **Optional**. Default to `default` mode | |
236 | | -| `children` | `(state: any, stage: Stage)=>React.ReactNode` | **Required**. FaCC pattern. | |
| 48 | +> Write some thing nice. |
237 | 49 |
|
238 | 50 | ## License |
239 | 51 |
|
|
0 commit comments