1
1
# react-quizzes
2
2
3
3
[ ![ MIT License] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=plastic )] ( http://opensource.org/licenses/MIT )
4
- [ ![ npm version] ( https://img.shields.io/badge/npm-v0.1 .0-green.svg?style=plastic )] ( https://www.npmjs.com/package/react-quizzes )
4
+ [ ![ npm version] ( https://img.shields.io/badge/npm-v0.2 .0-green.svg?style=plastic )] ( https://www.npmjs.com/package/react-quizzes )
5
5
6
6
Demo:
7
7
[ ![ Edit react-quizzesExample] ( https://codesandbox.io/static/img/play-codesandbox.svg )] ( https://codesandbox.io/s/magical-chandrasekhar-88del?fontsize=14&hidenavigation=1&theme=dark )
@@ -12,6 +12,7 @@ React form builder and form delivery solution for admins and clients that makes
12
12
Inspired by abandoned project: https://github.com/blackjk3/react-form-builder
13
13
14
14
Advantages:
15
+
15
16
- Supports custom inputs
16
17
- Rich text questions
17
18
- Supports custom styles
@@ -36,84 +37,79 @@ For custom styling check [`Custom styles`](#Custom-styles) section
36
37
37
38
` react-quizzes ` requires ` react ` and ` react-dom ` as [ ` peerDependency ` ] ( https://docs.npmjs.com/files/package.json#peerdependencies )
38
39
39
- # QuizzBuilder
40
+ # QuizzBuilder
40
41
41
42
``` html
42
- import { QuizzBuilder } from "react-quizzes"
43
- <QuizzBuilder
44
- onChange ={(QuizzData) => console.log(form)}
45
- />
46
- ````
43
+ import { QuizzBuilder } from "react-quizzes" <QuizzBuilder onChange ={(QuizzData)
44
+ => console.log(form)} />
45
+ ```
47
46
48
47
## API
48
+
49
49
QuizzBuilder component objective is to provide the user a nice and smooth interface to build quizzes
50
50
51
- Props | Type | Default | Description
52
- ------------- | -------- | ------- | -------------
53
- `onChange` | `Function` | ` ` | will returns builded quizz in QuizzData type
54
- `initialValue`| `QuizzData`| `` | initial value to QuizzBuilder, useful if user wants to edit a saved quizz
55
- `toolBox` | `QuizzToolBox`| `default QuizzToolBox` | list of inputs to use, defaults to react-quizz but custom inputs can be supplied
56
- `language` | `string`| `en` | Language that QuizzBuilder will show
57
- `messages` | `QuizzMessages`| `default QuizzMessages` | Object with each language and each language with each text translation
51
+ | Props | Type | Default | Description |
52
+ | -------------- | --------------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
53
+ | ` onChange ` | ` Function ` | `` | will returns builded quizz in QuizzData type |
54
+ | ` initialValue ` | ` QuizzData ` | `` | initial value to QuizzBuilder, useful if user wants to edit a saved quizz |
55
+ | ` toolBox ` | ` QuizzToolBox ` | ` default QuizzToolBox ` | list of inputs to use, defaults to react-quizz but custom inputs can be supplied |
56
+ | ` language ` | ` string ` | ` en ` | Language that QuizzBuilder will show |
57
+ | ` messages ` | ` QuizzMessages ` | ` default QuizzMessages ` | Object with each language and each language with each text translation |
58
58
59
59
# Quiz
60
60
61
61
A component that provides the final user a quiz/form to fill
62
62
63
63
``` html
64
- import { Quiz } from "react-quizzes"
65
- <Quiz
66
- data ={Mockdata}
67
- onSubmit ={(values) => console.log("form submited values", values)}
68
- />
69
- ````
64
+ import { Quiz } from "react-quizzes" <Quiz data ={Mockdata} onSubmit ={(values) =>
65
+ console.log("form submited values", values)} />
66
+ ```
70
67
71
68
## API
72
69
73
- Props | Type | Default | Description
74
- ------------- | ----------- | ------- | -------------
75
- `data` | `QuizzData` | ` ` | data to build the final user form to be filled
76
- `onSubmit` | `Fucntion` | ` ` | returns the submitted form values
77
- `submitButton`| `boolean` | ` true` | shows/hides default submit button*
78
- `toolBox` | `QuizzToolBox`| `default QuizzToolBox` | list of inputs to use, defaults to react-quizz but custom inputs can be supplied
79
- `language` | `string`| `en` | Language that Quiz questions and options will show
80
- `messages` | `QuizzMessages`| `default QuizzMessages` | Object with each language and each language with each text translation
70
+ | Props | Type | Default | Description |
71
+ | -------------- | --------------- | ----------------------- | -------------------------------------------------------------------------------- |
72
+ | ` data ` | ` QuizzData ` | `` | data to build the final user form to be filled |
73
+ | ` onSubmit ` | ` Fucntion ` | `` | returns the submitted form values |
74
+ | ` submitButton ` | ` boolean ` | ` true ` | shows/hides default submit button\* |
75
+ | ` toolBox ` | ` QuizzToolBox ` | ` default QuizzToolBox ` | list of inputs to use, defaults to react-quizz but custom inputs can be supplied |
76
+ | ` language ` | ` string ` | ` en ` | Language that Quiz questions and options will show |
77
+ | ` messages ` | ` QuizzMessages ` | ` default QuizzMessages ` | Object with each language and each language with each text translation |
81
78
82
- * if submit button is hidden the default onSubmit will not work, you must implement a custom submit
79
+ - if submit button is hidden the default onSubmit will not work, you must implement a custom submit
83
80
84
81
## Custom submit
85
82
86
- There is a prop `wrappedComponentRef` that gives you access to make basically anything, reset form, set initial values change the values based on something....
83
+ There is a prop ` wrappedComponentRef ` that gives you access to make basically anything, reset form, set initial values change the values based on something....
87
84
88
85
[ ` wrappedComponentRef ` ] ( https://github.com/react-component/form#note-use-wrappedcomponentref-instead-of-withref-after-rc-form140 )
89
86
90
87
``` jsx
91
- import { Quiz } from "react-quizzes"
92
-
93
- saveQuizRef =(quizRef) => {
94
- // saves Quizz component ref
95
- this.quizRef = quizRef;
96
- }
97
- // custom submit function
98
- handleCustomSubmit= () =>{
99
- const form = this.quizRef.props.form;
100
- form.validateFields((err, values) => {
101
- if (!err) {
102
- // if no errors, no errors means required answers are filled
103
- console.log('Received values of form: ', values);
104
- form.resetFields(); // resets form after recieveing values
105
- }
106
-
107
- });
108
- }
88
+ import { Quiz } from " react-quizzes" ;
89
+
90
+ saveQuizRef = quizRef => {
91
+ // saves Quizz component ref
92
+ this .quizRef = quizRef;
93
+ };
94
+ // custom submit function
95
+ handleCustomSubmit = () => {
96
+ const form = this .quizRef .props .form ;
97
+ form .validateFields ((err , values ) => {
98
+ if (! err) {
99
+ // if no errors, no errors means required answers are filled
100
+ console .log (" Received values of form: " , values);
101
+ form .resetFields (); // resets form after recieveing values
102
+ }
103
+ });
104
+ };
109
105
< Fragment>
110
- <Quiz
111
- wrappedComponentRef ={this.saveQuizRef}
112
- submitButton ={false} // hides inside submit button
113
- data ={Mockdata}
114
- />
115
- <Button onClick ={this.handleCustomSubmit} >Custom Submit btn</Button >
116
- </Fragment >
106
+ < Quiz
107
+ wrappedComponentRef= {this .saveQuizRef }
108
+ submitButton= {false } // hides inside submit button
109
+ data= {Mockdata}
110
+ / >
111
+ < Button onClick= {this .handleCustomSubmit }> Custom Submit btn< / Button>
112
+ < / Fragment> ;
117
113
```
118
114
119
115
# Translations/Internationalization
@@ -138,7 +134,7 @@ function App() {
138
134
return < QuizzBuilder
139
135
onChange= {(form ) => console .log (form)}
140
136
language= " pt-PT"
141
- messages= {toolBoxItems}
137
+ messages= {toolBoxItems}
142
138
/ >
143
139
}
144
140
```
@@ -167,7 +163,7 @@ toolbox.push(
167
163
name: " toolbox.input.name" , // id of translation
168
164
questions: {
169
165
" en" : " How are you ?"
170
- ...
166
+ ...
171
167
},
172
168
// description: "toolbox.headertext.description", // desciption under input on toolbox
173
169
icon: < Avatar icon= " line" / > , // this will go to Dom so can be string|| jsx component
@@ -183,6 +179,7 @@ function App() {
183
179
/ >
184
180
}
185
181
```
182
+
186
183
[ MyInput example] ( ./src/ToolBox/Components/TextInput.tsx )
187
184
188
185
Example:
0 commit comments