dce-reactkit 1.0.20 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/.eslintrc.js +95 -0
  2. package/lib/components/LoadingSpinner.d.ts +7 -0
  3. package/lib/components/LoadingSpinner.js +39 -0
  4. package/lib/components/LoadingSpinner.js.map +1 -0
  5. package/lib/components/Modal.d.ts +69 -0
  6. package/lib/components/Modal.js +311 -0
  7. package/lib/components/Modal.js.map +1 -0
  8. package/lib/helpers/abbreviate.d.ts +9 -0
  9. package/lib/helpers/abbreviate.js +21 -0
  10. package/lib/helpers/abbreviate.js.map +1 -0
  11. package/lib/helpers/avg.d.ts +8 -0
  12. package/lib/helpers/avg.js +24 -0
  13. package/lib/helpers/avg.js.map +1 -0
  14. package/lib/helpers/ceilToNumDecimals.d.ts +9 -0
  15. package/lib/helpers/ceilToNumDecimals.js +15 -0
  16. package/lib/helpers/ceilToNumDecimals.js.map +1 -0
  17. package/lib/helpers/floorToNumDecimals.d.ts +9 -0
  18. package/lib/helpers/floorToNumDecimals.js +15 -0
  19. package/lib/helpers/floorToNumDecimals.js.map +1 -0
  20. package/lib/helpers/forceNumIntoBounds.d.ts +10 -0
  21. package/lib/helpers/forceNumIntoBounds.js +15 -0
  22. package/lib/helpers/forceNumIntoBounds.js.map +1 -0
  23. package/lib/helpers/padDecimalZeros.d.ts +10 -0
  24. package/lib/helpers/padDecimalZeros.js +30 -0
  25. package/lib/helpers/padDecimalZeros.js.map +1 -0
  26. package/lib/helpers/padZerosLeft.d.ts +9 -0
  27. package/lib/helpers/padZerosLeft.js +21 -0
  28. package/lib/helpers/padZerosLeft.js.map +1 -0
  29. package/lib/helpers/roundToNumDecimals.d.ts +9 -0
  30. package/lib/helpers/roundToNumDecimals.js +15 -0
  31. package/lib/helpers/roundToNumDecimals.js.map +1 -0
  32. package/lib/helpers/sum.d.ts +8 -0
  33. package/lib/helpers/sum.js +15 -0
  34. package/lib/helpers/sum.js.map +1 -0
  35. package/lib/helpers/waitMs.d.ts +7 -0
  36. package/lib/helpers/waitMs.js +55 -0
  37. package/lib/helpers/waitMs.js.map +1 -0
  38. package/lib/types/Variant.d.ts +15 -0
  39. package/lib/types/Variant.js +19 -0
  40. package/lib/types/Variant.js.map +1 -0
  41. package/package.json +22 -40
  42. package/src/components/LoadingSpinner.scss +50 -0
  43. package/src/components/LoadingSpinner.tsx +50 -0
  44. package/src/components/Modal.scss +48 -0
  45. package/src/components/Modal.tsx +391 -0
  46. package/src/helpers/abbreviate.tsx +23 -0
  47. package/src/helpers/avg.tsx +22 -0
  48. package/src/helpers/ceilToNumDecimals.tsx +13 -0
  49. package/src/helpers/floorToNumDecimals.tsx +13 -0
  50. package/src/helpers/forceNumIntoBounds.tsx +19 -0
  51. package/src/helpers/padDecimalZeros.tsx +32 -0
  52. package/src/helpers/padZerosLeft.tsx +21 -0
  53. package/src/helpers/roundToNumDecimals.tsx +13 -0
  54. package/src/helpers/sum.tsx +16 -0
  55. package/src/helpers/waitMs.tsx +12 -0
  56. package/src/types/Variant.tsx +16 -0
  57. package/tsconfig.json +24 -0
  58. package/index.js +0 -1
  59. package/lib/Bar.js +0 -169
  60. package/lib/Donut.js +0 -145
  61. package/lib/DownloadButton.js +0 -81
  62. package/lib/Histogram.js +0 -193
  63. package/lib/Scatter.js +0 -162
  64. package/lib/StackedBar.js +0 -243
  65. package/lib/common/chart/Holder/index.js +0 -182
  66. package/lib/common/chart/Holder/style.css +0 -41
  67. package/lib/common/chart/colors.js +0 -12
  68. package/lib/common/csvToString.js +0 -23
  69. package/lib/common/isFloat.js +0 -14
  70. package/lib/common/isInteger.js +0 -24
  71. package/lib/common/math.js +0 -21
  72. package/lib/common/validators.js +0 -18
  73. package/lib/glyph/Adjust.js +0 -13
  74. package/lib/glyph/Angle.js +0 -44
  75. package/lib/glyph/Archive.js +0 -13
  76. package/lib/glyph/Arrow.js +0 -49
  77. package/lib/glyph/ArrowsHorizontal.js +0 -13
  78. package/lib/glyph/ArrowsVertical.js +0 -13
  79. package/lib/glyph/Award.js +0 -13
  80. package/lib/glyph/Ban.js +0 -13
  81. package/lib/glyph/Barcode.js +0 -13
  82. package/lib/glyph/Bed.js +0 -13
  83. package/lib/glyph/Bell.js +0 -35
  84. package/lib/glyph/Bolt.js +0 -13
  85. package/lib/glyph/Bookmark.js +0 -37
  86. package/lib/glyph/Bug.js +0 -13
  87. package/lib/glyph/Calendar.js +0 -13
  88. package/lib/glyph/Check.js +0 -36
  89. package/lib/glyph/Checkbox.js +0 -40
  90. package/lib/glyph/Chevron.js +0 -63
  91. package/lib/glyph/Circle.js +0 -15
  92. package/lib/glyph/Cog.js +0 -13
  93. package/lib/glyph/DoubleAngle.js +0 -45
  94. package/lib/glyph/Download.js +0 -13
  95. package/lib/glyph/Ellipsis.js +0 -36
  96. package/lib/glyph/Envelope.js +0 -13
  97. package/lib/glyph/File.js +0 -37
  98. package/lib/glyph/IdCard.js +0 -13
  99. package/lib/glyph/Menu.js +0 -13
  100. package/lib/glyph/Minus.js +0 -13
  101. package/lib/glyph/Move.js +0 -13
  102. package/lib/glyph/Plus.js +0 -13
  103. package/lib/glyph/Square.js +0 -47
  104. package/lib/glyph/Teacher.js +0 -13
  105. package/lib/glyph/TextAlign.js +0 -53
  106. package/lib/glyph/Times.js +0 -36
  107. package/lib/glyph/WarningTriangle.js +0 -13
  108. package/lib/index.js +0 -1
  109. package/src-old/common/csvToString.js +0 -5
  110. package/src-old/common/isFloat.js +0 -3
  111. package/src-old/common/isInteger.js +0 -14
  112. package/src-old/common/math.js +0 -16
  113. package/src-old/common/validators.js +0 -14
  114. package/src-old/components/Alert.js +0 -79
  115. package/src-old/components/Button.js +0 -64
  116. package/src-old/components/CSV/autoMatch.js +0 -174
  117. package/src-old/components/CSV/getNumCols.js +0 -15
  118. package/src-old/components/CSV/index.js +0 -743
  119. package/src-old/components/Card.js +0 -64
  120. package/src-old/components/Chart/Bar.js +0 -169
  121. package/src-old/components/Chart/Donut.js +0 -160
  122. package/src-old/components/Chart/Histogram.js +0 -189
  123. package/src-old/components/Chart/Scatter.js +0 -162
  124. package/src-old/components/Chart/colors.js +0 -20
  125. package/src-old/components/Checkbox/index.js +0 -106
  126. package/src-old/components/Checkbox/style.css +0 -11
  127. package/src-old/components/DatePicker.js +0 -59
  128. package/src-old/components/DownloadButton.js +0 -72
  129. package/src-old/components/Dropdown.js +0 -120
  130. package/src-old/components/Layout/LeftAddon.js +0 -63
  131. package/src-old/components/Layout/RightAddon.js +0 -64
  132. package/src-old/components/Layout/TwoCol.js +0 -67
  133. package/src-old/components/Modal.js +0 -161
  134. package/src-old/components/PhotoRoster.js +0 -152
  135. package/src-old/components/Pills.js +0 -117
  136. package/src-old/components/Radio.js +0 -94
  137. package/src-old/components/Splash/Error.js +0 -62
  138. package/src-old/components/Splash/Load/index.js +0 -32
  139. package/src-old/components/Splash/Load/style.css +0 -51
  140. package/src-old/components/Stat/General.js +0 -252
  141. package/src-old/components/Stat/helpers/calcAverage.js +0 -20
  142. package/src-old/components/Stat/helpers/calcExtremes.js +0 -27
  143. package/src-old/components/Stat/helpers/calcMedian.js +0 -32
  144. package/src-old/components/Stat/helpers/calcStdDev.js +0 -30
  145. package/src-old/components/Stat/helpers/calcSum.js +0 -8
  146. package/src-old/components/UserProfile/index.js +0 -151
  147. package/src-old/components/UserProfile/style.css +0 -33
  148. package/src-old/components/Well.js +0 -28
  149. package/src-old/components/Wizard/Question/CSV.js +0 -307
  150. package/src-old/components/Wizard/Question/Chooser/Assignment.js +0 -108
  151. package/src-old/components/Wizard/Question/Chooser/Course.js +0 -214
  152. package/src-old/components/Wizard/Question/Chooser/helpers/divideIntoSections.js +0 -16
  153. package/src-old/components/Wizard/Question/Chooser/helpers/genGetItemsPromise.js +0 -20
  154. package/src-old/components/Wizard/Question/Chooser/helpers/preprocessSections.js +0 -36
  155. package/src-old/components/Wizard/Question/Chooser/index.js +0 -306
  156. package/src-old/components/Wizard/Question/Form/Field/CheckableItem.js +0 -155
  157. package/src-old/components/Wizard/Question/Form/Field/Input.js +0 -149
  158. package/src-old/components/Wizard/Question/Form/Field/NumberItem.js +0 -374
  159. package/src-old/components/Wizard/Question/Form/Field/index.js +0 -34
  160. package/src-old/components/Wizard/Question/Form/Field/readme.md +0 -7
  161. package/src-old/components/Wizard/Question/Form/index.js +0 -175
  162. package/src-old/components/Wizard/Question/Form/style.css +0 -3
  163. package/src-old/components/Wizard/Question/OneButton.js +0 -80
  164. package/src-old/components/Wizard/Question/index.js +0 -46
  165. package/src-old/components/Wizard/Question/readme.md +0 -10
  166. package/src-old/components/Wizard/QuestionGroup/AnswerAll.js +0 -126
  167. package/src-old/components/Wizard/QuestionGroup/AnswerAny.js +0 -60
  168. package/src-old/components/Wizard/index.js +0 -233
  169. package/src-old/components/Wizard/style.css +0 -21
  170. package/src-old/glyphs/Adjust.js +0 -13
  171. package/src-old/glyphs/Angle.js +0 -57
  172. package/src-old/glyphs/Archive.js +0 -13
  173. package/src-old/glyphs/Arrow.js +0 -85
  174. package/src-old/glyphs/ArrowsHorizontal.js +0 -13
  175. package/src-old/glyphs/ArrowsVertical.js +0 -13
  176. package/src-old/glyphs/Award.js +0 -13
  177. package/src-old/glyphs/Ban.js +0 -13
  178. package/src-old/glyphs/Barcode.js +0 -13
  179. package/src-old/glyphs/Bed.js +0 -13
  180. package/src-old/glyphs/Bell.js +0 -34
  181. package/src-old/glyphs/Bolt.js +0 -13
  182. package/src-old/glyphs/Bookmark.js +0 -36
  183. package/src-old/glyphs/Bug.js +0 -13
  184. package/src-old/glyphs/Calendar.js +0 -13
  185. package/src-old/glyphs/Check.js +0 -34
  186. package/src-old/glyphs/Checkbox.js +0 -42
  187. package/src-old/glyphs/Chevron.js +0 -88
  188. package/src-old/glyphs/Circle.js +0 -16
  189. package/src-old/glyphs/Cog.js +0 -13
  190. package/src-old/glyphs/DoubleAngle.js +0 -58
  191. package/src-old/glyphs/Download.js +0 -13
  192. package/src-old/glyphs/Ellipsis.js +0 -35
  193. package/src-old/glyphs/Envelope.js +0 -13
  194. package/src-old/glyphs/File.js +0 -40
  195. package/src-old/glyphs/IdCard.js +0 -13
  196. package/src-old/glyphs/Menu.js +0 -13
  197. package/src-old/glyphs/Minus.js +0 -13
  198. package/src-old/glyphs/Move.js +0 -13
  199. package/src-old/glyphs/Plus.js +0 -13
  200. package/src-old/glyphs/Square.js +0 -48
  201. package/src-old/glyphs/Teacher.js +0 -13
  202. package/src-old/glyphs/TextAlign.js +0 -58
  203. package/src-old/glyphs/Times.js +0 -34
  204. package/src-old/glyphs/WarningTriangle.js +0 -13
  205. package/src-old/index.js +0 -1
