@jsonforms/material-renderers 3.0.0-alpha.1 → 3.0.0-alpha.2

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 (293) hide show
  1. package/docs/assets/js/search.json +1 -1
  2. package/docs/classes/combinatorproperties.html +2 -5
  3. package/docs/classes/materialanyofstringorenumcontrol.html +6 -9
  4. package/docs/classes/materialtablecontrol.html +4 -7
  5. package/docs/globals.html +803 -213
  6. package/docs/index.html +63 -42
  7. package/docs/interfaces/ajvprops.html +1 -4
  8. package/docs/interfaces/arraylayouttoolbarprops.html +0 -3
  9. package/docs/interfaces/categorizationstate.html +0 -3
  10. package/docs/interfaces/categorizationstepperstate.html +0 -3
  11. package/docs/interfaces/combinatorpropertiesprops.html +0 -3
  12. package/docs/interfaces/deletedialogprops.html +0 -3
  13. package/docs/interfaces/dispatchpropsofexpandpanel.html +3 -6
  14. package/docs/interfaces/emptytableprops.html +0 -3
  15. package/docs/interfaces/expandpanelprops.html +19 -22
  16. package/docs/interfaces/jsonformstheme.html +0 -3
  17. package/docs/interfaces/materialcategorizationlayoutrendererprops.html +1 -4
  18. package/docs/interfaces/materialcategorizationstepperlayoutrendererprops.html +1 -4
  19. package/docs/interfaces/materiallayoutrendererprops.html +0 -3
  20. package/docs/interfaces/materialtabletoolbarprops.html +0 -3
  21. package/docs/interfaces/muitextinputprops.html +2 -5
  22. package/docs/interfaces/nonemptycellcomponentprops.html +266 -0
  23. package/docs/interfaces/nonemptycellprops.html +0 -3
  24. package/docs/interfaces/nonemptyrowprops.html +80 -27
  25. package/docs/interfaces/ownoneofprops.html +0 -3
  26. package/docs/interfaces/ownpropsofexpandpanel.html +14 -17
  27. package/docs/interfaces/ownpropsofnonemptycell.html +0 -3
  28. package/docs/interfaces/statepropsofexpandpanel.html +16 -19
  29. package/docs/interfaces/tableheadercellprops.html +0 -3
  30. package/docs/interfaces/tablerowsprop.html +9 -12
  31. package/docs/interfaces/validationprops.html +0 -3
  32. package/docs/interfaces/withdeletedialogsupport.html +0 -3
  33. package/docs/interfaces/withinput.html +1 -4
  34. package/docs/interfaces/withoptionlabel.html +3 -6
  35. package/lib/additional/ListWithDetailMasterItem.d.ts +1 -1
  36. package/lib/additional/ListWithDetailMasterItem.js.map +1 -1
  37. package/lib/additional/MaterialLabelRenderer.d.ts +1 -1
  38. package/lib/additional/MaterialLabelRenderer.js +3 -1
  39. package/lib/additional/MaterialLabelRenderer.js.map +1 -1
  40. package/lib/additional/MaterialListWithDetailRenderer.d.ts +1 -1
  41. package/lib/additional/MaterialListWithDetailRenderer.js +3 -1
  42. package/lib/additional/MaterialListWithDetailRenderer.js.map +1 -1
  43. package/lib/additional/index.js +3 -2
  44. package/lib/additional/index.js.map +1 -1
  45. package/lib/cells/CustomizableCells.js +10 -9
  46. package/lib/cells/CustomizableCells.js.map +1 -1
  47. package/lib/cells/MaterialBooleanCell.d.ts +1 -1
  48. package/lib/cells/MaterialBooleanCell.js +3 -1
  49. package/lib/cells/MaterialBooleanCell.js.map +1 -1
  50. package/lib/cells/MaterialBooleanToggleCell.d.ts +1 -1
  51. package/lib/cells/MaterialBooleanToggleCell.js +3 -1
  52. package/lib/cells/MaterialBooleanToggleCell.js.map +1 -1
  53. package/lib/cells/MaterialDateCell.d.ts +1 -1
  54. package/lib/cells/MaterialDateCell.js +3 -1
  55. package/lib/cells/MaterialDateCell.js.map +1 -1
  56. package/lib/cells/MaterialEnumCell.d.ts +1 -1
  57. package/lib/cells/MaterialEnumCell.js +3 -1
  58. package/lib/cells/MaterialEnumCell.js.map +1 -1
  59. package/lib/cells/MaterialIntegerCell.d.ts +1 -1
  60. package/lib/cells/MaterialIntegerCell.js +3 -1
  61. package/lib/cells/MaterialIntegerCell.js.map +1 -1
  62. package/lib/cells/MaterialNumberCell.d.ts +1 -1
  63. package/lib/cells/MaterialNumberCell.js +3 -1
  64. package/lib/cells/MaterialNumberCell.js.map +1 -1
  65. package/lib/cells/MaterialNumberFormatCell.d.ts +1 -1
  66. package/lib/cells/MaterialNumberFormatCell.js +3 -1
  67. package/lib/cells/MaterialNumberFormatCell.js.map +1 -1
  68. package/lib/cells/MaterialOneOfEnumCell.d.ts +1 -1
  69. package/lib/cells/MaterialOneOfEnumCell.js +3 -1
  70. package/lib/cells/MaterialOneOfEnumCell.js.map +1 -1
  71. package/lib/cells/MaterialTextCell.d.ts +1 -1
  72. package/lib/cells/MaterialTextCell.js +3 -1
  73. package/lib/cells/MaterialTextCell.js.map +1 -1
  74. package/lib/cells/MaterialTimeCell.d.ts +1 -1
  75. package/lib/cells/MaterialTimeCell.js +3 -1
  76. package/lib/cells/MaterialTimeCell.js.map +1 -1
  77. package/lib/cells/index.js +11 -10
  78. package/lib/cells/index.js.map +1 -1
  79. package/lib/complex/CombinatorProperties.js +3 -1
  80. package/lib/complex/CombinatorProperties.js.map +1 -1
  81. package/lib/complex/DeleteDialog.js +1 -0
  82. package/lib/complex/DeleteDialog.js.map +1 -1
  83. package/lib/complex/MaterialAllOfRenderer.d.ts +3 -2
  84. package/lib/complex/MaterialAllOfRenderer.js +3 -1
  85. package/lib/complex/MaterialAllOfRenderer.js.map +1 -1
  86. package/lib/complex/MaterialAnyOfRenderer.d.ts +3 -2
  87. package/lib/complex/MaterialAnyOfRenderer.js +3 -1
  88. package/lib/complex/MaterialAnyOfRenderer.js.map +1 -1
  89. package/lib/complex/MaterialArrayControlRenderer.d.ts +1 -1
  90. package/lib/complex/MaterialArrayControlRenderer.js +3 -1
  91. package/lib/complex/MaterialArrayControlRenderer.js.map +1 -1
  92. package/lib/complex/MaterialEnumArrayRenderer.d.ts +2 -2
  93. package/lib/complex/MaterialEnumArrayRenderer.js +6 -3
  94. package/lib/complex/MaterialEnumArrayRenderer.js.map +1 -1
  95. package/lib/complex/MaterialObjectRenderer.d.ts +3 -2
  96. package/lib/complex/MaterialObjectRenderer.js +3 -1
  97. package/lib/complex/MaterialObjectRenderer.js.map +1 -1
  98. package/lib/complex/MaterialOneOfRenderer.d.ts +2 -1
  99. package/lib/complex/MaterialOneOfRenderer.js +5 -4
  100. package/lib/complex/MaterialOneOfRenderer.js.map +1 -1
  101. package/lib/complex/MaterialTableControl.d.ts +16 -1
  102. package/lib/complex/MaterialTableControl.js +16 -8
  103. package/lib/complex/MaterialTableControl.js.map +1 -1
  104. package/lib/complex/NoBorderTableCell.js.map +1 -1
  105. package/lib/complex/TableToolbar.js.map +1 -1
  106. package/lib/complex/ValidationIcon.d.ts +5 -3
  107. package/lib/complex/ValidationIcon.js.map +1 -1
  108. package/lib/complex/index.js +6 -5
  109. package/lib/complex/index.js.map +1 -1
  110. package/lib/controls/MaterialAnyOfStringOrEnumControl.d.ts +1 -1
  111. package/lib/controls/MaterialAnyOfStringOrEnumControl.js +17 -12
  112. package/lib/controls/MaterialAnyOfStringOrEnumControl.js.map +1 -1
  113. package/lib/controls/MaterialBooleanControl.d.ts +1 -1
  114. package/lib/controls/MaterialBooleanControl.js +3 -1
  115. package/lib/controls/MaterialBooleanControl.js.map +1 -1
  116. package/lib/controls/MaterialBooleanToggleControl.d.ts +1 -1
  117. package/lib/controls/MaterialBooleanToggleControl.js +3 -1
  118. package/lib/controls/MaterialBooleanToggleControl.js.map +1 -1
  119. package/lib/controls/MaterialDateControl.d.ts +3 -6
  120. package/lib/controls/MaterialDateControl.js +25 -29
  121. package/lib/controls/MaterialDateControl.js.map +1 -1
  122. package/lib/controls/MaterialDateTimeControl.d.ts +3 -6
  123. package/lib/controls/MaterialDateTimeControl.js +25 -29
  124. package/lib/controls/MaterialDateTimeControl.js.map +1 -1
  125. package/lib/controls/MaterialEnumControl.d.ts +1 -1
  126. package/lib/controls/MaterialEnumControl.js +3 -1
  127. package/lib/controls/MaterialEnumControl.js.map +1 -1
  128. package/lib/controls/MaterialInputControl.d.ts +2 -5
  129. package/lib/controls/MaterialInputControl.js +23 -28
  130. package/lib/controls/MaterialInputControl.js.map +1 -1
  131. package/lib/controls/MaterialIntegerControl.d.ts +1 -1
  132. package/lib/controls/MaterialIntegerControl.js +3 -1
  133. package/lib/controls/MaterialIntegerControl.js.map +1 -1
  134. package/lib/controls/MaterialNativeControl.d.ts +3 -6
  135. package/lib/controls/MaterialNativeControl.js +15 -19
  136. package/lib/controls/MaterialNativeControl.js.map +1 -1
  137. package/lib/controls/MaterialNumberControl.d.ts +1 -1
  138. package/lib/controls/MaterialNumberControl.js +3 -1
  139. package/lib/controls/MaterialNumberControl.js.map +1 -1
  140. package/lib/controls/MaterialOneOfEnumControl.d.ts +1 -1
  141. package/lib/controls/MaterialOneOfEnumControl.js +3 -1
  142. package/lib/controls/MaterialOneOfEnumControl.js.map +1 -1
  143. package/lib/controls/MaterialOneOfRadioGroupControl.d.ts +1 -1
  144. package/lib/controls/MaterialOneOfRadioGroupControl.js +3 -1
  145. package/lib/controls/MaterialOneOfRadioGroupControl.js.map +1 -1
  146. package/lib/controls/MaterialRadioGroup.d.ts +2 -5
  147. package/lib/controls/MaterialRadioGroup.js +15 -20
  148. package/lib/controls/MaterialRadioGroup.js.map +1 -1
  149. package/lib/controls/MaterialRadioGroupControl.d.ts +1 -1
  150. package/lib/controls/MaterialRadioGroupControl.js +3 -1
  151. package/lib/controls/MaterialRadioGroupControl.js.map +1 -1
  152. package/lib/controls/MaterialSliderControl.d.ts +3 -6
  153. package/lib/controls/MaterialSliderControl.js +35 -39
  154. package/lib/controls/MaterialSliderControl.js.map +1 -1
  155. package/lib/controls/MaterialTextControl.d.ts +1 -1
  156. package/lib/controls/MaterialTextControl.js +3 -1
  157. package/lib/controls/MaterialTextControl.js.map +1 -1
  158. package/lib/controls/MaterialTimeControl.d.ts +3 -6
  159. package/lib/controls/MaterialTimeControl.js +25 -29
  160. package/lib/controls/MaterialTimeControl.js.map +1 -1
  161. package/lib/controls/index.d.ts +10 -10
  162. package/lib/controls/index.js +16 -15
  163. package/lib/controls/index.js.map +1 -1
  164. package/lib/extended/MaterialAutocompleteEnumControl.d.ts +1 -1
  165. package/lib/extended/MaterialAutocompleteEnumControl.js +3 -1
  166. package/lib/extended/MaterialAutocompleteEnumControl.js.map +1 -1
  167. package/lib/extended/MaterialAutocompleteOneOfEnumControl.d.ts +1 -1
  168. package/lib/extended/MaterialAutocompleteOneOfEnumControl.js +3 -1
  169. package/lib/extended/MaterialAutocompleteOneOfEnumControl.js.map +1 -1
  170. package/lib/extended/MuiAutocomplete.d.ts +2 -2
  171. package/lib/extended/MuiAutocomplete.js +4 -3
  172. package/lib/extended/MuiAutocomplete.js.map +1 -1
  173. package/lib/extended/index.d.ts +2 -2
  174. package/lib/extended/index.js +2 -1
  175. package/lib/extended/index.js.map +1 -1
  176. package/lib/index.js +1 -0
  177. package/lib/index.js.map +1 -1
  178. package/lib/jsonforms-material.js +8 -8
  179. package/lib/jsonforms-material.js.map +1 -1
  180. package/lib/layouts/ArrayToolbar.js +1 -0
  181. package/lib/layouts/ArrayToolbar.js.map +1 -1
  182. package/lib/layouts/ExpandPanelRenderer.d.ts +3 -3
  183. package/lib/layouts/ExpandPanelRenderer.js +16 -13
  184. package/lib/layouts/ExpandPanelRenderer.js.map +1 -1
  185. package/lib/layouts/MaterialArrayLayout.d.ts +1 -11
  186. package/lib/layouts/MaterialArrayLayout.js +19 -31
  187. package/lib/layouts/MaterialArrayLayout.js.map +1 -1
  188. package/lib/layouts/MaterialArrayLayoutRenderer.d.ts +1 -1
  189. package/lib/layouts/MaterialArrayLayoutRenderer.js +3 -1
  190. package/lib/layouts/MaterialArrayLayoutRenderer.js.map +1 -1
  191. package/lib/layouts/MaterialCategorizationLayout.d.ts +2 -10
  192. package/lib/layouts/MaterialCategorizationLayout.js +31 -47
  193. package/lib/layouts/MaterialCategorizationLayout.js.map +1 -1
  194. package/lib/layouts/MaterialCategorizationStepperLayout.d.ts +2 -9
  195. package/lib/layouts/MaterialCategorizationStepperLayout.js +42 -53
  196. package/lib/layouts/MaterialCategorizationStepperLayout.js.map +1 -1
  197. package/lib/layouts/MaterialGroupLayout.d.ts +1 -1
  198. package/lib/layouts/MaterialGroupLayout.js +3 -1
  199. package/lib/layouts/MaterialGroupLayout.js.map +1 -1
  200. package/lib/layouts/MaterialHorizontalLayout.d.ts +1 -1
  201. package/lib/layouts/MaterialHorizontalLayout.js +3 -1
  202. package/lib/layouts/MaterialHorizontalLayout.js.map +1 -1
  203. package/lib/layouts/MaterialVerticalLayout.d.ts +1 -1
  204. package/lib/layouts/MaterialVerticalLayout.js +3 -1
  205. package/lib/layouts/MaterialVerticalLayout.js.map +1 -1
  206. package/lib/layouts/index.js +6 -5
  207. package/lib/layouts/index.js.map +1 -1
  208. package/lib/mui-controls/MuiCheckbox.js +2 -2
  209. package/lib/mui-controls/MuiCheckbox.js.map +1 -1
  210. package/lib/mui-controls/MuiInputInteger.js +9 -6
  211. package/lib/mui-controls/MuiInputInteger.js.map +1 -1
  212. package/lib/mui-controls/MuiInputNumber.js +9 -6
  213. package/lib/mui-controls/MuiInputNumber.js.map +1 -1
  214. package/lib/mui-controls/MuiInputNumberFormat.js +7 -8
  215. package/lib/mui-controls/MuiInputNumberFormat.js.map +1 -1
  216. package/lib/mui-controls/MuiInputText.js +11 -7
  217. package/lib/mui-controls/MuiInputText.js.map +1 -1
  218. package/lib/mui-controls/MuiInputTime.js +5 -3
  219. package/lib/mui-controls/MuiInputTime.js.map +1 -1
  220. package/lib/mui-controls/MuiSelect.js +3 -3
  221. package/lib/mui-controls/MuiSelect.js.map +1 -1
  222. package/lib/mui-controls/MuiToggle.js +2 -2
  223. package/lib/mui-controls/MuiToggle.js.map +1 -1
  224. package/lib/util/datejs.d.ts +2 -2
  225. package/lib/util/datejs.js +5 -2
  226. package/lib/util/datejs.js.map +1 -1
  227. package/lib/util/debounce.d.ts +1 -0
  228. package/lib/util/debounce.js +48 -0
  229. package/lib/util/debounce.js.map +1 -0
  230. package/lib/util/focus.d.ts +1 -0
  231. package/lib/util/focus.js +36 -0
  232. package/lib/util/focus.js.map +1 -0
  233. package/lib/util/index.d.ts +2 -0
  234. package/lib/util/index.js +3 -0
  235. package/lib/util/index.js.map +1 -1
  236. package/lib/util/layout.d.ts +2 -1
  237. package/lib/util/layout.js +8 -4
  238. package/lib/util/layout.js.map +1 -1
  239. package/package.json +5 -5
  240. package/src/cells/MaterialTimeCell.tsx +1 -0
  241. package/src/complex/MaterialAllOfRenderer.tsx +2 -1
  242. package/src/complex/MaterialAnyOfRenderer.tsx +2 -1
  243. package/src/complex/MaterialEnumArrayRenderer.tsx +1 -0
  244. package/src/complex/MaterialObjectRenderer.tsx +2 -1
  245. package/src/complex/MaterialOneOfRenderer.tsx +6 -6
  246. package/src/complex/MaterialTableControl.tsx +36 -24
  247. package/src/controls/MaterialAnyOfStringOrEnumControl.tsx +16 -12
  248. package/src/controls/MaterialDateControl.tsx +80 -85
  249. package/src/controls/MaterialDateTimeControl.tsx +83 -86
  250. package/src/controls/MaterialInputControl.tsx +62 -69
  251. package/src/controls/MaterialNativeControl.tsx +54 -57
  252. package/src/controls/MaterialRadioGroup.tsx +67 -69
  253. package/src/controls/MaterialSliderControl.tsx +92 -87
  254. package/src/controls/MaterialTimeControl.tsx +77 -80
  255. package/src/extended/MuiAutocomplete.tsx +2 -3
  256. package/src/layouts/ExpandPanelRenderer.tsx +11 -17
  257. package/src/layouts/MaterialArrayLayout.tsx +73 -82
  258. package/src/layouts/MaterialCategorizationLayout.tsx +49 -65
  259. package/src/layouts/MaterialCategorizationStepperLayout.tsx +79 -87
  260. package/src/mui-controls/MuiCheckbox.tsx +1 -2
  261. package/src/mui-controls/MuiInputInteger.tsx +12 -9
  262. package/src/mui-controls/MuiInputNumber.tsx +9 -6
  263. package/src/mui-controls/MuiInputNumberFormat.tsx +8 -11
  264. package/src/mui-controls/MuiInputText.tsx +17 -15
  265. package/src/mui-controls/MuiInputTime.tsx +6 -4
  266. package/src/mui-controls/MuiSelect.tsx +2 -3
  267. package/src/mui-controls/MuiToggle.tsx +1 -2
  268. package/src/util/debounce.ts +43 -0
  269. package/src/util/focus.ts +32 -0
  270. package/src/util/index.ts +2 -0
  271. package/src/util/layout.tsx +5 -6
  272. package/test/renderers/MaterialAnyOfRenderer.test.tsx +14 -8
  273. package/test/renderers/MaterialArrayLayout.test.tsx +6 -6
  274. package/test/renderers/MaterialCategorizationLayout.test.tsx +73 -0
  275. package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +73 -0
  276. package/test/renderers/MaterialInputControl.test.tsx +3 -3
  277. package/test/renderers/MaterialIntegerCell.test.tsx +41 -20
  278. package/test/renderers/MaterialNumberCell.test.tsx +45 -24
  279. package/test/renderers/MaterialOneOfRenderer.test.tsx +7 -4
  280. package/test/renderers/MaterialTextCell.test.tsx +41 -20
  281. package/test/renderers/MaterialTimeCell.test.tsx +41 -20
  282. package/test/renderers/MaterialTimeControl.test.tsx +3 -3
  283. package/docs/classes/materialarraylayout.html +0 -777
  284. package/docs/classes/materialcategorizationlayoutrenderer.html +0 -786
  285. package/docs/classes/materialcategorizationstepperlayoutrenderer.html +0 -762
  286. package/docs/classes/materialdatecontrol.html +0 -825
  287. package/docs/classes/materialdatetimecontrol.html +0 -825
  288. package/docs/classes/materialinputcontrol.html +0 -825
  289. package/docs/classes/materialnativecontrol.html +0 -825
  290. package/docs/classes/materialradiogroup.html +0 -825
  291. package/docs/classes/materialslidercontrol.html +0 -825
  292. package/docs/classes/materialtimecontrol.html +0 -825
  293. package/docs/interfaces/materialarraylayoutstate.html +0 -157
