|
1 | 1 | # react-wizard-flow |
2 | | -[](https://circleci.com/gh/notwillk/react-wizard-flow) |
3 | 2 |
|
4 | 3 | [](https://www.npmjs.com/package/react-wizard-flow) |
5 | 4 | [](https://unpkg.com/react-wizard-flow) |
6 | 5 | [](https://www.npmjs.com/package/react-wizard-flow) |
7 | 6 | [](http://makeapullrequest.com) |
8 | 7 |
|
| 8 | +## Usage |
| 9 | + |
| 10 | +```typescript |
| 11 | +import { createWizardFlow, useWizardFlow } from 'react-wizard-flow'; |
| 12 | + |
| 13 | +enum TestSteps { |
| 14 | + step1, |
| 15 | + step2, |
| 16 | +} |
| 17 | + |
| 18 | +const WizardFlow = createWizardFlow(TestSteps); |
| 19 | + |
| 20 | +function Step1() { |
| 21 | + const { transition, close } = useWizardFlow(WizardFlow); |
| 22 | + return ( |
| 23 | + <div> |
| 24 | + <header>Step 1</header> |
| 25 | + <button onClick={() => transition(TestSteps.step1)}>To Step 1</button> |
| 26 | + <button onClick={() => transition(TestSteps.step2)}>To Step 2</button> |
| 27 | + <button onClick={close}>Close</button> |
| 28 | + </div> |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +function Step2() { |
| 33 | + const { transition, close } = useWizardFlow(WizardFlow); |
| 34 | + return ( |
| 35 | + <div> |
| 36 | + <header>Step 1</header> |
| 37 | + <button onClick={() => transition(TestSteps.step1)}>To Step 1</button> |
| 38 | + <button onClick={() => transition(TestSteps.step2)}>To Step 2</button> |
| 39 | + <button onClick={close}>Close</button> |
| 40 | + </div> |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +const STEPS = { |
| 45 | + [TestSteps.step1]: <Step1 />, |
| 46 | + [TestSteps.step2]: <Step2 />, |
| 47 | +}; |
| 48 | + |
| 49 | +export default function() { |
| 50 | + const onClose = () => { console.log('Flow closed'); } |
| 51 | + return <WizardFlow.Provider initialStep={TestSteps.step1} steps={STEPS} onClose={onClose} /> |
| 52 | +} |
| 53 | +``` |
| 54 | + |
9 | 55 | This README was generated by [anansi](https://github.com/ntucker/anansi/tree/master/packages/generator-js#readme). |
0 commit comments