Module to easily implement decision tree logic in a react app
npm install catalyst-decision-treeA simple react module to enable chained questions, where each user response leads to a unique follow up question, ultimately ending in a final result based on that specific pathway of answers.
===THIS IS STILL A WIP====
* Based off the code that was created for the NZ COVID Financial Tool
* No limit on the number of questions you can ask in a given chain
* Made with accessibility in mind
* All inputs are radio buttons
* Option to include a customizable "moreInfo" dropdown for a given question to provide additional details to your user
* Features easy to understand class names to making CSS styling easier
* Embedded HTML allows customization of the results paragraph
Check out the decision tree in action here!
``
import React, { Fragment } from "react";
import DATA from './data.json'
import { DecisionTree } from 'react-decision-tree-questionnaire';
export const myComponent = () => {
return (
My Decision Tree
resultsHeader={"Based on your results..."}
/>
);
};
`
` Good human! Sounds like you'll make for an excellent dog friend. Click here to see some photos of dogs as a treat pat pat Good human! Sounds like you'll make for an excellent dog friend. Click here to see some photos of dogs as a treat pat pat Bad human! Dogs like being outside, and dogs can't wear most of the things available at a mall anyway. It sounds like you might not like dogs very much. Dogs love you, why don't you love them back? Here is a link to see some images of dogs not licking you.`
{
"question": "What's your favourite animal?",
"answers": [
{
"answer": "Dog",
"subquestion": {
"question": "Do you like being licked in the face?",
"answers": [
{
"answer": "Yes",
"subquestion": {
"question": "Where's the best place to walk a dog?",
"moreInfo": {
"title": "What constitutes a walk?",
"text": "Walking a dog is a shorthand to mean taking it outside to relive itself, play, run or indeed walk. Walks can be any length of time, and are expected to take place outdoors. A backyard or balcony is not considered a walk."
},
"answers": [
{
"answer": "A park",
"result": {
"text": "
}
},
{
"answer": "Around the block",
"result": {
"text": "
}
},
{
"answer": "At a mall",
"result": {
"text": "
}
}
]
}
},
{
"answer": "No",
"result": {
"text": "
}
}
]
}
},
{
"answer": "Cat",
//...
},
{
"answer": "Elephant",
// ...
},
{
"answer": "Penguin",
// ...
}
]
}subquestion
| Attribute | Type | Description |
| :------------- | :----------: | -----------: |
| question
required | string | Exists at every layer of the chain except for when a result is revealed |
| answers
required | array | An array containing all the answer options. There is no limit on the number of answer options you can include. |
| answer
required | string | This is the answer option for the previously listed question. |
| subquestion
optional | object
| What happens after a user clicks on a given answer? Either a new question () or a result. subquestion is an object that contains the next layer of question and answers, which repeats itself until the chain of questioning has been completed. Only one subquestion can exist at a given layer. |subquestion
| result
optional | object
| What happens after a user clicks on a given answer? Either a new question () or a result. result is an object that takes text. text accepts HTML markup. |title
| moreInfo
optional | object | To provide user with further information about the question. This reveals an accordion with a display text () and text when clicked open. |moreInfo
| title / text
as appears in or result`| string | -- |
| Attribute | Type | Description |
| :------------- | :----------: | -----------: |
| data
require | JSON | As noted above |
| resultsHeader
optional | string | Suggested. The heading you would like to appear at the top of the results. This will be uniform across all results.