@@ -22,17 +22,16 @@
22
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
23
  THE SOFTWARE.
24
24
  */
25
- import React from 'react';
25
+ import React, { useMemo } from 'react';
26
26
  import merge from 'lodash/merge';
27
27
  import {
28
28
  ControlProps,
29
- ControlState,
30
29
  isDateTimeControl,
31
30
  isDescriptionHidden,
32
31
  RankedTester,
33
32
  rankWith
34
33
  } from '@jsonforms/core';
35
- import { Control, withJsonFormsControlProps } from '@jsonforms/react';
34
+ import { withJsonFormsControlProps } from '@jsonforms/react';
36
35
  import { FormHelperText, Hidden } from '@material-ui/core';
37
36
  import KeyboardArrowLeftIcon from '@material-ui/icons/KeyboardArrowLeft';
38
37
  import KeyboardArrowRightIcon from '@material-ui/icons/KeyboardArrowRight';
@@ -44,94 +43,92 @@ import {
44
43
  MuiPickersUtilsProvider
45
44
  } from '@material-ui/pickers';
46
45
  import DayjsUtils from '@date-io/dayjs';
47
- import { createOnChangeHandler, getData } from '../util';
46
+ import { createOnChangeHandler, getData, useFocus } from '../util';
48
47
 
49
- export class MaterialDateTimeControl extends Control<
50
- ControlProps,
51
- ControlState
52
- > {
53
- render() {
54
- const {
55
- id,
56
- description,
57
- errors,
58
- label,
59
- uischema,
60
- visible,
61
- enabled,
62
- required,
63
- path,
64
- handleChange,
65
- data,
66
- config
67
- } = this.props;
68
- const appliedUiSchemaOptions = merge({}, config, uischema.options);
69
- const isValid = errors.length === 0;
48
+ export const MaterialDateTimeControl = (props: ControlProps) => {
49
+ const [focused, onFocus, onBlur] = useFocus();
50
+ const {
51
+ id,
52
+ description,
53
+ errors,
54
+ label,
55
+ uischema,
56
+ visible,
57
+ enabled,
58
+ required,
59
+ path,
60
+ handleChange,
61
+ data,
62
+ config
63
+ } = props;
64
+ const appliedUiSchemaOptions = merge({}, config, uischema.options);
65
+ const isValid = errors.length === 0;
66
+
67
+ const showDescription = !isDescriptionHidden(
68
+ visible,
69
+ description,
70
+ focused,
71
+ appliedUiSchemaOptions.showUnfocusedDescription
72
+ );
70
73
 
71
- const showDescription = !isDescriptionHidden(
72
- visible,
73
- description,
74
- this.state.isFocused,
75
- appliedUiSchemaOptions.showUnfocusedDescription
76
- );
74
+ const format = appliedUiSchemaOptions.dateTimeFormat ?? 'YYYY-MM-DD HH:mm';
75
+ const saveFormat = appliedUiSchemaOptions.dateTimeSaveFormat ?? undefined;
77
76
 
78
- const format = appliedUiSchemaOptions.dateTimeFormat ?? 'YYYY-MM-DD HH:mm';
79
- const saveFormat = appliedUiSchemaOptions.dateTimeSaveFormat ?? undefined;
77
+ const firstFormHelperText = showDescription
78
+ ? description
79
+ : !isValid
80
+ ? errors
81
+ : null;
82
+ const secondFormHelperText = showDescription && !isValid ? errors : null;
80
83
 
81
- const firstFormHelperText = showDescription
82
- ? description
83
- : !isValid
84
- ? errors
85
- : null;
86
- const secondFormHelperText = showDescription && !isValid ? errors : null;
84
+ const onChange = useMemo(() => createOnChangeHandler(
85
+ path,
86
+ handleChange,
87
+ saveFormat
88
+ ),[path, handleChange, saveFormat]);
87
89
 
88
- return (
89
- <Hidden xsUp={!visible}>
90
- <MuiPickersUtilsProvider utils={DayjsUtils}>
91
- <KeyboardDateTimePicker
92
- id={id + '-input'}
93
- required={required && !appliedUiSchemaOptions.hideRequiredAsterisk}
94
- label={label}
95
- error={!isValid}
96
- fullWidth={!appliedUiSchemaOptions.trim}
97
- onFocus={this.onFocus}
98
- onBlur={this.onBlur}
99
- InputLabelProps={data ? { shrink: true } : undefined}
100
- value={getData(data, saveFormat)}
101
- clearable
102
- onChange={createOnChangeHandler(
103
- path,
104
- handleChange,
105
- saveFormat
106
- )}
107
- format={format}
108
- ampm={!!appliedUiSchemaOptions.ampm}
109
- views={appliedUiSchemaOptions.views}
110
- disabled={!enabled}
111
- autoFocus={appliedUiSchemaOptions.focus}
112
- cancelLabel={appliedUiSchemaOptions.cancelLabel}
113
- clearLabel={appliedUiSchemaOptions.clearLabel}
114
- okLabel={appliedUiSchemaOptions.okLabel}
115
- leftArrowIcon={<KeyboardArrowLeftIcon />}
116
- rightArrowIcon={<KeyboardArrowRightIcon />}
117
- dateRangeIcon={<DateRangeIcon />}
118
- keyboardIcon={<EventIcon />}
119
- timeIcon={<AccessTimeIcon />}
120
- invalidDateMessage={null}
121
- maxDateMessage={null}
122
- minDateMessage={null}
123
- />
124
- <FormHelperText error={!isValid && !showDescription}>
125
- {firstFormHelperText}
126
- </FormHelperText>
127
- <FormHelperText error={!isValid}>
128
- {secondFormHelperText}
129
- </FormHelperText>
130
- </MuiPickersUtilsProvider>
131
- </Hidden>
132
- );
133
- }
134
- }
90
+ return (
91
+ <Hidden xsUp={!visible}>
92
+ <MuiPickersUtilsProvider utils={DayjsUtils}>
93
+ <KeyboardDateTimePicker
94
+ id={id + '-input'}
95
+ required={required && !appliedUiSchemaOptions.hideRequiredAsterisk}
96
+ label={label}
97
+ error={!isValid}
98
+ fullWidth={!appliedUiSchemaOptions.trim}
99
+ onFocus={onFocus}
100
+ onBlur={onBlur}
101
+ InputLabelProps={data ? { shrink: true } : undefined}
102
+ value={getData(data, saveFormat)}
103
+ clearable
104
+ onChange={onChange}
105
+ format={format}
106
+ ampm={!!appliedUiSchemaOptions.ampm}
107
+ views={appliedUiSchemaOptions.views}
108
+ disabled={!enabled}
109
+ autoFocus={appliedUiSchemaOptions.focus}
110
+ cancelLabel={appliedUiSchemaOptions.cancelLabel}
111
+ clearLabel={appliedUiSchemaOptions.clearLabel}
112
+ okLabel={appliedUiSchemaOptions.okLabel}
113
+ leftArrowIcon={<KeyboardArrowLeftIcon />}
114
+ rightArrowIcon={<KeyboardArrowRightIcon />}
115
+ dateRangeIcon={<DateRangeIcon />}
116
+ keyboardIcon={<EventIcon />}
117
+ timeIcon={<AccessTimeIcon />}
118
+ invalidDateMessage={null}
119
+ maxDateMessage={null}
120
+ minDateMessage={null}
121
+ />
122
+ <FormHelperText error={!isValid && !showDescription}>
123
+ {firstFormHelperText}
124
+ </FormHelperText>
125
+ <FormHelperText error={!isValid}>
126
+ {secondFormHelperText}
127
+ </FormHelperText>
128
+ </MuiPickersUtilsProvider>
129
+ </Hidden>
130
+ );
131
+ };
135
132
 
