Skip to content

Commit b5e2959

Browse files
committed
Merge branch 'main' of https://github.com/devrnt/react-use-wizard into feat/wizard-wrapper
2 parents cdf6d89 + b5abeb7 commit b5e2959

20 files changed

Lines changed: 2781 additions & 4684 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ jobs:
77
runs-on: ${{ matrix.os }}
88
strategy:
99
matrix:
10-
node: ['12.x', '14.x']
11-
os: [ubuntu-latest]
10+
node: ['14.x', '16.x']
11+
os: [ubuntu-20.04]
1212

1313
steps:
1414
- name: Checkout repo

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*.log
22
.DS_Store
33
node_modules
4-
.cache
54
dist
5+
.parcel-cache

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,25 @@ const App = () => {
108108

109109
### useWizard
110110

111-
Used to retrieve all methods and properties related to your wizard. Make sure `Wizard` is wrapped around your component when calling `useWizard`.
111+
Used to retrieve all methods and properties related to your wizard. Make sure `Wizard` is wrapped around your component when calling `useWizard`.
112112

113113
`handleStep` is used to attach a handler to the step, can either be `async` or a `sync` function. This function will be invoked when calling `nextStep`.
114114

115115
**Remark** - You can't use `useWizard` in the same component where `Wizard` is used.
116116

117117
#### Methods
118118

119-
| name | type | description |
120-
| ------------ | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
121-
| nextStep | () => Promise<void> | Go to the next step |
122-
| previousStep | () => void | Go to the previous step index |
123-
| goToStep | (stepIndex: number) => void | Go to the given step index |
124-
| handleStep | (handler: Handler) => void | Attach a callback that will be called when calling `nextStep`. `handler` can be either sync or async |
125-
| isLoading | boolean | \* Will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected |
126-
| activeStep | number | The current active step of the wizard |
127-
| isFirstStep | boolean | Indicate if the current step is the first step (aka no previous step) |
128-
| isLastStep | boolean | Indicate if the current step is the last step (aka no next step) |
119+
| name | type | description |
120+
| ------------ | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
121+
| nextStep | () => Promise<void> | Go to the next step |
122+
| previousStep | () => void | Go to the previous step index |
123+
| goToStep | (stepIndex: number) => void | Go to the given step index |
124+
| handleStep | (handler: Handler) => void | Attach a callback that will be called when calling `nextStep`. `handler` can be either sync or async |
125+
| isLoading | boolean | \* Will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected |
126+
| activeStep | number | The current active step of the wizard |
127+
| stepCount | number | The total number of steps of the wizard |
128+
| isFirstStep | boolean | Indicate if the current step is the first step (aka no previous step) |
129+
| isLastStep | boolean | Indicate if the current step is the last step (aka no next step) |
129130
| |
130131

131132
#### Example
@@ -149,6 +150,7 @@ const Step1 = () => {
149150
isLastStep,
150151
isFirstStep,
151152
activeStep,
153+
stepCount,
152154
previousStep,
153155
nextStep,
154156
goToStep,
@@ -180,16 +182,20 @@ const Step1 = () => {
180182
It's recommended to pass the shared components to the `header` or `footer` in the `Wizard` to avoid duplication.
181183

182184
## Playground
185+
183186
Small playground to showcase the functionalities of `react-use-wizard`:
184187
[https://devrnt.github.io/react-use-wizard/](https://devrnt.github.io/react-use-wizard/)
185188

186189
Following use cases are available in the playground
187-
- Simple wizard with async and sync steps
188-
- Animated wizard with sync steps
189-
- Integration with [react-query](https://react-query.tanstack.com/) (mutation on next step)
190190

191-
Source code can be found [here](https://github.com/devrnt/react-use-wizard/tree/main/playground).
191+
- Simple wizard with async and sync steps
192+
- Animated wizard with sync steps
193+
- Integration with [react-query](https://react-query.tanstack.com/) (mutation on next step)
194+
195+
Source code can be found [here](https://github.com/devrnt/react-use-wizard/tree/main/playground).
196+
192197
## Examples
198+
193199
Go to [examples](https://github.com/devrnt/react-use-wizard/tree/master/examples) to check out some integrations (Gatsby, NextJS...).
194200

195201
## Async
@@ -230,9 +236,10 @@ If an async function is attached to `handleStep` the `isLoading` property will i
230236

231237
Since `react-use-wizard` is focused to manage the logic of a wizard it doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest [framer-motion](https://www.framer.com/motion/) to add your animations.
232238

233-
Checkout this [example](https://github.com/devrnt/react-use-wizard/blob/main/playground/components/animatedStep.tsx) to see how a step can be animated with framer motion.
239+
Checkout this [example](https://github.com/devrnt/react-use-wizard/blob/main/playground/components/animatedStep.tsx) to see how a step can be animated with framer motion.
234240

235241
## IE11
242+
236243
Since Internet Explorer 11 doesn't support promises or async functions you'll need to install a polyfill for the `regenerator-runtime`.
237244

238-
In general using [react-app-polyfill](https://www.npmjs.com/package/react-app-polyfill) is recommended, it includes polyfills for various browsers.
245+
In general using [react-app-polyfill](https://www.npmjs.com/package/react-app-polyfill) is recommended, it includes polyfills for various browsers.

examples/gatsby/src/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Footer = () => {
1919
previousStep,
2020
isLoading,
2121
activeStep,
22+
stepCount,
2223
isLastStep,
2324
isFirstStep
2425
} = useWizard();
@@ -33,6 +34,10 @@ const Footer = () => {
3334
<p>
3435
Active step: {activeStep + 1} <br />
3536
</p>
37+
<br />
38+
<p>
39+
Total steps: {stepCount} <br />
40+
</p>
3641
</div>
3742
<div>
3843
<button

examples/gatsby/yarn.lock

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,17 +4296,10 @@ debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.6, debug@^3.2.7:
42964296
dependencies:
42974297
ms "^2.1.1"
42984298

4299-
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1:
4300-
version "4.3.1"
4301-
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
4302-
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
4303-
dependencies:
4304-
ms "2.1.2"
4305-
4306-
debug@~4.3.1:
4307-
version "4.3.2"
4308-
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b"
4309-
integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==
4299+
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@~4.3.1:
4300+
version "4.3.3"
4301+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
4302+
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
43104303
dependencies:
43114304
ms "2.1.2"
43124305

@@ -4847,16 +4840,16 @@ engine.io-client@~4.1.0:
48474840
yeast "0.1.2"
48484841

48494842
engine.io-parser@~4.0.0, engine.io-parser@~4.0.1:
4850-
version "4.0.2"
4851-
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-4.0.2.tgz#e41d0b3fb66f7bf4a3671d2038a154024edb501e"
4852-
integrity sha512-sHfEQv6nmtJrq6TKuIz5kyEKH/qSdK56H/A+7DnAuUPWosnIZAS2NHNcPLmyjtY3cGS/MqJdZbUjW97JU72iYg==
4843+
version "4.0.3"
4844+
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-4.0.3.tgz#83d3a17acfd4226f19e721bb22a1ee8f7662d2f6"
4845+
integrity sha512-xEAAY0msNnESNPc00e19y5heTPX4y/TJ36gr8t1voOaNmTojP9b3oK3BbJLFufW2XFPQaaijpFewm2g2Um3uqA==
48534846
dependencies:
48544847
base64-arraybuffer "0.1.4"
48554848

48564849
engine.io@~4.1.0:
4857-
version "4.1.1"
4858-
resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-4.1.1.tgz#9a8f8a5ac5a5ea316183c489bf7f5b6cf91ace5b"
4859-
integrity sha512-t2E9wLlssQjGw0nluF6aYyfX8LwYU8Jj0xct+pAhfWfv/YrBn6TSNtEYsgxHIfaMqfrLx07czcMg9bMN6di+3w==
4850+
version "4.1.2"
4851+
resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-4.1.2.tgz#f96ceb56d4b39cc7ca5bd29a20e9c99c1ad1a765"
4852+
integrity sha512-t5z6zjXuVLhXDMiFJPYsPOWEER8B0tIsD3ETgw19S1yg9zryvUfY3Vhtk3Gf4sihw/bQGIqQ//gjvVlu+Ca0bQ==
48604853
dependencies:
48614854
accepts "~1.3.4"
48624855
base64id "2.0.0"
@@ -5809,9 +5802,9 @@ flatted@^3.1.0:
58095802
integrity sha512-OMQjaErSFHmHqZe+PSidH5n8j3O0F2DdnVh8JB4j4eUQ2k6KvB0qGfrKIhapvez5JerBbmWkaLYUYWISaESoXg==
58105803

58115804
follow-redirects@^1.0.0, follow-redirects@^1.10.0:
5812-
version "1.13.0"
5813-
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
5814-
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==
5805+
version "1.14.8"
5806+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
5807+
integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==
58155808

58165809
for-in@^1.0.2:
58175810
version "1.0.2"
@@ -8735,12 +8728,17 @@ mime-db@1.48.0:
87358728
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.48.0.tgz#e35b31045dd7eada3aaad537ed88a33afbef2d1d"
87368729
integrity sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==
87378730

8731+
mime-db@1.51.0:
8732+
version "1.51.0"
8733+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.51.0.tgz#d9ff62451859b18342d960850dc3cfb77e63fb0c"
8734+
integrity sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==
8735+
87388736
"mime-db@>= 1.43.0 < 2", mime-db@^1.28.0:
87398737
version "1.45.0"
87408738
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea"
87418739
integrity sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==
87428740

8743-
mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.24:
8741+
mime-types@^2.1.12, mime-types@~2.1.17:
87448742
version "2.1.27"
87458743
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f"
87468744
integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==
@@ -8754,6 +8752,13 @@ mime-types@^2.1.27, mime-types@^2.1.30:
87548752
dependencies:
87558753
mime-db "1.48.0"
87568754

8755+
mime-types@~2.1.24:
8756+
version "2.1.34"
8757+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.34.tgz#5a712f9ec1503511a945803640fafe09d3793c24"
8758+
integrity sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==
8759+
dependencies:
8760+
mime-db "1.51.0"
8761+
87578762
mime@1.6.0, mime@^1.3.4:
87588763
version "1.6.0"
87598764
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
@@ -8823,9 +8828,9 @@ minimatch@3.0.4, minimatch@^3.0.3, minimatch@^3.0.4:
88238828
brace-expansion "^1.1.7"
88248829

88258830
minimist@^1.1.0, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5:
8826-
version "1.2.5"
8827-
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
8828-
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
8831+
version "1.2.6"
8832+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
8833+
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
88298834

88308835
mitt@^1.2.0:
88318836
version "1.2.0"
@@ -8858,9 +8863,9 @@ mkdirp@^1.0.4:
88588863
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
88598864

88608865
moment@^2.27.0:
8861-
version "2.29.1"
8862-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
8863-
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
8866+
version "2.29.2"
8867+
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.2.tgz#00910c60b20843bcba52d37d58c628b47b1f20e4"
8868+
integrity sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==
88648869

88658870
mozjpeg@^7.0.0:
88668871
version "7.0.0"
@@ -8929,9 +8934,9 @@ nan@^2.12.1:
89298934
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
89308935

89318936
nanoid@^3.1.20, nanoid@^3.1.23:
8932-
version "3.1.23"
8933-
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.23.tgz#f744086ce7c2bc47ee0a8472574d5c78e4183a81"
8934-
integrity sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==
8937+
version "3.2.0"
8938+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.2.0.tgz#62667522da6673971cca916a6d3eff3f415ff80c"
8939+
integrity sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA==
89358940

89368941
nanomatch@^1.2.9:
89378942
version "1.2.13"
@@ -11380,9 +11385,9 @@ simple-concat@^1.0.0:
1138011385
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==
1138111386

1138211387
simple-get@^3.0.3, simple-get@^3.1.0:
11383-
version "3.1.0"
11384-
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-3.1.0.tgz#b45be062435e50d159540b576202ceec40b9c6b3"
11385-
integrity sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA==
11388+
version "3.1.1"
11389+
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-3.1.1.tgz#cc7ba77cfbe761036fbfce3d021af25fc5584d55"
11390+
integrity sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==
1138611391
dependencies:
1138711392
decompress-response "^4.2.0"
1138811393
once "^1.3.1"
@@ -12712,9 +12717,9 @@ url-parse-lax@^3.0.0:
1271212717
prepend-http "^2.0.0"
1271312718

1271412719
url-parse@^1.4.3, url-parse@^1.4.7:
12715-
version "1.5.3"
12716-
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862"
12717-
integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==
12720+
version "1.5.10"
12721+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
12722+
integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==
1271812723
dependencies:
1271912724
querystringify "^2.1.1"
1272012725
requires-port "^1.0.0"

examples/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "next start"
99
},
1010
"dependencies": {
11-
"next": "11.1.1",
11+
"next": "12.1.0",
1212
"react": "17.0.2",
1313
"react-dom": "17.0.2",
1414
"react-use-wizard": "^1.1.2"

examples/nextjs/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const Footer = () => {
1717
previousStep,
1818
isLoading,
1919
activeStep,
20+
stepCount,
2021
isLastStep,
2122
isFirstStep,
2223
} = useWizard();
@@ -31,6 +32,10 @@ const Footer = () => {
3132
<p>
3233
Active step: {activeStep + 1} <br />
3334
</p>
35+
<br />
36+
<p>
37+
Total steps: {stepCount} <br />
38+
</p>
3439
</div>
3540
<div>
3641
<button

0 commit comments

Comments
 (0)