Skip to content

Commit b34250e

Browse files
authored
Merge pull request #7 from devrnt/chore/improve-example
chore: add animated example
2 parents e0b32d5 + 3ac1b06 commit b34250e

File tree

7 files changed

+185
-13
lines changed

7 files changed

+185
-13
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { motion } from 'framer-motion';
2+
import * as React from 'react';
3+
4+
const variants = {
5+
enter: {
6+
x: -1000,
7+
opacity: 0,
8+
},
9+
center: {
10+
zIndex: 1,
11+
x: 0,
12+
opacity: 1,
13+
},
14+
exit: {
15+
zIndex: 0,
16+
x: 1000,
17+
opacity: 0,
18+
},
19+
};
20+
21+
const AnimatedStep: React.FC = React.memo(({ children }) => {
22+
return (
23+
<motion.div
24+
variants={variants}
25+
initial="enter"
26+
animate="center"
27+
exit="exit"
28+
>
29+
{children}
30+
</motion.div>
31+
);
32+
});
33+
34+
export default AnimatedStep;

example/components/asyncStep.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ const AsyncStep: React.FC<Props> = React.memo(({ number }) => {
3333
// });
3434

3535
return (
36-
<div>
36+
<div
37+
style={{
38+
border: '1px solid grey',
39+
minHeight: '20vh',
40+
display: 'flex',
41+
alignItems: 'center',
42+
justifyContent: 'center',
43+
flexDirection: 'column',
44+
}}
45+
>
46+
<code>Async</code>
3747
<p>Step {number}</p>
3848
{isLoading && <p>loading...</p>}
3949
</div>

example/components/step.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ const Step: React.FC<Props> = React.memo(({ number }) => {
1414
});
1515

1616
return (
17-
<div>
17+
<div
18+
style={{
19+
border: '1px solid grey',
20+
minHeight: '20vh',
21+
display: 'flex',
22+
alignItems: 'center',
23+
justifyContent: 'center',
24+
flexDirection: 'column',
25+
}}
26+
>
27+
<code>Sync</code>
1828
<p>Step {number}</p>
1929
{isLoading && <p>loading...</p>}
2030
</div>

example/hooks/useMockMutation.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,38 @@ type Options<T> = {
88

99
/**
1010
* An ApolloClient clone of `useMutation`
11+
*
1112
* @param result The result once the promise is fulfilled
1213
* @param options Some options
14+
* @param options.makeError
15+
* @param options.timeout
16+
* @param options.onCompleted
17+
* @param options.makeError
18+
* @param options.timeout
19+
* @param options.onCompleted
20+
* @param options.makeError
21+
* @param options.timeout
22+
* @param options.onCompleted
1323
*/
1424
const useMockMutation = <T extends object = any>(
1525
result: T,
16-
{ makeError = false, timeout = 3000, onCompleted }: Options<T> = {}
26+
{ makeError = false, timeout = 3000, onCompleted }: Options<T> = {},
1727
) => {
1828
const [loading, setLoading] = React.useState(false);
1929
const [error, setError] = React.useState<{ message: string }>();
2030

2131
const mutationCb = React.useRef(async () => {
22-
const promise = new Promise<void>((res, rej) => {
32+
const promise = new Promise<void>((resolve, reject) => {
2333
setLoading(true);
2434

2535
setTimeout(() => {
2636
setLoading(false);
2737

2838
if (makeError) {
2939
setError({ message: 'Something went wrong' });
30-
rej({ message: 'Something went wrong' });
40+
reject({ message: 'Something went wrong' });
3141
} else {
32-
res(onCompleted?.(result));
42+
resolve(onCompleted?.(result));
3343
}
3444
}, timeout);
3545
});

example/index.tsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,43 @@ import * as ReactDOM from 'react-dom';
66

77
import { Wizard } from '../.';
88
import { AsyncStep, Footer, Step } from './components';
9+
import AnimatedStep from './components/animatedStep';
910

1011
const App: React.FC = () => {
1112
return (
12-
<Wizard footer={<Footer />} header={<p>header</p>}>
13-
<AsyncStep number={1} />
14-
<Step number={2} />
15-
<AsyncStep number={3} />
16-
<Step number={4} />
17-
</Wizard>
13+
<div
14+
style={{
15+
display: 'grid',
16+
gridTemplateRows: '1fr 1fr',
17+
}}
18+
>
19+
<section>
20+
<h2>Vanila</h2>
21+
<Wizard footer={<Footer />} header={<p>header</p>}>
22+
<AsyncStep number={1} />
23+
<Step number={2} />
24+
<AsyncStep number={3} />
25+
<Step number={4} />
26+
</Wizard>
27+
</section>
28+
<section>
29+
<h2>With animation</h2>
30+
<Wizard footer={<Footer />} header={<p>header</p>}>
31+
<AnimatedStep>
32+
<AsyncStep number={1} />
33+
</AnimatedStep>
34+
<AnimatedStep>
35+
<Step number={2} />
36+
</AnimatedStep>
37+
<AnimatedStep>
38+
<AsyncStep number={3} />
39+
</AnimatedStep>
40+
<AnimatedStep>
41+
<Step number={4} />
42+
</AnimatedStep>
43+
</Wizard>
44+
</section>
45+
</div>
1846
);
1947
};
2048

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "parcel build index.html"
99
},
1010
"dependencies": {
11+
"framer-motion": "^3.1.1",
1112
"react-app-polyfill": "^1.0.0"
1213
},
1314
"alias": {

example/yarn.lock

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@
807807
"@babel/types" "^7.4.4"
808808
esutils "^2.0.2"
809809

810-
"@babel/runtime@^7.4.4", "@babel/runtime@^7.8.4":
810+
"@babel/runtime@^7.12.5", "@babel/runtime@^7.4.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.8.4":
811811
version "7.12.5"
812812
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
813813
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
@@ -847,6 +847,18 @@
847847
lodash "^4.17.19"
848848
to-fast-properties "^2.0.0"
849849

850+
"@emotion/is-prop-valid@^0.8.2":
851+
version "0.8.8"
852+
resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz#db28b1c4368a259b60a97311d6a952d4fd01ac1a"
853+
integrity sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==
854+
dependencies:
855+
"@emotion/memoize" "0.7.4"
856+
857+
"@emotion/[email protected]":
858+
version "0.7.4"
859+
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.4.tgz#19bf0f5af19149111c40d98bb0cf82119f5d9eeb"
860+
integrity sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==
861+
850862
"@iarna/toml@^2.2.0":
851863
version "2.2.5"
852864
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
@@ -2386,6 +2398,24 @@ fragment-cache@^0.2.1:
23862398
dependencies:
23872399
map-cache "^0.2.2"
23882400

2401+
framer-motion@^3.1.1:
2402+
version "3.1.1"
2403+
resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-3.1.1.tgz#a8a779501213b7ce02cc35beb27621d73cc2f1e7"
2404+
integrity sha512-Gm1QSb0xUxuhcPar5FIs5Ws+STrhLZ6XZf2Io8dVwFofe1OzwkL9asGFVu7z3y6WqC4Hvnxm7wsW5SBHlxZDYw==
2405+
dependencies:
2406+
framesync "^5.0.0"
2407+
hey-listen "^1.0.8"
2408+
popmotion "^9.0.2"
2409+
style-value-types "^3.2.0"
2410+
tslib "^1.10.0"
2411+
optionalDependencies:
2412+
"@emotion/is-prop-valid" "^0.8.2"
2413+
2414+
[email protected], framesync@^5.0.0:
2415+
version "5.0.0"
2416+
resolved "https://registry.yarnpkg.com/framesync/-/framesync-5.0.0.tgz#7de8caedf53ac441118e79680f1beb7391c328b6"
2417+
integrity sha512-wd8t+JsQGisluSv1twiEeDv0aNGpavGb9q7xgIk9fGbcIWkNXF/KVtrjnOrCwBWJuiXxlJfNkcvGudsI32FxYA==
2418+
23892419
23902420
version "0.5.2"
23912421
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
@@ -2578,6 +2608,11 @@ hex-color-regex@^1.1.0:
25782608
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
25792609
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==
25802610

2611+
hey-listen@^1.0.8:
2612+
version "1.0.8"
2613+
resolved "https://registry.yarnpkg.com/hey-listen/-/hey-listen-1.0.8.tgz#8e59561ff724908de1aa924ed6ecc84a56a9aa68"
2614+
integrity sha512-COpmrF2NOg4TBWUJ5UVyaCU2A88wEMkUPK4hNqyCkqHbxT92BbvfjoSozkAIIm6XhicGlJHhFdullInrdhwU8Q==
2615+
25812616
hmac-drbg@^1.0.0:
25822617
version "1.0.1"
25832618
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
@@ -3159,6 +3194,14 @@ map-visit@^1.0.0:
31593194
dependencies:
31603195
object-visit "^1.0.0"
31613196

3197+
match-sorter@^6.0.2:
3198+
version "6.1.0"
3199+
resolved "https://registry.yarnpkg.com/match-sorter/-/match-sorter-6.1.0.tgz#7fec6808d94311a35fef7fd842a11634f2361bd7"
3200+
integrity sha512-sKPMf4kbF7Dm5Crx0bbfLpokK68PUJ/0STUIOPa1ZmTZEA3lCaPK3gapQR573oLmvdkTfGojzySkIwuq6Z6xRQ==
3201+
dependencies:
3202+
"@babel/runtime" "^7.12.5"
3203+
remove-accents "0.4.2"
3204+
31623205
md5.js@^1.3.4:
31633206
version "1.3.5"
31643207
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
@@ -3685,6 +3728,16 @@ pn@^1.1.0:
36853728
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
36863729
integrity sha512-2qHaIQr2VLRFoxe2nASzsV6ef4yOOH+Fi9FBOVH6cqeSgUnoyySPZkxzLuzd+RYOQTRpROA0ztTMqxROKSb/nA==
36873730

3731+
popmotion@^9.0.2:
3732+
version "9.0.2"
3733+
resolved "https://registry.yarnpkg.com/popmotion/-/popmotion-9.0.2.tgz#477650c3b4af97161011809223d9ca6860f3a2b5"
3734+
integrity sha512-WfSg8IfoUwYIP9uqeqbgncIsMHLAKWqebT2IP1aGAI6gdSJqTPy/H8NvP4ZyDtDCUCx5Yh3Pth/7iUJjIwR7LA==
3735+
dependencies:
3736+
framesync "5.0.0"
3737+
hey-listen "^1.0.8"
3738+
style-value-types "3.2.0"
3739+
tslib "^1.10.0"
3740+
36883741
posix-character-classes@^0.1.0:
36893742
version "0.1.1"
36903743
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
@@ -4209,6 +4262,14 @@ react-app-polyfill@^1.0.0:
42094262
regenerator-runtime "^0.13.3"
42104263
whatwg-fetch "^3.0.0"
42114264

4265+
react-query@^3.5.9:
4266+
version "3.5.9"
4267+
resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.5.9.tgz#2c001b5235e1afa11166a629c8645c9dd9464741"
4268+
integrity sha512-thlxrnl7cDg6qmk+N2ADjDVDJkoU3c7ZFJivYph0XoBDgkRIpb3A+tpqH7o6gu7JXZum9lfX1o294UfYfTiwvg==
4269+
dependencies:
4270+
"@babel/runtime" "^7.5.5"
4271+
match-sorter "^6.0.2"
4272+
42124273
readable-stream@^2.0.2, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.3, readable-stream@~2.3.6:
42134274
version "2.3.7"
42144275
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
@@ -4306,6 +4367,11 @@ relateurl@^0.2.7:
43064367
resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9"
43074368
integrity sha1-VNvzd+UUQKypCkzSdGANP/LYiKk=
43084369

4370+
4371+
version "0.4.2"
4372+
resolved "https://registry.yarnpkg.com/remove-accents/-/remove-accents-0.4.2.tgz#0a43d3aaae1e80db919e07ae254b285d9e1c7bb5"
4373+
integrity sha1-CkPTqq4egNuRngeuJUsoXZ4ce7U=
4374+
43094375
remove-trailing-separator@^1.0.1:
43104376
version "1.1.0"
43114377
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
@@ -4763,6 +4829,14 @@ strip-ansi@^4.0.0:
47634829
dependencies:
47644830
ansi-regex "^3.0.0"
47654831

4832+
[email protected], style-value-types@^3.2.0:
4833+
version "3.2.0"
4834+
resolved "https://registry.yarnpkg.com/style-value-types/-/style-value-types-3.2.0.tgz#eb89cab1340823fa7876f3e289d29d99c92111bb"
4835+
integrity sha512-ih0mGsrYYmVvdDi++/66O6BaQPRPRMQHoZevNNdMMcPlP/cH28Rnfsqf1UEba/Bwfuw9T8BmIMwbGdzsPwQKrQ==
4836+
dependencies:
4837+
hey-listen "^1.0.8"
4838+
tslib "^1.10.0"
4839+
47664840
stylehacks@^4.0.0:
47674841
version "4.0.3"
47684842
resolved "https://registry.yarnpkg.com/stylehacks/-/stylehacks-4.0.3.tgz#6718fcaf4d1e07d8a1318690881e8d96726a71d5"
@@ -4925,6 +4999,11 @@ tr46@^1.0.1:
49254999
dependencies:
49265000
punycode "^2.1.0"
49275001

5002+
tslib@^1.10.0:
5003+
version "1.14.1"
5004+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
5005+
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
5006+
49285007
49295008
version "0.0.0"
49305009
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
 (0)