136
133
  export const materialDateTimeControlTester: RankedTester = rankWith(
137
134
  2,
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  The MIT License
3
3
 
4
- Copyright (c) 2017-2019 EclipseSource Munich
4
+ Copyright (c) 2017-2021 EclipseSource Munich
5
5
  https://github.com/eclipsesource/jsonforms
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -24,87 +24,80 @@
24
24
  */
25
25
  import React from 'react';
26
26
  import {
27
- computeLabel,
27
+ showAsRequired,
28
28
  ControlProps,
29
- ControlState,
30
29
  isDescriptionHidden,
31
30
  } from '@jsonforms/core';
32
- import { Control } from '@jsonforms/react';
33
31
 
34
32
  import { Hidden, InputLabel } from '@material-ui/core';
35
33
  import { FormControl, FormHelperText } from '@material-ui/core';
36
34
  import merge from 'lodash/merge';
35
+ import { useFocus } from '../util';
37
36
 
38
37
  export interface WithInput {
39
38
  input: any;
40
39
  }
41
40
 
42
- export abstract class MaterialInputControl extends Control<
43
- ControlProps & WithInput,
44
- ControlState
45
- > {
46
- render() {
47
- const {
48
- id,
49
- description,
50
- errors,
51
- label,
52
- uischema,
53
- visible,
54
- required,
55
- config,
56
- input
57
- } = this.props;
58
- const isValid = errors.length === 0;
59
- const appliedUiSchemaOptions = merge({}, config, uischema.options);
41
+ export const MaterialInputControl = (props: ControlProps & WithInput) => {
42
+ const [focused, onFocus, onBlur] = useFocus();
43
+ const {
44
+ id,
45
+ description,
46
+ errors,
47
+ label,
48
+ uischema,
49
+ visible,
50
+ required,
51
+ config,
52
+ input
53
+ } = props;
54
+ const isValid = errors.length === 0;
55
+ const appliedUiSchemaOptions = merge({}, config, uischema.options);
60
56
 
61
- const showDescription = !isDescriptionHidden(
62
- visible,
63
- description,
64
- this.state.isFocused,
65
- appliedUiSchemaOptions.showUnfocusedDescription
66
- );
57
+ const showDescription = !isDescriptionHidden(
58
+ visible,
59
+ description,
60
+ focused,
61
+ appliedUiSchemaOptions.showUnfocusedDescription
62
+ );
67
63
 
68
- const firstFormHelperText = showDescription
69
- ? description
70
- : !isValid
71
- ? errors
72
- : null;
73
- const secondFormHelperText = showDescription && !isValid ? errors : null;
74
- const InnerComponent = input;
64
+ const firstFormHelperText = showDescription
65
+ ? description
66
+ : !isValid
67
+ ? errors
68
+ : null;
69
+ const secondFormHelperText = showDescription && !isValid ? errors : null;
70
+ const InnerComponent = input;
75
71
 
76
- return (
77
- <Hidden xsUp={!visible}>
78
- <FormControl
79
- fullWidth={!appliedUiSchemaOptions.trim}
80
- onFocus={this.onFocus}
81
- onBlur={this.onBlur}
82
- id={id}
72
+ return (
73
+ <Hidden xsUp={!visible}>
74
+ <FormControl
75
+ fullWidth={!appliedUiSchemaOptions.trim}
76
+ onFocus={onFocus}
77
+ onBlur={onBlur}
78
+ id={id}
79
+ >
80
+ <InputLabel
81
+ htmlFor={id + '-input'}
82
+ error={!isValid}
83
+ required={showAsRequired(required,
84
+ appliedUiSchemaOptions.hideRequiredAsterisk)}
83
85
  >
84
- <InputLabel
85
- htmlFor={id + '-input'}
86
- error={!isValid}
87
- >
88
- {computeLabel(
89
- label,
90
- required,
91
- appliedUiSchemaOptions.hideRequiredAsterisk
92
- )}
93
- </InputLabel>
94
- <InnerComponent
95
- {...this.props}
96
- id={id + '-input'}
97
- isValid={isValid}
98
- visible={visible}
99
- />
100
- <FormHelperText error={!isValid && !showDescription}>
101
- {firstFormHelperText}
102
- </FormHelperText>
103
- <FormHelperText error={!isValid}>
104
- {secondFormHelperText}
105
- </FormHelperText>
106
- </FormControl>
107
- </Hidden>
108
- );
109
- }
110
- }
86
+ {label}
87
+ </InputLabel>
88
+ <InnerComponent
89
+ {...props}
90
+ id={id + '-input'}
91
+ isValid={isValid}
92
+ visible={visible}
93
+ />
94
+ <FormHelperText error={!isValid && !showDescription}>
95
+ {firstFormHelperText}
96
+ </FormHelperText>
97
+ <FormHelperText error={!isValid}>
98
+ {secondFormHelperText}
99
+ </FormHelperText>
100
+ </FormControl>
101
+ </Hidden>
102
+ );
103
+ };
@@ -24,9 +24,8 @@
24
24
  */
25
25
  import React from 'react';
26
26
  import {
27
- computeLabel,
28
27
  ControlProps,
29
- ControlState,
28
+ showAsRequired,
30
29
  isDateControl,
31
30
  isDescriptionHidden,
32
31
  isTimeControl,
@@ -35,65 +34,63 @@ import {
35
34
  rankWith
36
35
  } from '@jsonforms/core';
37
36
  import { Hidden } from '@material-ui/core';
38
- import { Control, withJsonFormsControlProps } from '@jsonforms/react';
37
+ import { withJsonFormsControlProps } from '@jsonforms/react';
39
38
  import TextField from '@material-ui/core/TextField';
40
39
  import merge from 'lodash/merge';
40
+ import { useDebouncedChange, useFocus } from '../util';
41
41
 
42
- export class MaterialNativeControl extends Control<ControlProps, ControlState> {
43
- render() {
44
- const {
45
- id,
46
- errors,
47
- label,
48
- schema,
49
- description,
50
- enabled,
51
- visible,
52
- required,
53
- path,
54
- handleChange,
55
- data,
56
- config
57
- } = this.props;
58
- const isValid = errors.length === 0;
59
- const appliedUiSchemaOptions = merge(
60
- {},
61
- config,
62
- this.props.uischema.options
63
- );
64
- const onChange = (ev: any) => handleChange(path, ev.target.value);
65
- const fieldType = appliedUiSchemaOptions.format ?? schema.format;
66
- const showDescription = !isDescriptionHidden(
67
- visible,
68
- description,
69
- this.state.isFocused,
70
- appliedUiSchemaOptions.showUnfocusedDescription
71
- );
42
+ export const MaterialNativeControl = (props: ControlProps) => {
43
+ const [focused, onFocus, onBlur] = useFocus();
44
+ const {
45
+ id,
46
+ errors,
47
+ label,
48
+ schema,
49
+ description,
50
+ enabled,
51
+ visible,
52
+ required,
53
+ path,
54
+ handleChange,
55
+ data,
56
+ config
57
+ } = props;
58
+ const isValid = errors.length === 0;
59
+ const appliedUiSchemaOptions = merge(
60
+ {},
61
+ config,
62
+ props.uischema.options
63
+ );
64
+ const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path);
65
+ const fieldType = appliedUiSchemaOptions.format ?? schema.format;
66
+ const showDescription = !isDescriptionHidden(
67
+ visible,
68
+ description,
69
+ focused,
70
+ appliedUiSchemaOptions.showUnfocusedDescription
71
+ );
72
72
 
73
- return (
74
- <Hidden xsUp={!visible}>
75
- <TextField
76
- id={id + '-input'}
77
- label={computeLabel(
78
- label,
79
- required,
80
- appliedUiSchemaOptions.hideRequiredAsterisk
81
- )}
82
- type={fieldType}
83
- error={!isValid}
84
- disabled={!enabled}
85
- fullWidth={!appliedUiSchemaOptions.trim}
86
- onFocus={this.onFocus}
87
- onBlur={this.onBlur}
88
- helperText={!isValid ? errors : showDescription ? description : null}
89
- InputLabelProps={{ shrink: true }}
90
- value={data}
91
- onChange={onChange}
92
- />
93
- </Hidden>
94
- );
95
- }
96
- }
73
+ return (
74
+ <Hidden xsUp={!visible}>
75
+ <TextField
76
+ required={showAsRequired(required,
77
+ appliedUiSchemaOptions.hideRequiredAsterisk)}
78
+ id={id + '-input'}
79
+ label={label}
80
+ type={fieldType}
81
+ error={!isValid}
82
+ disabled={!enabled}
83
+ fullWidth={!appliedUiSchemaOptions.trim}
84
+ onFocus={onFocus}
85
+ onBlur={onBlur}
86
+ helperText={!isValid ? errors : showDescription ? description : null}
87
+ InputLabelProps={{ shrink: true }}
88
+ value={inputValue}
89
+ onChange={onChange}
90
+ />
91
+ </Hidden>
92
+ );
93
+ };
97
94
 
98
95
  export const materialNativeControlTester: RankedTester = rankWith(
99
96
  2,
@@ -25,13 +25,11 @@
25
25
  import merge from 'lodash/merge';
26
26
  import React from 'react';
27
27
  import {
28
- computeLabel,
29
28
  ControlProps,
30
- ControlState,
29
+ showAsRequired,
31
30
  isDescriptionHidden,
32
31
  OwnPropsOfEnum
33
32
  } from '@jsonforms/core';
34
- import { Control } from '@jsonforms/react';
35
33
  import Radio from '@material-ui/core/Radio';
36
34
  import RadioGroup from '@material-ui/core/RadioGroup';
37
35
  import {
@@ -41,73 +39,73 @@ import {
41
39
  FormLabel,
42
40
  Hidden
43
41
  } from '@material-ui/core';
42
+ import { useFocus } from '../util';
44
43
 
45
- export class MaterialRadioGroup extends Control<
46
- ControlProps & OwnPropsOfEnum,
47
- ControlState
48
- > {
49
- render() {
50
- const {
51
- config,
52
- id,
53
- label,
54
- required,
55
- description,
56
- errors,
57
- data,
58
- visible,
59
- options
60
- } = this.props;
61
- const isValid = errors.length === 0;
62
- const appliedUiSchemaOptions = merge(
63
- {},
64
- config,
65
- this.props.uischema.options
66
- );
67
- const showDescription = !isDescriptionHidden(
68
- visible,
69
- description,
70
- this.state.isFocused,
71
- appliedUiSchemaOptions.showUnfocusedDescription
72
- );
44
+ export const MaterialRadioGroup = (props: ControlProps & OwnPropsOfEnum) => {
45
+ const [focused, onFocus, onBlur] = useFocus();
46
+ const {
47
+ config,
48
+ id,
49
+ label,
50
+ required,
51
+ description,
52
+ errors,
53
+ data,
54
+ visible,
55
+ options,
56
+ handleChange,
57
+ path
58
+ } = props;
59
+ const isValid = errors.length === 0;
60
+ const appliedUiSchemaOptions = merge(
61
+ {},
62
+ config,
63
+ props.uischema.options
64
+ );
65
+ const showDescription = !isDescriptionHidden(
66
+ visible,
67
+ description,
68
+ focused,
69
+ appliedUiSchemaOptions.showUnfocusedDescription
70
+ );
71
+ const onChange = (_ev:any, value:any) => handleChange(path, value);
73
72
 
74
- return (
75
- <Hidden xsUp={!visible}>
76
- <FormControl
77
- component={'fieldset' as 'div'}
78
- fullWidth={!appliedUiSchemaOptions.trim}
73
+ return (
74
+ <Hidden xsUp={!visible}>
75
+ <FormControl
76
+ component={'fieldset' as 'div'}
77
+ fullWidth={!appliedUiSchemaOptions.trim}
78
+ onFocus={onFocus}
79
+ onBlur={onBlur}
80
+ >
81
+ <FormLabel
82
+ htmlFor={id}
83
+ error={!isValid}
84
+ component={'legend' as 'label'}
85
+ required={showAsRequired(required,
86
+ appliedUiSchemaOptions.hideRequiredAsterisk)}
79
87
  >
80
- <FormLabel
81
- htmlFor={id}
82
- error={!isValid}
83
- component={'legend' as 'label'}
84
- >
85
- {computeLabel(
86
- label,
87
- required,
88
- appliedUiSchemaOptions.hideRequiredAsterisk
89
- )}
90
- </FormLabel>
88
+ {label}
89
+ </FormLabel>
91
90
 
92
- <RadioGroup
93
- value={this.state.value}
94
- onChange={(_ev, value) => this.handleChange(value)}
95
- row={true}
96
- >
97
- {options.map(option => (
98
- <FormControlLabel
99
- value={option.value}
100
- key={option.label}
101
- control={<Radio checked={data === option.value} />}
102
- label={option.label}
103
- />
104
- ))}
105
- </RadioGroup>
106
- <FormHelperText error={!isValid}>
107
- {!isValid ? errors : showDescription ? description : null}
108
- </FormHelperText>
109
- </FormControl>
110
- </Hidden>
111
- );
112
- }
113
- }
91
+ <RadioGroup
92
+ value={props.data}
93
+ onChange={onChange}
94
+ row={true}
95
+ >
96
+ {options.map(option => (
97
+ <FormControlLabel
98
+ value={option.value}
99
+ key={option.label}
100
+ control={<Radio checked={data === option.value} />}
101
+ label={option.label}
102
+ />
103
+ ))}
104
+ </RadioGroup>
105
+ <FormHelperText error={!isValid}>
106
+ {!isValid ? errors : showDescription ? description : null}
107
+ </FormHelperText>
108
+ </FormControl>
109
+ </Hidden>
110
+ );
111
+ };