Skip to content

Commit

Permalink
feat: allow async next function evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarbareket committed Apr 14, 2023
1 parent e5af478 commit 06a4125
Show file tree
Hide file tree
Showing 64 changed files with 903 additions and 266 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# WhizFlow
![npm bundle size](https://img.shields.io/bundlephobia/minzip/whizflow)
![npm](https://img.shields.io/npm/dm/whizflow)
![npm](https://img.shields.io/npm/v/whizflow)
![node-current](https://img.shields.io/node/v/whizflow)

WhizFlow is a lightweight, headless and extensible React library for building dynamic multi-step forms or troubleshooting workflows.

Expand Down Expand Up @@ -120,8 +124,10 @@ export default YourComponent;

- `step`: The current step object.
- `answers`: An object containing the answers for each question in the workflow.
- `loading`: A boolean to mark when `handleNext` is waiting to resolve.
- `setAnswers`: A function to update the `answers` object.
- `handleNext`: A function to handle navigation to the next step in the workflow.
- `handlePrev`: A function to handle navigation to the previous step.
- `renderQuestion`: A function to render the correct question type based on the provided dictionary.

### Step
Expand Down Expand Up @@ -172,14 +178,17 @@ const questionTypes = {
| | `onComplete` | `(answers: Answers) => void` |A callback function to be called when the workflow reaches the `done` step. (Optional) |
| | `questionTypes` | `{ [key: string]: QuestionRenderFunction }` | An object with keys representing the question type and values as the corresponding render functions. (Optional) |
| | `step` | `Step` | The current step object. (Render prop) |
| | `loading` | `boolean` | Whether `handleNext` is running asyncly. (Render prop) |
| | `answers` | `Record<string, any>` | An object containing the answers for each question in the workflow. (Render prop) |
| | `setAnswers` | `(updatedAnswers: Record<string, any>) => void` | A function to update the `answers` object. (Render prop) |
| | `handleNext` | `(submitterAnswers?: Record<string, any>) => void` | A function to handle navigation to the next step in the workflow, allows the submitter to update the answers. (Render prop) |
| | `handlePrev` | `() => void` | A function to handle navigation to the previous step in the workflow. (Render prop) |
| | `renderQuestion` | `(questionId: string) => React.ReactNode` | A function to render the correct question type based on the provided dictionary. (Render prop) |
| **Step** | | | An object defining a single step in the workflow. |
| | `id` | `string` | A unique identifier for the step. |
| | `questions` | `Question[]` | An array of `Question` objects. |
| | `next` | `(answers: Record<string, any>) => string \| 'done'` | A function that determines the next step in the workflow based on the current answers. It should return the next step's ID or 'done' if the workflow is complete. |
| | `next` | `string \| { nextStepId: string; updatedAnswers?: Answers } ֿֿֿ\| Promise<string> \| Promise<{ nextStepId: string; updatedAnswers?: Answers }>` | A function that determines the next step in the workflow based on the current answers. It should return the next step's ID or 'done' if the workflow is complete. |
| | `context?` | `any` | An optional context object for the question to pass (to be used later when rendering). |
| **Question** | | | An object defining a single question within a step. |
| | `id` | `string` | A unique identifier for the question. |
| | `prompt` | `string` | The question's text. |
Expand Down
2 changes: 1 addition & 1 deletion dist/WhizFlow.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions dist/WhizFlow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/WhizFlow.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 06a4125

Please sign in to comment.