@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.
- package/docs/assets/js/search.json +1 -1
- package/docs/classes/combinatorproperties.html +2 -5
- package/docs/classes/materialanyofstringorenumcontrol.html +6 -9
- package/docs/classes/materialtablecontrol.html +4 -7
- package/docs/globals.html +803 -213
- package/docs/index.html +63 -42
- package/docs/interfaces/ajvprops.html +1 -4
- package/docs/interfaces/arraylayouttoolbarprops.html +0 -3
- package/docs/interfaces/categorizationstate.html +0 -3
- package/docs/interfaces/categorizationstepperstate.html +0 -3
- package/docs/interfaces/combinatorpropertiesprops.html +0 -3
- package/docs/interfaces/deletedialogprops.html +0 -3
- package/docs/interfaces/dispatchpropsofexpandpanel.html +3 -6
- package/docs/interfaces/emptytableprops.html +0 -3
- package/docs/interfaces/expandpanelprops.html +19 -22
- package/docs/interfaces/jsonformstheme.html +0 -3
- package/docs/interfaces/materialcategorizationlayoutrendererprops.html +1 -4
- package/docs/interfaces/materialcategorizationstepperlayoutrendererprops.html +1 -4
- package/docs/interfaces/materiallayoutrendererprops.html +0 -3
- package/docs/interfaces/materialtabletoolbarprops.html +0 -3
- package/docs/interfaces/muitextinputprops.html +2 -5
- package/docs/interfaces/nonemptycellcomponentprops.html +266 -0
- package/docs/interfaces/nonemptycellprops.html +0 -3
- package/docs/interfaces/nonemptyrowprops.html +80 -27
- package/docs/interfaces/ownoneofprops.html +0 -3
- package/docs/interfaces/ownpropsofexpandpanel.html +14 -17
- package/docs/interfaces/ownpropsofnonemptycell.html +0 -3
- package/docs/interfaces/statepropsofexpandpanel.html +16 -19
- package/docs/interfaces/tableheadercellprops.html +0 -3
- package/docs/interfaces/tablerowsprop.html +9 -12
- package/docs/interfaces/validationprops.html +0 -3
- package/docs/interfaces/withdeletedialogsupport.html +0 -3
- package/docs/interfaces/withinput.html +1 -4
- package/docs/interfaces/withoptionlabel.html +3 -6
- package/lib/additional/ListWithDetailMasterItem.d.ts +1 -1
- package/lib/additional/ListWithDetailMasterItem.js.map +1 -1
- package/lib/additional/MaterialLabelRenderer.d.ts +1 -1
- package/lib/additional/MaterialLabelRenderer.js +3 -1
- package/lib/additional/MaterialLabelRenderer.js.map +1 -1
- package/lib/additional/MaterialListWithDetailRenderer.d.ts +1 -1
- package/lib/additional/MaterialListWithDetailRenderer.js +3 -1
- package/lib/additional/MaterialListWithDetailRenderer.js.map +1 -1
- package/lib/additional/index.js +3 -2
- package/lib/additional/index.js.map +1 -1
- package/lib/cells/CustomizableCells.js +10 -9
- package/lib/cells/CustomizableCells.js.map +1 -1
- package/lib/cells/MaterialBooleanCell.d.ts +1 -1
- package/lib/cells/MaterialBooleanCell.js +3 -1
- package/lib/cells/MaterialBooleanCell.js.map +1 -1
- package/lib/cells/MaterialBooleanToggleCell.d.ts +1 -1
- package/lib/cells/MaterialBooleanToggleCell.js +3 -1
- package/lib/cells/MaterialBooleanToggleCell.js.map +1 -1
- package/lib/cells/MaterialDateCell.d.ts +1 -1
- package/lib/cells/MaterialDateCell.js +3 -1
- package/lib/cells/MaterialDateCell.js.map +1 -1
- package/lib/cells/MaterialEnumCell.d.ts +1 -1
- package/lib/cells/MaterialEnumCell.js +3 -1
- package/lib/cells/MaterialEnumCell.js.map +1 -1
- package/lib/cells/MaterialIntegerCell.d.ts +1 -1
- package/lib/cells/MaterialIntegerCell.js +3 -1
- package/lib/cells/MaterialIntegerCell.js.map +1 -1
- package/lib/cells/MaterialNumberCell.d.ts +1 -1
- package/lib/cells/MaterialNumberCell.js +3 -1
- package/lib/cells/MaterialNumberCell.js.map +1 -1
- package/lib/cells/MaterialNumberFormatCell.d.ts +1 -1
- package/lib/cells/MaterialNumberFormatCell.js +3 -1
- package/lib/cells/MaterialNumberFormatCell.js.map +1 -1
- package/lib/cells/MaterialOneOfEnumCell.d.ts +1 -1
- package/lib/cells/MaterialOneOfEnumCell.js +3 -1
- package/lib/cells/MaterialOneOfEnumCell.js.map +1 -1
- package/lib/cells/MaterialTextCell.d.ts +1 -1
- package/lib/cells/MaterialTextCell.js +3 -1
- package/lib/cells/MaterialTextCell.js.map +1 -1
- package/lib/cells/MaterialTimeCell.d.ts +1 -1
- package/lib/cells/MaterialTimeCell.js +3 -1
- package/lib/cells/MaterialTimeCell.js.map +1 -1
- package/lib/cells/index.js +11 -10
- package/lib/cells/index.js.map +1 -1
- package/lib/complex/CombinatorProperties.js +3 -1
- package/lib/complex/CombinatorProperties.js.map +1 -1
- package/lib/complex/DeleteDialog.js +1 -0
- package/lib/complex/DeleteDialog.js.map +1 -1
- package/lib/complex/MaterialAllOfRenderer.d.ts +3 -2
- package/lib/complex/MaterialAllOfRenderer.js +3 -1
- package/lib/complex/MaterialAllOfRenderer.js.map +1 -1
- package/lib/complex/MaterialAnyOfRenderer.d.ts +3 -2
- package/lib/complex/MaterialAnyOfRenderer.js +3 -1
- package/lib/complex/MaterialAnyOfRenderer.js.map +1 -1
- package/lib/complex/MaterialArrayControlRenderer.d.ts +1 -1
- package/lib/complex/MaterialArrayControlRenderer.js +3 -1
- package/lib/complex/MaterialArrayControlRenderer.js.map +1 -1
- package/lib/complex/MaterialEnumArrayRenderer.d.ts +2 -2
- package/lib/complex/MaterialEnumArrayRenderer.js +6 -3
- package/lib/complex/MaterialEnumArrayRenderer.js.map +1 -1
- package/lib/complex/MaterialObjectRenderer.d.ts +3 -2
- package/lib/complex/MaterialObjectRenderer.js +3 -1
- package/lib/complex/MaterialObjectRenderer.js.map +1 -1
- package/lib/complex/MaterialOneOfRenderer.d.ts +2 -1
- package/lib/complex/MaterialOneOfRenderer.js +5 -4
- package/lib/complex/MaterialOneOfRenderer.js.map +1 -1
- package/lib/complex/MaterialTableControl.d.ts +16 -1
- package/lib/complex/MaterialTableControl.js +16 -8
- package/lib/complex/MaterialTableControl.js.map +1 -1
- package/lib/complex/NoBorderTableCell.js.map +1 -1
- package/lib/complex/TableToolbar.js.map +1 -1
- package/lib/complex/ValidationIcon.d.ts +5 -3
- package/lib/complex/ValidationIcon.js.map +1 -1
- package/lib/complex/index.js +6 -5
- package/lib/complex/index.js.map +1 -1
- package/lib/controls/MaterialAnyOfStringOrEnumControl.d.ts +1 -1
- package/lib/controls/MaterialAnyOfStringOrEnumControl.js +17 -12
- package/lib/controls/MaterialAnyOfStringOrEnumControl.js.map +1 -1
- package/lib/controls/MaterialBooleanControl.d.ts +1 -1
- package/lib/controls/MaterialBooleanControl.js +3 -1
- package/lib/controls/MaterialBooleanControl.js.map +1 -1
- package/lib/controls/MaterialBooleanToggleControl.d.ts +1 -1
- package/lib/controls/MaterialBooleanToggleControl.js +3 -1
- package/lib/controls/MaterialBooleanToggleControl.js.map +1 -1
- package/lib/controls/MaterialDateControl.d.ts +3 -6
- package/lib/controls/MaterialDateControl.js +25 -29
- package/lib/controls/MaterialDateControl.js.map +1 -1
- package/lib/controls/MaterialDateTimeControl.d.ts +3 -6
- package/lib/controls/MaterialDateTimeControl.js +25 -29
- package/lib/controls/MaterialDateTimeControl.js.map +1 -1
- package/lib/controls/MaterialEnumControl.d.ts +1 -1
- package/lib/controls/MaterialEnumControl.js +3 -1
- package/lib/controls/MaterialEnumControl.js.map +1 -1
- package/lib/controls/MaterialInputControl.d.ts +2 -5
- package/lib/controls/MaterialInputControl.js +23 -28
- package/lib/controls/MaterialInputControl.js.map +1 -1
- package/lib/controls/MaterialIntegerControl.d.ts +1 -1
- package/lib/controls/MaterialIntegerControl.js +3 -1
- package/lib/controls/MaterialIntegerControl.js.map +1 -1
- package/lib/controls/MaterialNativeControl.d.ts +3 -6
- package/lib/controls/MaterialNativeControl.js +15 -19
- package/lib/controls/MaterialNativeControl.js.map +1 -1
- package/lib/controls/MaterialNumberControl.d.ts +1 -1
- package/lib/controls/MaterialNumberControl.js +3 -1
- package/lib/controls/MaterialNumberControl.js.map +1 -1
- package/lib/controls/MaterialOneOfEnumControl.d.ts +1 -1
- package/lib/controls/MaterialOneOfEnumControl.js +3 -1
- package/lib/controls/MaterialOneOfEnumControl.js.map +1 -1
- package/lib/controls/MaterialOneOfRadioGroupControl.d.ts +1 -1
- package/lib/controls/MaterialOneOfRadioGroupControl.js +3 -1
- package/lib/controls/MaterialOneOfRadioGroupControl.js.map +1 -1
- package/lib/controls/MaterialRadioGroup.d.ts +2 -5
- package/lib/controls/MaterialRadioGroup.js +15 -20
- package/lib/controls/MaterialRadioGroup.js.map +1 -1
- package/lib/controls/MaterialRadioGroupControl.d.ts +1 -1
- package/lib/controls/MaterialRadioGroupControl.js +3 -1
- package/lib/controls/MaterialRadioGroupControl.js.map +1 -1
- package/lib/controls/MaterialSliderControl.d.ts +3 -6
- package/lib/controls/MaterialSliderControl.js +35 -39
- package/lib/controls/MaterialSliderControl.js.map +1 -1
- package/lib/controls/MaterialTextControl.d.ts +1 -1
- package/lib/controls/MaterialTextControl.js +3 -1
- package/lib/controls/MaterialTextControl.js.map +1 -1
- package/lib/controls/MaterialTimeControl.d.ts +3 -6
- package/lib/controls/MaterialTimeControl.js +25 -29
- package/lib/controls/MaterialTimeControl.js.map +1 -1
- package/lib/controls/index.d.ts +10 -10
- package/lib/controls/index.js +16 -15
- package/lib/controls/index.js.map +1 -1
- package/lib/extended/MaterialAutocompleteEnumControl.d.ts +1 -1
- package/lib/extended/MaterialAutocompleteEnumControl.js +3 -1
- package/lib/extended/MaterialAutocompleteEnumControl.js.map +1 -1
- package/lib/extended/MaterialAutocompleteOneOfEnumControl.d.ts +1 -1
- package/lib/extended/MaterialAutocompleteOneOfEnumControl.js +3 -1
- package/lib/extended/MaterialAutocompleteOneOfEnumControl.js.map +1 -1
- package/lib/extended/MuiAutocomplete.d.ts +2 -2
- package/lib/extended/MuiAutocomplete.js +4 -3
- package/lib/extended/MuiAutocomplete.js.map +1 -1
- package/lib/extended/index.d.ts +2 -2
- package/lib/extended/index.js +2 -1
- package/lib/extended/index.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/jsonforms-material.js +8 -8
- package/lib/jsonforms-material.js.map +1 -1
- package/lib/layouts/ArrayToolbar.js +1 -0
- package/lib/layouts/ArrayToolbar.js.map +1 -1
- package/lib/layouts/ExpandPanelRenderer.d.ts +3 -3
- package/lib/layouts/ExpandPanelRenderer.js +16 -13
- package/lib/layouts/ExpandPanelRenderer.js.map +1 -1
- package/lib/layouts/MaterialArrayLayout.d.ts +1 -11
- package/lib/layouts/MaterialArrayLayout.js +19 -31
- package/lib/layouts/MaterialArrayLayout.js.map +1 -1
- package/lib/layouts/MaterialArrayLayoutRenderer.d.ts +1 -1
- package/lib/layouts/MaterialArrayLayoutRenderer.js +3 -1
- package/lib/layouts/MaterialArrayLayoutRenderer.js.map +1 -1
- package/lib/layouts/MaterialCategorizationLayout.d.ts +2 -10
- package/lib/layouts/MaterialCategorizationLayout.js +31 -47
- package/lib/layouts/MaterialCategorizationLayout.js.map +1 -1
- package/lib/layouts/MaterialCategorizationStepperLayout.d.ts +2 -9
- package/lib/layouts/MaterialCategorizationStepperLayout.js +42 -53
- package/lib/layouts/MaterialCategorizationStepperLayout.js.map +1 -1
- package/lib/layouts/MaterialGroupLayout.d.ts +1 -1
- package/lib/layouts/MaterialGroupLayout.js +3 -1
- package/lib/layouts/MaterialGroupLayout.js.map +1 -1
- package/lib/layouts/MaterialHorizontalLayout.d.ts +1 -1
- package/lib/layouts/MaterialHorizontalLayout.js +3 -1
- package/lib/layouts/MaterialHorizontalLayout.js.map +1 -1
- package/lib/layouts/MaterialVerticalLayout.d.ts +1 -1
- package/lib/layouts/MaterialVerticalLayout.js +3 -1
- package/lib/layouts/MaterialVerticalLayout.js.map +1 -1
- package/lib/layouts/index.js +6 -5
- package/lib/layouts/index.js.map +1 -1
- package/lib/mui-controls/MuiCheckbox.js +2 -2
- package/lib/mui-controls/MuiCheckbox.js.map +1 -1
- package/lib/mui-controls/MuiInputInteger.js +9 -6
- package/lib/mui-controls/MuiInputInteger.js.map +1 -1
- package/lib/mui-controls/MuiInputNumber.js +9 -6
- package/lib/mui-controls/MuiInputNumber.js.map +1 -1
- package/lib/mui-controls/MuiInputNumberFormat.js +7 -8
- package/lib/mui-controls/MuiInputNumberFormat.js.map +1 -1
- package/lib/mui-controls/MuiInputText.js +11 -7
- package/lib/mui-controls/MuiInputText.js.map +1 -1
- package/lib/mui-controls/MuiInputTime.js +5 -3
- package/lib/mui-controls/MuiInputTime.js.map +1 -1
- package/lib/mui-controls/MuiSelect.js +3 -3
- package/lib/mui-controls/MuiSelect.js.map +1 -1
- package/lib/mui-controls/MuiToggle.js +2 -2
- package/lib/mui-controls/MuiToggle.js.map +1 -1
- package/lib/util/datejs.d.ts +2 -2
- package/lib/util/datejs.js +5 -2
- package/lib/util/datejs.js.map +1 -1
- package/lib/util/debounce.d.ts +1 -0
- package/lib/util/debounce.js +48 -0
- package/lib/util/debounce.js.map +1 -0
- package/lib/util/focus.d.ts +1 -0
- package/lib/util/focus.js +36 -0
- package/lib/util/focus.js.map +1 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.js +3 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/layout.d.ts +2 -1
- package/lib/util/layout.js +8 -4
- package/lib/util/layout.js.map +1 -1
- package/package.json +5 -5
- package/src/cells/MaterialTimeCell.tsx +1 -0
- package/src/complex/MaterialAllOfRenderer.tsx +2 -1
- package/src/complex/MaterialAnyOfRenderer.tsx +2 -1
- package/src/complex/MaterialEnumArrayRenderer.tsx +1 -0
- package/src/complex/MaterialObjectRenderer.tsx +2 -1
- package/src/complex/MaterialOneOfRenderer.tsx +6 -6
- package/src/complex/MaterialTableControl.tsx +36 -24
- package/src/controls/MaterialAnyOfStringOrEnumControl.tsx +16 -12
- package/src/controls/MaterialDateControl.tsx +80 -85
- package/src/controls/MaterialDateTimeControl.tsx +83 -86
- package/src/controls/MaterialInputControl.tsx +62 -69
- package/src/controls/MaterialNativeControl.tsx +54 -57
- package/src/controls/MaterialRadioGroup.tsx +67 -69
- package/src/controls/MaterialSliderControl.tsx +92 -87
- package/src/controls/MaterialTimeControl.tsx +77 -80
- package/src/extended/MuiAutocomplete.tsx +2 -3
- package/src/layouts/ExpandPanelRenderer.tsx +11 -17
- package/src/layouts/MaterialArrayLayout.tsx +73 -82
- package/src/layouts/MaterialCategorizationLayout.tsx +49 -65
- package/src/layouts/MaterialCategorizationStepperLayout.tsx +79 -87
- package/src/mui-controls/MuiCheckbox.tsx +1 -2
- package/src/mui-controls/MuiInputInteger.tsx +12 -9
- package/src/mui-controls/MuiInputNumber.tsx +9 -6
- package/src/mui-controls/MuiInputNumberFormat.tsx +8 -11
- package/src/mui-controls/MuiInputText.tsx +17 -15
- package/src/mui-controls/MuiInputTime.tsx +6 -4
- package/src/mui-controls/MuiSelect.tsx +2 -3
- package/src/mui-controls/MuiToggle.tsx +1 -2
- package/src/util/debounce.ts +43 -0
- package/src/util/focus.ts +32 -0
- package/src/util/index.ts +2 -0
- package/src/util/layout.tsx +5 -6
- package/test/renderers/MaterialAnyOfRenderer.test.tsx +14 -8
- package/test/renderers/MaterialArrayLayout.test.tsx +6 -6
- package/test/renderers/MaterialCategorizationLayout.test.tsx +73 -0
- package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +73 -0
- package/test/renderers/MaterialInputControl.test.tsx +3 -3
- package/test/renderers/MaterialIntegerCell.test.tsx +41 -20
- package/test/renderers/MaterialNumberCell.test.tsx +45 -24
- package/test/renderers/MaterialOneOfRenderer.test.tsx +7 -4
- package/test/renderers/MaterialTextCell.test.tsx +41 -20
- package/test/renderers/MaterialTimeCell.test.tsx +41 -20
- package/test/renderers/MaterialTimeControl.test.tsx +3 -3
- package/docs/classes/materialarraylayout.html +0 -777
- package/docs/classes/materialcategorizationlayoutrenderer.html +0 -786
- package/docs/classes/materialcategorizationstepperlayoutrenderer.html +0 -762
- package/docs/classes/materialdatecontrol.html +0 -825
- package/docs/classes/materialdatetimecontrol.html +0 -825
- package/docs/classes/materialinputcontrol.html +0 -825
- package/docs/classes/materialnativecontrol.html +0 -825
- package/docs/classes/materialradiogroup.html +0 -825
- package/docs/classes/materialslidercontrol.html +0 -825
- package/docs/classes/materialtimecontrol.html +0 -825
- package/docs/interfaces/materialarraylayoutstate.html +0 -157
|
@@ -22,7 +22,7 @@
|
|
|
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, {useState} from 'react';
|
|
26
26
|
import { Hidden, Tab, Tabs } from '@material-ui/core';
|
|
27
27
|
import AppBar from '@material-ui/core/AppBar';
|
|
28
28
|
import {
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
UISchemaElement,
|
|
38
38
|
uiTypeIs
|
|
39
39
|
} from '@jsonforms/core';
|
|
40
|
-
import {
|
|
40
|
+
import { withJsonFormsLayoutProps } from '@jsonforms/react';
|
|
41
41
|
import {
|
|
42
42
|
AjvProps,
|
|
43
43
|
MaterialLayoutRenderer,
|
|
@@ -76,71 +76,55 @@ export interface MaterialCategorizationLayoutRendererProps
|
|
|
76
76
|
onChange?(selected: number, prevSelected: number): void;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
export const MaterialCategorizationLayoutRenderer = (props: MaterialCategorizationLayoutRendererProps) => {
|
|
80
|
+
const {
|
|
81
|
+
data,
|
|
82
|
+
path,
|
|
83
|
+
renderers,
|
|
84
|
+
cells,
|
|
85
|
+
schema,
|
|
86
|
+
uischema,
|
|
87
|
+
visible,
|
|
88
|
+
enabled,
|
|
89
|
+
selected,
|
|
90
|
+
onChange,
|
|
91
|
+
ajv
|
|
92
|
+
} = props;
|
|
93
|
+
const categorization = uischema as Categorization;
|
|
94
|
+
const [activeCategory, setActiveCategory]= useState<number|undefined>(selected??0);
|
|
95
|
+
const categories = categorization.elements.filter((category: Category) =>
|
|
96
|
+
isVisible(category, data, undefined, ajv)
|
|
97
|
+
);
|
|
98
|
+
const childProps: MaterialLayoutRendererProps = {
|
|
99
|
+
elements: categories[activeCategory].elements,
|
|
100
|
+
schema,
|
|
101
|
+
path,
|
|
102
|
+
direction: 'column',
|
|
103
|
+
enabled,
|
|
104
|
+
visible,
|
|
105
|
+
renderers,
|
|
106
|
+
cells
|
|
85
107
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
data,
|
|
90
|
-
path,
|
|
91
|
-
renderers,
|
|
92
|
-
cells,
|
|
93
|
-
schema,
|
|
94
|
-
uischema,
|
|
95
|
-
visible,
|
|
96
|
-
enabled,
|
|
97
|
-
selected,
|
|
98
|
-
ajv
|
|
99
|
-
} = this.props;
|
|
100
|
-
const categorization = uischema as Categorization;
|
|
101
|
-
const value = this.hasOwnState() ? this.state.activeCategory : selected;
|
|
102
|
-
const childProps: MaterialLayoutRendererProps = {
|
|
103
|
-
elements: categorization.elements[value].elements,
|
|
104
|
-
schema,
|
|
105
|
-
path,
|
|
106
|
-
direction: 'column',
|
|
107
|
-
enabled,
|
|
108
|
-
visible,
|
|
109
|
-
renderers,
|
|
110
|
-
cells
|
|
111
|
-
};
|
|
112
|
-
const categories = categorization.elements.filter((category: Category) =>
|
|
113
|
-
isVisible(category, data, undefined, ajv)
|
|
114
|
-
);
|
|
115
|
-
return (
|
|
116
|
-
<Hidden xsUp={!visible}>
|
|
117
|
-
<AppBar position='static'>
|
|
118
|
-
<Tabs value={value} onChange={this.handleChange} variant='scrollable'>
|
|
119
|
-
{categories.map((e: Category, idx: number) => (
|
|
120
|
-
<Tab key={idx} label={e.label} />
|
|
121
|
-
))}
|
|
122
|
-
</Tabs>
|
|
123
|
-
</AppBar>
|
|
124
|
-
<div style={{ marginTop: '0.5em' }}>
|
|
125
|
-
<MaterialLayoutRenderer {...childProps} />
|
|
126
|
-
</div>
|
|
127
|
-
</Hidden>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
hasOwnState = () => {
|
|
132
|
-
return this.props.ownState !== undefined ? this.props.ownState : true;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
private handleChange = (_event: any, value: any) => {
|
|
136
|
-
if (this.props.onChange) {
|
|
137
|
-
this.props.onChange(value, this.state.activeCategory);
|
|
138
|
-
}
|
|
139
|
-
const hasOwnState = this.hasOwnState();
|
|
140
|
-
if (hasOwnState) {
|
|
141
|
-
this.setState({ activeCategory: value });
|
|
108
|
+
const onTabChange = (_event: any, value: any) => {
|
|
109
|
+
if (onChange) {
|
|
110
|
+
onChange(value, activeCategory);
|
|
142
111
|
}
|
|
112
|
+
setActiveCategory(value);
|
|
143
113
|
};
|
|
144
|
-
|
|
114
|
+
return (
|
|
115
|
+
<Hidden xsUp={!visible}>
|
|
116
|
+
<AppBar position='static'>
|
|
117
|
+
<Tabs value={activeCategory} onChange={onTabChange} variant='scrollable'>
|
|
118
|
+
{categories.map((e: Category, idx: number) => (
|
|
119
|
+
<Tab key={idx} label={e.label} />
|
|
120
|
+
))}
|
|
121
|
+
</Tabs>
|
|
122
|
+
</AppBar>
|
|
123
|
+
<div style={{ marginTop: '0.5em' }}>
|
|
124
|
+
<MaterialLayoutRenderer {...childProps} />
|
|
125
|
+
</div>
|
|
126
|
+
</Hidden>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
145
129
|
|
|
146
130
|
export default withJsonFormsLayoutProps(withAjvProps(MaterialCategorizationLayoutRenderer));
|
|
@@ -22,7 +22,7 @@
|
|
|
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, {useState} from 'react';
|
|
26
26
|
import merge from 'lodash/merge';
|
|
27
27
|
import { Button, Hidden, Step, StepButton, Stepper } from '@material-ui/core';
|
|
28
28
|
import {
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
StatePropsOfLayout,
|
|
38
38
|
uiTypeIs
|
|
39
39
|
} from '@jsonforms/core';
|
|
40
|
-
import {
|
|
40
|
+
import { withJsonFormsLayoutProps } from '@jsonforms/react';
|
|
41
41
|
import {
|
|
42
42
|
AjvProps,
|
|
43
43
|
MaterialLayoutRenderer,
|
|
@@ -63,94 +63,86 @@ export interface MaterialCategorizationStepperLayoutRendererProps
|
|
|
63
63
|
data: any;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export
|
|
67
|
-
|
|
68
|
-
CategorizationStepperState
|
|
69
|
-
> {
|
|
70
|
-
state = {
|
|
71
|
-
activeCategory: 0
|
|
72
|
-
};
|
|
66
|
+
export const MaterialCategorizationStepperLayoutRenderer = (props: MaterialCategorizationStepperLayoutRendererProps)=> {
|
|
67
|
+
const [activeCategory, setActiveCategory] = useState<number>(0);
|
|
73
68
|
|
|
74
|
-
handleStep = (step: number) => {
|
|
75
|
-
|
|
69
|
+
const handleStep = (step: number) => {
|
|
70
|
+
setActiveCategory( step);
|
|
76
71
|
};
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
73
|
+
const {
|
|
74
|
+
data,
|
|
75
|
+
path,
|
|
76
|
+
renderers,
|
|
77
|
+
schema,
|
|
78
|
+
uischema,
|
|
79
|
+
visible,
|
|
80
|
+
cells,
|
|
81
|
+
config,
|
|
82
|
+
ajv
|
|
83
|
+
} = props;
|
|
84
|
+
const categorization = uischema as Categorization;
|
|
85
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
86
|
+
const buttonWrapperStyle = {
|
|
87
|
+
textAlign: 'right' as 'right',
|
|
88
|
+
width: '100%',
|
|
89
|
+
margin: '1em auto'
|
|
90
|
+
};
|
|
91
|
+
const buttonNextStyle = {
|
|
92
|
+
float: 'right' as 'right'
|
|
93
|
+
};
|
|
94
|
+
const buttonStyle = {
|
|
95
|
+
marginRight: '1em'
|
|
96
|
+
};
|
|
97
|
+
const categories = categorization.elements.filter((category: Category) =>
|
|
98
|
+
isVisible(category, data, undefined, ajv)
|
|
99
|
+
);
|
|
100
|
+
const childProps: MaterialLayoutRendererProps = {
|
|
101
|
+
elements: categories[activeCategory].elements,
|
|
102
|
+
schema,
|
|
103
|
+
path,
|
|
104
|
+
direction: 'column',
|
|
105
|
+
visible,
|
|
106
|
+
renderers,
|
|
107
|
+
cells
|
|
108
|
+
};
|
|
109
|
+
return (
|
|
110
|
+
<Hidden xsUp={!visible}>
|
|
111
|
+
<Stepper activeStep={activeCategory} nonLinear>
|
|
112
|
+
{categories.map((e: Category, idx: number) => (
|
|
113
|
+
<Step key={e.label}>
|
|
114
|
+
<StepButton onClick={() => handleStep(idx)}>
|
|
115
|
+
{e.label}
|
|
116
|
+
</StepButton>
|
|
117
|
+
</Step>
|
|
118
|
+
))}
|
|
119
|
+
</Stepper>
|
|
120
|
+
<div>
|
|
121
|
+
<MaterialLayoutRenderer {...childProps} />
|
|
122
|
+
</div>
|
|
123
|
+
{ !!appliedUiSchemaOptions.showNavButtons ? (<div style={buttonWrapperStyle}>
|
|
124
|
+
<Button
|
|
125
|
+
style={buttonNextStyle}
|
|
126
|
+
variant="contained"
|
|
127
|
+
color="primary"
|
|
128
|
+
disabled={activeCategory >= categories.length - 1}
|
|
129
|
+
onClick={() => handleStep(activeCategory + 1)}
|
|
130
|
+
>
|
|
131
|
+
Next
|
|
132
|
+
</Button>
|
|
133
|
+
<Button
|
|
134
|
+
style={buttonStyle}
|
|
135
|
+
color="secondary"
|
|
136
|
+
variant="contained"
|
|
137
|
+
disabled={activeCategory <= 0}
|
|
138
|
+
onClick={() => handleStep(activeCategory - 1)}
|
|
139
|
+
>
|
|
140
|
+
Previous
|
|
141
|
+
</Button>
|
|
142
|
+
</div>) : (<></>)}
|
|
143
|
+
</Hidden>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
154
146
|
|
|
155
147
|
export default withJsonFormsLayoutProps(withAjvProps(
|
|
156
148
|
MaterialCategorizationStepperLayoutRenderer
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
import React from 'react';
|
|
26
26
|
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
27
27
|
import Checkbox from '@material-ui/core/Checkbox';
|
|
28
|
-
import { areEqual } from '@jsonforms/react';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
30
29
|
|
|
31
30
|
export const MuiCheckbox = React.memo((props: CellProps & WithClassname) => {
|
|
@@ -54,4 +53,4 @@ export const MuiCheckbox = React.memo((props: CellProps & WithClassname) => {
|
|
|
54
53
|
inputProps={inputProps}
|
|
55
54
|
/>
|
|
56
55
|
);
|
|
57
|
-
}
|
|
56
|
+
});
|
|
@@ -25,10 +25,14 @@
|
|
|
25
25
|
import React from 'react';
|
|
26
26
|
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
27
27
|
import Input from '@material-ui/core/Input';
|
|
28
|
-
import { areEqual } from '@jsonforms/react';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
29
|
+
import { useDebouncedChange } from '../util';
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const toNumber = (value: string) =>
|
|
32
|
+
value === '' ? undefined : parseInt(value, 10);
|
|
33
|
+
const eventToValue = (ev:any) => toNumber(ev.target.value);
|
|
34
|
+
|
|
35
|
+
export const MuiInputInteger = React.memo(
|
|
32
36
|
(props: CellProps & WithClassname) => {
|
|
33
37
|
const {
|
|
34
38
|
data,
|
|
@@ -41,15 +45,16 @@ export const MuiInputInteger = React.memo(
|
|
|
41
45
|
config
|
|
42
46
|
} = props;
|
|
43
47
|
const inputProps = { step: '1' };
|
|
44
|
-
|
|
45
|
-
value === '' ? undefined : parseInt(value, 10);
|
|
48
|
+
|
|
46
49
|
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
47
50
|
|
|
51
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, eventToValue);
|
|
52
|
+
|
|
48
53
|
return (
|
|
49
54
|
<Input
|
|
50
55
|
type='number'
|
|
51
|
-
value={
|
|
52
|
-
onChange={
|
|
56
|
+
value={inputValue}
|
|
57
|
+
onChange={onChange}
|
|
53
58
|
className={className}
|
|
54
59
|
id={id}
|
|
55
60
|
disabled={!enabled}
|
|
@@ -58,6 +63,4 @@ export const MuiInputInteger = React.memo(
|
|
|
58
63
|
fullWidth={true}
|
|
59
64
|
/>
|
|
60
65
|
);
|
|
61
|
-
}
|
|
62
|
-
areEqual
|
|
63
|
-
);
|
|
66
|
+
});
|
|
@@ -25,9 +25,12 @@
|
|
|
25
25
|
import React from 'react';
|
|
26
26
|
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
27
27
|
import Input from '@material-ui/core/Input';
|
|
28
|
-
import { areEqual } from '@jsonforms/react';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
29
|
+
import {useDebouncedChange} from '../util';
|
|
30
30
|
|
|
31
|
+
const toNumber = (value: string) =>
|
|
32
|
+
value === '' ? undefined : parseFloat(value);
|
|
33
|
+
const eventToValue = (ev:any) => toNumber(ev.target.value);
|
|
31
34
|
export const MuiInputNumber = React.memo((props: CellProps & WithClassname) => {
|
|
32
35
|
const {
|
|
33
36
|
data,
|
|
@@ -40,15 +43,15 @@ export const MuiInputNumber = React.memo((props: CellProps & WithClassname) => {
|
|
|
40
43
|
config
|
|
41
44
|
} = props;
|
|
42
45
|
const inputProps = { step: '0.1' };
|
|
43
|
-
|
|
44
|
-
value === '' ? undefined : parseFloat(value);
|
|
46
|
+
|
|
45
47
|
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
48
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, eventToValue);
|
|
46
49
|
|
|
47
50
|
return (
|
|
48
51
|
<Input
|
|
49
52
|
type='number'
|
|
50
|
-
value={
|
|
51
|
-
onChange={
|
|
53
|
+
value={inputValue}
|
|
54
|
+
onChange={onChange}
|
|
52
55
|
className={className}
|
|
53
56
|
id={id}
|
|
54
57
|
disabled={!enabled}
|
|
@@ -57,4 +60,4 @@ export const MuiInputNumber = React.memo((props: CellProps & WithClassname) => {
|
|
|
57
60
|
fullWidth={true}
|
|
58
61
|
/>
|
|
59
62
|
);
|
|
60
|
-
}
|
|
63
|
+
});
|
|
@@ -22,13 +22,13 @@
|
|
|
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, {useCallback} from 'react';
|
|
26
26
|
import { CellProps, Formatted, WithClassname } from '@jsonforms/core';
|
|
27
27
|
import Input from '@material-ui/core/Input';
|
|
28
|
-
import { areEqual } from '@jsonforms/react';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
29
|
+
import { useDebouncedChange } from '../util';
|
|
30
30
|
|
|
31
|
-
export const MuiInputNumberFormat = React.memo(
|
|
31
|
+
export const MuiInputNumberFormat = React.memo(
|
|
32
32
|
(props: CellProps & WithClassname & Formatted<number>) => {
|
|
33
33
|
const {
|
|
34
34
|
className,
|
|
@@ -51,15 +51,14 @@ export const MuiInputNumberFormat = React.memo(
|
|
|
51
51
|
}
|
|
52
52
|
const formattedNumber = props.toFormatted(props.data);
|
|
53
53
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
54
|
+
const validStringNumber = useCallback((ev:any) => props.fromFormatted(ev.currentTarget.value),[props.fromFormatted]);
|
|
55
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', formattedNumber, path, validStringNumber);
|
|
56
|
+
|
|
58
57
|
|
|
59
58
|
return (
|
|
60
59
|
<Input
|
|
61
60
|
type='text'
|
|
62
|
-
value={
|
|
61
|
+
value={inputValue}
|
|
63
62
|
onChange={onChange}
|
|
64
63
|
className={className}
|
|
65
64
|
id={id}
|
|
@@ -71,6 +70,4 @@ export const MuiInputNumberFormat = React.memo(
|
|
|
71
70
|
error={!isValid}
|
|
72
71
|
/>
|
|
73
72
|
);
|
|
74
|
-
}
|
|
75
|
-
areEqual
|
|
76
|
-
);
|
|
73
|
+
});
|
|
@@ -24,22 +24,20 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import React, { useState } from 'react';
|
|
26
26
|
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
27
|
-
import { areEqual } from '@jsonforms/react';
|
|
28
27
|
import Input, { InputProps } from '@material-ui/core/Input';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
30
29
|
import IconButton from '@material-ui/core/IconButton';
|
|
31
30
|
import InputAdornment from '@material-ui/core/InputAdornment';
|
|
32
31
|
import Close from '@material-ui/icons/Close';
|
|
33
32
|
import { useTheme } from '@material-ui/core/styles';
|
|
34
|
-
import { JsonFormsTheme } from '../util';
|
|
33
|
+
import { JsonFormsTheme, useDebouncedChange } from '../util';
|
|
35
34
|
import { InputBaseComponentProps } from '@material-ui/core';
|
|
36
35
|
|
|
37
36
|
interface MuiTextInputProps {
|
|
38
37
|
muiInputProps?: InputProps['inputProps'];
|
|
39
38
|
inputComponent?: InputProps['inputComponent'];
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
export const MuiInputText = React.memo((props: CellProps & WithClassname & MuiTextInputProps) => {
|
|
40
|
+
export const MuiInputText = React.memo((props: CellProps & WithClassname & MuiTextInputProps) => {
|
|
43
41
|
const [showAdornment, setShowAdornment] = useState(false);
|
|
44
42
|
const {
|
|
45
43
|
data,
|
|
@@ -63,23 +61,27 @@ export const MuiInputText = React.memo((props: CellProps & WithClassname & MuiTe
|
|
|
63
61
|
} else {
|
|
64
62
|
inputProps = {};
|
|
65
63
|
}
|
|
66
|
-
|
|
64
|
+
|
|
67
65
|
inputProps = merge(inputProps, muiInputProps);
|
|
68
|
-
|
|
66
|
+
|
|
69
67
|
if (appliedUiSchemaOptions.trim && maxLength !== undefined) {
|
|
70
68
|
inputProps.size = maxLength;
|
|
71
|
-
}
|
|
72
|
-
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const [inputText, onChange, onClear] = useDebouncedChange(handleChange, '', data, path);
|
|
72
|
+
const onPointerEnter = () => setShowAdornment(true);
|
|
73
|
+
const onPointerLeave = () => setShowAdornment(false);
|
|
73
74
|
|
|
74
75
|
const theme: JsonFormsTheme = useTheme();
|
|
75
|
-
|
|
76
|
+
|
|
77
|
+
const closeStyle = {background: theme.jsonforms?.input?.delete?.background || theme.palette.background.default, borderRadius: '50%'};
|
|
76
78
|
|
|
77
79
|
return (
|
|
78
80
|
<Input
|
|
79
81
|
type={
|
|
80
82
|
appliedUiSchemaOptions.format === 'password' ? 'password' : 'text'
|
|
81
83
|
}
|
|
82
|
-
value={
|
|
84
|
+
value={inputText}
|
|
83
85
|
onChange={onChange}
|
|
84
86
|
className={className}
|
|
85
87
|
id={id}
|
|
@@ -89,8 +91,8 @@ export const MuiInputText = React.memo((props: CellProps & WithClassname & MuiTe
|
|
|
89
91
|
fullWidth={!appliedUiSchemaOptions.trim || maxLength === undefined}
|
|
90
92
|
inputProps={inputProps}
|
|
91
93
|
error={!isValid}
|
|
92
|
-
onPointerEnter={
|
|
93
|
-
onPointerLeave={
|
|
94
|
+
onPointerEnter={onPointerEnter}
|
|
95
|
+
onPointerLeave={onPointerLeave}
|
|
94
96
|
endAdornment={
|
|
95
97
|
<InputAdornment
|
|
96
98
|
position='end'
|
|
@@ -103,13 +105,13 @@ export const MuiInputText = React.memo((props: CellProps & WithClassname & MuiTe
|
|
|
103
105
|
>
|
|
104
106
|
<IconButton
|
|
105
107
|
aria-label='Clear input field'
|
|
106
|
-
onClick={
|
|
108
|
+
onClick={onClear}
|
|
107
109
|
>
|
|
108
|
-
<Close style={
|
|
110
|
+
<Close style={closeStyle}/>
|
|
109
111
|
</IconButton>
|
|
110
112
|
</InputAdornment>
|
|
111
113
|
}
|
|
112
114
|
inputComponent={inputComponent}
|
|
113
115
|
/>
|
|
114
116
|
);
|
|
115
|
-
}
|
|
117
|
+
});
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
import React from 'react';
|
|
26
26
|
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
27
27
|
import Input from '@material-ui/core/Input';
|
|
28
|
-
import { areEqual } from '@jsonforms/react';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
29
|
+
import { useDebouncedChange } from '../util';
|
|
30
30
|
|
|
31
31
|
export const MuiInputTime = React.memo((props: CellProps & WithClassname) => {
|
|
32
32
|
const {
|
|
@@ -40,11 +40,13 @@ export const MuiInputTime = React.memo((props: CellProps & WithClassname) => {
|
|
|
40
40
|
config
|
|
41
41
|
} = props;
|
|
42
42
|
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
43
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path);
|
|
44
|
+
|
|
43
45
|
return (
|
|
44
46
|
<Input
|
|
45
47
|
type='time'
|
|
46
|
-
value={
|
|
47
|
-
onChange={
|
|
48
|
+
value={inputValue}
|
|
49
|
+
onChange={onChange}
|
|
48
50
|
className={className}
|
|
49
51
|
id={id}
|
|
50
52
|
disabled={!enabled}
|
|
@@ -52,4 +54,4 @@ export const MuiInputTime = React.memo((props: CellProps & WithClassname) => {
|
|
|
52
54
|
fullWidth={true}
|
|
53
55
|
/>
|
|
54
56
|
);
|
|
55
|
-
}
|
|
57
|
+
});
|
|
@@ -27,7 +27,6 @@ import { EnumCellProps, WithClassname } from '@jsonforms/core';
|
|
|
27
27
|
|
|
28
28
|
import Select from '@material-ui/core/Select';
|
|
29
29
|
import { MenuItem } from '@material-ui/core';
|
|
30
|
-
import { areEqual } from '@jsonforms/react';
|
|
31
30
|
import merge from 'lodash/merge';
|
|
32
31
|
|
|
33
32
|
export const MuiSelect = React.memo((props: EnumCellProps & WithClassname) => {
|
|
@@ -50,7 +49,7 @@ export const MuiSelect = React.memo((props: EnumCellProps & WithClassname) => {
|
|
|
50
49
|
id={id}
|
|
51
50
|
disabled={!enabled}
|
|
52
51
|
autoFocus={appliedUiSchemaOptions.focus}
|
|
53
|
-
value={data
|
|
52
|
+
value={data !== undefined ? data : ''}
|
|
54
53
|
onChange={ev => handleChange(path, ev.target.value)}
|
|
55
54
|
fullWidth={true}
|
|
56
55
|
>
|
|
@@ -63,4 +62,4 @@ export const MuiSelect = React.memo((props: EnumCellProps & WithClassname) => {
|
|
|
63
62
|
)}
|
|
64
63
|
</Select>
|
|
65
64
|
);
|
|
66
|
-
}
|
|
65
|
+
});
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
import React from 'react';
|
|
26
26
|
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
27
27
|
import Switch from '@material-ui/core/Switch';
|
|
28
|
-
import { areEqual } from '@jsonforms/react';
|
|
29
28
|
import merge from 'lodash/merge';
|
|
30
29
|
|
|
31
30
|
export const MuiToggle = React.memo((props: CellProps & WithClassname) => {
|
|
@@ -53,4 +52,4 @@ export const MuiToggle = React.memo((props: CellProps & WithClassname) => {
|
|
|
53
52
|
inputProps={inputProps}
|
|
54
53
|
/>
|
|
55
54
|
);
|
|
56
|
-
}
|
|
55
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021 EclipseSource Munich
|
|
5
|
+
https://github.com/eclipsesource/jsonforms
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
import { debounce } from 'lodash';
|
|
26
|
+
import { useState, useCallback, useEffect } from 'react'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const eventToValue = (ev: any) => ev.target.value;
|
|
30
|
+
export const useDebouncedChange = (handleChange: (path: string, value: any) => void, defaultValue: any, data: any, path: string, eventToValueFunction: (ev: any) => any = eventToValue, timeout = 300): [any, React.ChangeEventHandler, () => void] => {
|
|
31
|
+
const [input, setInput] = useState(data ?? defaultValue);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setInput(data ?? defaultValue);
|
|
34
|
+
}, [data]);
|
|
35
|
+
const debouncedUpdate = useCallback(debounce((newValue: string) => handleChange(path, newValue), timeout), [handleChange, path, timeout]);
|
|
36
|
+
const onChange = useCallback((ev: any) => {
|
|
37
|
+
const newValue = eventToValueFunction(ev);
|
|
38
|
+
setInput(newValue ?? defaultValue);
|
|
39
|
+
debouncedUpdate(newValue);
|
|
40
|
+
}, [debouncedUpdate, eventToValueFunction]);
|
|
41
|
+
const onClear = useCallback(() => { setInput(defaultValue); handleChange(path, undefined) }, [defaultValue, handleChange, path]);
|
|
42
|
+
return [input, onChange, onClear];
|
|
43
|
+
};
|