@@ -1,306 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
- import genUUID from 'uuid/v1';
4
-
5
- // Import other components
6
- import Question from '..';
7
- import ErrorSplash from '../../../Splash/Error';
8
- import LoadSplash from '../../../Splash/Load';
9
- import Well from '../../../Well';
10
- import Button from '../../../Button';
11
- import Dropdown from '../../../Dropdown';
12
- import RightAddonLayout from '../../../Layout/RightAddon';
13
-
14
- // Import glyphs
15
- import WarningTriangle from '../../../../glyphs/WarningTriangle';
16
- import Cog from '../../../../glyphs/Cog';
17
-
18
- // Import helper functions
19
- import genGetItemsPromise from './helpers/genGetItemsPromise';
20
- import divideIntoSections from './helpers/divideIntoSections';
21
- import preprocessSections from './helpers/preprocessSections';
22
-
23
- const STATUS = {
24
- LOADING: 'loading',
25
- ERROR: 'error',
26
- CHOOSING: 'choosing',
27
- };
28
-
29
- /**
30
- * onAnswered is called with the following:
31
- * {
32
- * dropdownItem: dropdownItems[].name OR undefined (if choose button clicked),
33
- * value: the chosen item
34
- * }
35
- */
36
-
37
- class Chooser extends Component {
38
- constructor(props) {
39
- super(props);
40
-
41
- // Initialize state
42
- this.state = {
43
- status: STATUS.LOADING,
44
- };
45
-
46
- // Bind functions
47
- this.onOptionChosen = this.onOptionChosen.bind(this);
48
- this.fetchOptions = this.fetchOptions.bind(this);
49
- }
50
-
51
- componentDidMount() {
52
- this.fetchOptions();
53
- }
54
-
55
- onOptionChosen(sectionIndex, optionIndex, itemName) {
56
- const { onAnswered } = this.props;
57
- const { sections } = this.state;
58
-
59
- if (sections) {
60
- onAnswered({
61
- dropdownItem: itemName,
62
- value: sections[sectionIndex].items[optionIndex],
63
- });
64
- }
65
- }
66
-
67
- fetchOptions() {
68
- // Set state
69
- this.setState({
70
- status: STATUS.LOADING,
71
- });
72
-
73
- // Deconstruct props
74
- const {
75
- items,
76
- getItems,
77
- } = this.props;
78
-
79
- // Wait for list of items
80
- genGetItemsPromise(items, getItems)
81
- .then((loadedOptions) => {
82
- const sections = divideIntoSections(loadedOptions);
83
- const preprocessedSections = preprocessSections(sections);
84
-
85
- // Save options to state
86
- this.setState({
87
- sections: preprocessedSections,
88
- status: STATUS.CHOOSING,
89
- });
90
- })
91
- .catch((err) => {
92
- // Error occurred while getting options
93
- this.setState({
94
- err,
95
- status: STATUS.ERROR,
96
- });
97
- });
98
- }
99
-
100
- render() {
101
- // Deconstruct state
102
- const {
103
- status,
104
- err,
105
- sections,
106
- } = this.state;
107
-
108
- // Deconstruct props
109
- const {
110
- title,
111
- subtitle,
112
- loadMessage,
113
- buttonTitle,
114
- buttonColor,
115
- dropdownTitle,
116
- dropdownColor,
117
- dropdownItems,
118
- } = this.props;
119
-
120
- let body;
121
-
122
- // Render error
123
- if (status === STATUS.ERROR) {
124
- const errorButtons = [{
125
- text: 'Try Again',
126
- color: 'primary',
127
- onClick: () => {
128
- this.fetchOptions();
129
- },
130
- }];
131
- body = (
132
- <ErrorSplash
133
- err={err}
134
- buttons={errorButtons}
135
- />
136
- );
137
- }
138
-
139
- // Render loading
140
- if (status === STATUS.LOADING) {
141
- body = (
142
- <LoadSplash
143
- message={loadMessage}
144
- />
145
- );
146
- }
147
-
148
- // Render options
149
- if (status === STATUS.CHOOSING) {
150
- let atLeastOneOption = false;
151
- const sectionElements = sections.map((section, sectionIndex) => {
152
- // Create all option elements in the section
153
- const optionWells = section.items.map((option, optionIndex) => {
154
- // Create option element
155
-
156
- let button;
157
- let dropdown;
158
- if (dropdownItems) {
159
- dropdown = (
160
- <Dropdown
161
- title={dropdownTitle || (
162
- <Cog />
163
- )}
164
- rightAligned
165
- inline
166
- color={dropdownColor}
167
- items={dropdownItems.map((item) => {
168
- return {
169
- text: item.text,
170
- divider: item.divider,
171
- header: item.header,
172
- disabled: item.disabled,
173
- onClick: () => {
174
- this.onOptionChosen(sectionIndex, optionIndex, item.name);
175
- },
176
- };
177
- })}
178
- />
179
- );
180
- }
181
- if (buttonTitle || buttonColor || !dropdownItems) {
182
- button = (
183
- <Button
184
- text={buttonTitle || 'Choose'}
185
- color={buttonColor || 'info'}
186
- className={dropdownItems ? 'mr-1' : null}
187
- onClick={() => {
188
- this.onOptionChosen(sectionIndex, optionIndex);
189
- }}
190
- title={`${buttonTitle} - ${option.title}`}
191
- />
192
- );
193
- }
194
-
195
- atLeastOneOption = true;
196
- return (
197
- <Well
198
- key={genUUID()}
199
- >
200
- <RightAddonLayout>
201
- <div>
202
- <h5>
203
- {option.title}
204
- </h5>
205
- {option.subtitle && (
206
- <p className="mb-0 mt-0">{option.subtitle}</p>
207
- )}
208
- </div>
209
- <div className="text-nowrap">
210
- {button}
211
- {dropdown}
212
- </div>
213
- </RightAddonLayout>
214
- </Well>
215
- );
216
- });
217
-
218
-
219
- // Create section element
220
- return (
221
- <div key={genUUID()}>
222
- {section.title && (
223
- <h5 className="text-center">
224
- {section.title}
225
- </h5>
226
- )}
227
- {optionWells}
228
- </div>
229
- );
230
- });
231
-
232
- if (atLeastOneOption) {
233
- body = (
234
- <div>
235
- {sectionElements}
236
- </div>
237
- );
238
- } else {
239
- body = (
240
- <div>
241
- <WarningTriangle />
242
- &nbsp;No options to choose from.
243
- </div>
244
- );
245
- }
246
- }
247
-
248
- return (
249
- <Question
250
- title={title}
251
- subtitle={subtitle}
252
- >
253
- {body}
254
- </Question>
255
- );
256
- }
257
- }
258
-
259
- Chooser.propTypes = {
260
- /* Title of the chooser */
261
- title: PropTypes.string,
262
- /* Subtitle of the chooser */
263
- subtitle: PropTypes.string,
264
- /* Handler for when the question is answered */
265
- onAnswered: PropTypes.func.isRequired,
266
- /* Message to display while loading items */
267
- loadMessage: PropTypes.string,
268
- /* Title of the "choose" button (also displayed if no dropdown) */
269
- buttonTitle: PropTypes.string,
270
- /* Color of the "choose" button (also displayed if no dropdown) */
271
- buttonColor: PropTypes.string,
272
- /* Title of the dropdown menu (not displayed if no dropdown items) */
273
- dropdownTitle: PropTypes.string,
274
- /* Color of the dropdown menu (not displayed if no dropdown items) */
275
- dropdownColor: PropTypes.string,
276
- /* Dropdown items (mostly same definition as those in /components/Dropdown)
277
- * but also an additional 'name' prop that is passed when the dropdown is
278
- * clicked. */
279
- dropdownItems: PropTypes.arrayOf(PropTypes.object),
280
- /* The list of items to display (this or getItems should be included) */
281
- items: PropTypes.oneOfType([
282
- PropTypes.arrayOf(PropTypes.object), /* The list of items */
283
- PropTypes.func, /* a function that returns the list of items */
284
- ]),
285
- /* A promise that resolves with the list of items (this or items should be
286
- * included) */
287
- getItems: PropTypes.oneOfType([
288
- PropTypes.instanceOf(Promise), /* Promise that resolves to items */
289
- PropTypes.func, /* a function that returns the Promise */
290
- ]),
291
- };
292
-
293
- Chooser.defaultProps = {
294
- title: 'Choose an Item:',
295
- subtitle: null,
296
- loadMessage: 'Loading Items',
297
- buttonTitle: 'Choose',
298
- buttonColor: 'info',
299
- dropdownTitle: null,
300
- dropdownColor: null,
301
- dropdownItems: null,
302
- items: null,
303
- getItems: null,
304
- };
305
-
306
- export default Chooser;
@@ -1,155 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- // Import bootstrap componenets
5
- import { FormFeedback } from 'reactstrap';
6
- // Import bootstrap stylesheet
7
- import 'bootstrap/dist/css/bootstrap.min.css';
8
-
9
- // Import other components
10
- import Field from '.';
11
- import Checkbox from '../../../../Checkbox';
12
- import Well from '../../../../Well';
13
- import LeftAddon from '../../../../Layout/LeftAddon';
14
-
15
- class CheckableItem extends Component {
16
- constructor(props) {
17
- super(props);
18
-
19
- // Deconstruct props
20
- const {
21
- onChange,
22
- startChecked,
23
- required,
24
- } = this.props;
25
-
26
- const checked = startChecked;
27
- const haltSubmit = (required && !startChecked);
28
-
29
- // Create initial state
30
- this.state = {
31
- haltSubmit, // Halt submission until checked (if required)
32
- };
33
-
34
- // Bind functions
35
- this.onCheckboxChange = this.onCheckboxChange.bind(this);
36
-
37
- // Update parent
38
- onChange(checked, haltSubmit);
39
- }
40
-
41
- onCheckboxChange(checked) {
42
- // Send answer to onChange listener
43
- const {
44
- onChange,
45
- required,
46
- } = this.props;
47
-
48
- // Validation
49
- const haltSubmit = (required && !checked);
50
-
51
- // Update state
52
- this.setState({
53
- haltSubmit,
54
- });
55
-
56
- // Update handler
57
- onChange(checked, haltSubmit);
58
- }
59
-
60
- render() {
61
- // Deconstruct props
62
- const {
63
- title,
64
- name,
65
- subtitle,
66
- startChecked,
67
- children,
68
- } = this.props;
69
-
70
- // Deconstruct state
71
- const { haltSubmit } = this.state;
72
-
73
- // Create content
74
- let content = children;
75
- if (!content) {
76
- if (title || subtitle) {
77
- content = (
78
- <div>
79
- <h5 className="mb-0">
80
- {title}
81
- </h5>
82
- {subtitle && (
83
- <p className="mb-0 mt-2">{subtitle}</p>
84
- )}
85
- </div>
86
- );
87
- } else {
88
- content = (
89
- <h5 className="mb-0">
90
- Unnamed Item
91
- </h5>
92
- );
93
- }
94
- }
95
-
96
- // Render the field
97
- return (
98
- <Field name={name}>
99
- <Well
100
- className={`p-2 border mb-0${haltSubmit ? ' border-danger' : ' border-secondary'}`}
101
- >
102
- <LeftAddon
103
- centerVertically
104
- >
105
- <Checkbox
106
- onChange={this.onCheckboxChange}
107
- startChecked={startChecked}
108
- />
109
- <div
110
- className="ml-2"
111
- >
112
- {content}
113
- </div>
114
- </LeftAddon>
115
- </Well>
116
- <FormFeedback
117
- className={haltSubmit ? 'd-block' : null}
118
- >
119
- This needs to be checked
120
- </FormFeedback>
121
- </Field>
122
- );
123
- }
124
- }
125
-
126
- CheckableItem.propTypes = {
127
- /* Title of the number item (replaced by children if children are included) */
128
- title: PropTypes.string,
129
- /* The field name (to be used as a key in the form) */
130
- name: PropTypes.string.isRequired,
131
- /* Subtitle of the item (replaced by children if children are included) */
132
- subtitle: PropTypes.string,
133
- /* Handler to call when checkbox is toggled */
134
- onChange: PropTypes.func,
135
- /* If true, checkbox starts checked */
136
- startChecked: PropTypes.bool,
137
- /* If true, checkbox must be checked to submit the form */
138
- required: PropTypes.bool,
139
- /* The children of this component (displayed as content) */
140
- children: PropTypes.oneOfType([
141
- PropTypes.arrayOf(PropTypes.node),
142
- PropTypes.node,
143
- ]),
144
- };
145
-
146
- CheckableItem.defaultProps = {
147
- title: null,
148
- subtitle: null,
149
- onChange: () => {},
150
- startChecked: false,
151
- required: false,
152
- children: null,
153
- };
154
-
155
- export default CheckableItem;
@@ -1,149 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- // Import bootstrap components
5
- import {
6
- InputGroup,
7
- InputGroupText,
8
- InputGroupAddon,
9
- Input as BootstrapInput,
10
- FormFeedback,
11
- } from 'reactstrap';
12
- // Import bootstrap stylesheet
13
- import 'bootstrap/dist/css/bootstrap.min.css';
14
-
15
- // Import other componenets
16
- import Field from '.';
17
-
18
- class Input extends Component {
19
- constructor(props) {
20
- super(props);
21
-
22
- // Deconstruct props
23
- const {
24
- onChange,
25
- required,
26
- } = this.props;
27
-
28
- const answer = '';
29
- const haltSubmit = required;
30
-
31
- // Create initial state
32
- this.state = {
33
- haltSubmit, // Halt submission until required has passed
34
- answer,
35
- };
36
-
37
- // Bind functions
38
- this.onUpdate = this.onUpdate.bind(this);
39
-
40
- // Update parent
41
- onChange(answer, haltSubmit);
42
- }
43
-
44
- onUpdate(event) {
45
- // Deconstruct props
46
- const {
47
- onChange,
48
- required,
49
- } = this.props;
50
-
51
- // Extract value from event
52
- const answer = event.target.value;
53
-
54
- // Validation
55
- const haltSubmit = (
56
- required
57
- && (
58
- !answer
59
- || answer.trim().length === 0
60
- )
61
- );
62
-
63
- // Update state
64
- this.setState({
65
- haltSubmit,
66
- answer,
67
- });
68
-
69
- // Send answer to onChange listener
70
- onChange(answer, haltSubmit);
71
- }
72
-
73
- render() {
74
- // Deconstruct props
75
- const {
76
- name,
77
- leftLabel,
78
- rightLabel,
79
- placeholder,
80
- } = this.props;
81
-
82
- // Deconstruct state
83
- const {
84
- haltSubmit,
85
- answer,
86
- } = this.state;
87
-
88
- // Create input item
89
- const input = (
90
- <BootstrapInput
91
- invalid={haltSubmit}
92
- placeholder={placeholder}
93
- value={answer}
94
- onChange={this.onUpdate}
95
- />
96
- );
97
-
98
- // Render a chooser
99
- return (
100
- <Field name={name}>
101
- <InputGroup>
102
- {leftLabel && (
103
- <InputGroupAddon addonType="prepend">
104
- <InputGroupText>
105
- {leftLabel}
106
- </InputGroupText>
107
- </InputGroupAddon>
108
- )}
109
- {input}
110
- {rightLabel && (
111
- <InputGroupAddon addonType="append">
112
- <InputGroupText>
113
- {rightLabel}
114
- </InputGroupText>
115
- </InputGroupAddon>
116
- )}
117
- <FormFeedback>
118
- This field is required
119
- </FormFeedback>
120
- </InputGroup>
121
- </Field>
122
- );
123
- }
124
- }
125
-
126
- Input.propTypes = {
127
- /* The field name (to be used as a key in the form) */
128
- name: PropTypes.string.isRequired,
129
- /* A label string to display to the left of the input field */
130
- leftLabel: PropTypes.string,
131
- /* A label string to display to the right of the input field */
132
- rightLabel: PropTypes.string,
133
- /* Placeholder text for the input field */
134
- placeholder: PropTypes.string,
135
- /* Handler to call when the text is changed */
136
- onChange: PropTypes.func,
137
- /* If true, field is required for the form to be submitted */
138
- required: PropTypes.bool,
139
- };
140
-
141
- Input.defaultProps = {
142
- leftLabel: null,
143
- rightLabel: null,
144
- placeholder: '',
145
- onChange: () => {},
146
- required: false,
147
- };
148
-
149
- export default Input;