@jsonforms/material-renderers 3.0.0-beta.5 → 3.0.0-rc.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 (53) hide show
  1. package/docs/assets/js/search.json +1 -1
  2. package/docs/globals.html +77 -31
  3. package/docs/index.html +6 -0
  4. package/docs/interfaces/categorizationstate.html +1 -1
  5. package/docs/interfaces/categorizationstepperstate.html +1 -1
  6. package/docs/interfaces/materialcategorizationlayoutrendererprops.html +49 -4
  7. package/docs/interfaces/materialcategorizationstepperlayoutrendererprops.html +46 -1
  8. package/docs/interfaces/materiallabelablelayoutrendererprops.html +328 -0
  9. package/docs/interfaces/materiallayoutrendererprops.html +5 -0
  10. package/docs/interfaces/withoptionlabel.html +3 -3
  11. package/lib/additional/MaterialLabelRenderer.d.ts +3 -3
  12. package/lib/cells/MaterialEnumCell.d.ts +2 -1
  13. package/lib/cells/MaterialOneOfEnumCell.d.ts +2 -1
  14. package/lib/controls/MaterialEnumControl.d.ts +2 -1
  15. package/lib/controls/MaterialOneOfEnumControl.d.ts +2 -1
  16. package/lib/controls/index.d.ts +2 -2
  17. package/lib/jsonforms-react-material.cjs.js +82 -46
  18. package/lib/jsonforms-react-material.cjs.js.map +1 -1
  19. package/lib/jsonforms-react-material.esm.js +79 -48
  20. package/lib/jsonforms-react-material.esm.js.map +1 -1
  21. package/lib/layouts/MaterialCategorizationLayout.d.ts +4 -3
  22. package/lib/layouts/MaterialCategorizationStepperLayout.d.ts +4 -3
  23. package/lib/layouts/MaterialGroupLayout.d.ts +2 -2
  24. package/lib/layouts/MaterialHorizontalLayout.d.ts +1 -1
  25. package/lib/layouts/MaterialVerticalLayout.d.ts +1 -1
  26. package/lib/mui-controls/MuiAutocomplete.d.ts +2 -2
  27. package/lib/mui-controls/MuiSelect.d.ts +2 -1
  28. package/lib/util/i18nDefaults.d.ts +3 -0
  29. package/lib/util/index.d.ts +1 -0
  30. package/lib/util/layout.d.ts +3 -0
  31. package/package.json +6 -6
  32. package/src/additional/MaterialLabelRenderer.tsx +5 -7
  33. package/src/cells/MaterialEnumCell.tsx +4 -3
  34. package/src/cells/MaterialOneOfEnumCell.tsx +3 -3
  35. package/src/controls/MaterialEnumControl.tsx +12 -5
  36. package/src/controls/MaterialOneOfEnumControl.tsx +13 -5
  37. package/src/layouts/MaterialCategorizationLayout.tsx +18 -9
  38. package/src/layouts/MaterialCategorizationStepperLayout.tsx +19 -12
  39. package/src/layouts/MaterialGroupLayout.tsx +6 -5
  40. package/src/mui-controls/MuiAutocomplete.tsx +81 -38
  41. package/src/mui-controls/MuiInputText.tsx +4 -1
  42. package/src/mui-controls/MuiSelect.tsx +10 -5
  43. package/src/util/i18nDefaults.ts +3 -0
  44. package/src/util/index.ts +1 -0
  45. package/src/util/layout.tsx +4 -0
  46. package/stats.html +1 -1
  47. package/test/renderers/MaterialArrayLayout.test.tsx +4 -4
  48. package/test/renderers/MaterialCategorizationLayout.test.tsx +17 -7
  49. package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +21 -11
  50. package/test/renderers/MaterialGroupLayout.test.tsx +4 -1
  51. package/test/renderers/MaterialInputControl.test.tsx +4 -0
  52. package/test/renderers/MaterialLabelRenderer.test.tsx +2 -1
  53. package/test/renderers/util.ts +5 -0
@@ -1,17 +1,18 @@
1
- import React from 'react';
1
+ /// <reference types="react" />
2
2
  import { RankedTester, StatePropsOfLayout, Tester } from '@jsonforms/core';
3
+ import { TranslateProps } from '@jsonforms/react';
3
4
  import { AjvProps } from '../util/layout';
4
5
  export declare const isSingleLevelCategorization: Tester;
5
6
  export declare const materialCategorizationTester: RankedTester;
6
7
  export interface CategorizationState {
7
8
  activeCategory: number;
8
9
  }
9
- export interface MaterialCategorizationLayoutRendererProps extends StatePropsOfLayout, AjvProps {
10
+ export interface MaterialCategorizationLayoutRendererProps extends StatePropsOfLayout, AjvProps, TranslateProps {
10
11
  selected?: number;
11
12
  ownState?: boolean;
12
13
  data?: any;
13
14
  onChange?(selected: number, prevSelected: number): void;
14
15
  }
15
16
  export declare const MaterialCategorizationLayoutRenderer: (props: MaterialCategorizationLayoutRendererProps) => JSX.Element;
16
- declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfLayout>;
17
+ declare const _default: (props: MaterialCategorizationLayoutRendererProps & import("@jsonforms/core").OwnPropsOfLayout) => JSX.Element;
17
18
  export default _default;
@@ -1,13 +1,14 @@
1
- import React from 'react';
1
+ /// <reference types="react" />
2
2
  import { RankedTester, StatePropsOfLayout } from '@jsonforms/core';
3
+ import { TranslateProps } from '@jsonforms/react';
3
4
  import { AjvProps } from '../util/layout';
4
5
  export declare const materialCategorizationStepperTester: RankedTester;
5
6
  export interface CategorizationStepperState {
6
7
  activeCategory: number;
7
8
  }
8
- export interface MaterialCategorizationStepperLayoutRendererProps extends StatePropsOfLayout, AjvProps {
9
+ export interface MaterialCategorizationStepperLayoutRendererProps extends StatePropsOfLayout, AjvProps, TranslateProps {
9
10
  data: any;
10
11
  }
11
12
  export declare const MaterialCategorizationStepperLayoutRenderer: (props: MaterialCategorizationStepperLayoutRendererProps) => JSX.Element;
12
- declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfLayout>;
13
+ declare const _default: (props: MaterialCategorizationStepperLayoutRendererProps & import("@jsonforms/core").OwnPropsOfLayout) => JSX.Element;
13
14
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { LayoutProps, RankedTester } from '@jsonforms/core';
3
3
  export declare const groupTester: RankedTester;
4
- export declare const MaterializedGroupLayoutRenderer: ({ uischema, schema, path, visible, enabled, renderers, cells, direction }: LayoutProps) => JSX.Element;
5
- declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfLayout>;
4
+ export declare const MaterializedGroupLayoutRenderer: ({ uischema, schema, path, visible, enabled, renderers, cells, direction, label }: LayoutProps) => JSX.Element;
5
+ declare const _default: React.ComponentType<LayoutProps & import("@jsonforms/core").OwnPropsOfLayout>;
6
6
  export default _default;
7
7
  export declare const materialGroupTester: RankedTester;
@@ -6,5 +6,5 @@ import { LayoutProps, RankedTester } from '@jsonforms/core';
6
6
  */
7
7
  export declare const materialHorizontalLayoutTester: RankedTester;
8
8
  export declare const MaterialHorizontalLayoutRenderer: ({ uischema, renderers, cells, schema, path, enabled, visible }: LayoutProps) => JSX.Element;
9
- declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfLayout>;
9
+ declare const _default: React.ComponentType<LayoutProps & import("@jsonforms/core").OwnPropsOfLayout>;
10
10
  export default _default;
@@ -6,5 +6,5 @@ import { LayoutProps, RankedTester } from '@jsonforms/core';
6
6
  */
7
7
  export declare const materialVerticalLayoutTester: RankedTester;
8
8
  export declare const MaterialVerticalLayoutRenderer: ({ uischema, schema, path, enabled, visible, renderers, cells }: LayoutProps) => JSX.Element;
9
- declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfLayout>;
9
+ declare const _default: React.ComponentType<LayoutProps & import("@jsonforms/core").OwnPropsOfLayout>;
10
10
  export default _default;
@@ -1,9 +1,9 @@
1
1
  import React, { ReactNode } from 'react';
2
- import { EnumCellProps, EnumOption, WithClassname } from '@jsonforms/core';
2
+ import { ControlProps, EnumCellProps, EnumOption, WithClassname } from '@jsonforms/core';
3
3
  import { AutocompleteRenderOptionState, FilterOptionsState } from '@mui/material';
4
4
  export interface WithOptionLabel {
5
5
  getOptionLabel?(option: EnumOption): string;
6
6
  renderOption?(props: React.HTMLAttributes<HTMLLIElement>, option: EnumOption, state: AutocompleteRenderOptionState): ReactNode;
7
7
  filterOptions?(options: EnumOption[], state: FilterOptionsState<EnumOption>): EnumOption[];
8
8
  }
9
- export declare const MuiAutocomplete: (props: EnumCellProps & WithClassname & WithOptionLabel) => JSX.Element;
9
+ export declare const MuiAutocomplete: (props: ControlProps & EnumCellProps & WithClassname & WithOptionLabel) => JSX.Element;
@@ -1,3 +1,4 @@
1
1
  import React from 'react';
2
2
  import { EnumCellProps, WithClassname } from '@jsonforms/core';
3
- export declare const MuiSelect: React.MemoExoticComponent<(props: EnumCellProps & WithClassname) => JSX.Element>;
3
+ import { TranslateProps } from '@jsonforms/react';
4
+ export declare const MuiSelect: React.MemoExoticComponent<(props: EnumCellProps & WithClassname & TranslateProps) => JSX.Element>;
@@ -0,0 +1,3 @@
1
+ export declare const i18nDefaults: {
2
+ 'enum.none': string;
3
+ };
@@ -3,3 +3,4 @@ export * from './layout';
3
3
  export * from './theme';
4
4
  export * from './debounce';
5
5
  export * from './focus';
6
+ export * from './i18nDefaults';
@@ -13,3 +13,6 @@ export interface AjvProps {
13
13
  ajv: Ajv;
14
14
  }
15
15
  export declare const withAjvProps: <P extends {}>(Component: React.ComponentType<AjvProps & P>) => (props: P) => JSX.Element;
16
+ export interface MaterialLabelableLayoutRendererProps extends MaterialLayoutRendererProps {
17
+ label?: string;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/material-renderers",
3
- "version": "3.0.0-beta.5",
3
+ "version": "3.0.0-rc.0",
4
4
  "description": "Material Renderer Set for JSON Forms",
5
5
  "repository": "https://github.com/eclipsesource/jsonforms",
6
6
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
@@ -76,8 +76,8 @@
76
76
  "peerDependencies": {
77
77
  "@emotion/react": "^11.4.1",
78
78
  "@emotion/styled": "^11.3.0",
79
- "@jsonforms/core": "3.0.0-beta.5",
80
- "@jsonforms/react": "3.0.0-beta.5",
79
+ "@jsonforms/core": "3.0.0-rc.0",
80
+ "@jsonforms/react": "3.0.0-rc.0",
81
81
  "@mui/icons-material": "^5.0.0",
82
82
  "@mui/lab": "^5.0.0-alpha.54",
83
83
  "@mui/material": "^5.0.0"
@@ -85,8 +85,8 @@
85
85
  "devDependencies": {
86
86
  "@emotion/react": "^11.5.0",
87
87
  "@emotion/styled": "^11.3.0",
88
- "@jsonforms/core": "^3.0.0-beta.5",
89
- "@jsonforms/react": "^3.0.0-beta.5",
88
+ "@jsonforms/core": "^3.0.0-rc.0",
89
+ "@jsonforms/react": "^3.0.0-rc.0",
90
90
  "@mui/icons-material": "^5.2.0",
91
91
  "@mui/lab": "^5.0.0-alpha.58",
92
92
  "@mui/material": "^5.2.2",
@@ -114,5 +114,5 @@
114
114
  "webpack-cli": "^3.2.1",
115
115
  "webpack-dev-server": "^3.9.0"
116
116
  },
117
- "gitHead": "b66023cf081e56baa3194ac3d6658e23fd267bf9"
117
+ "gitHead": "5ef030e8b3f91bcdc3e6b8d232a0b191bf1195ce"
118
118
  }
@@ -24,13 +24,12 @@
24
24
  */
25
25
  import React from 'react';
26
26
  import {
27
- LabelElement,
28
- OwnPropsOfRenderer,
27
+ LabelProps,
29
28
  RankedTester,
30
29
  rankWith,
31
30
  uiTypeIs,
32
31
  } from '@jsonforms/core';
33
- import { withJsonFormsLayoutProps } from '@jsonforms/react';
32
+ import { withJsonFormsLabelProps } from '@jsonforms/react';
34
33
  import {
35
34
  Hidden,
36
35
  Typography
@@ -45,15 +44,14 @@ export const materialLabelRendererTester: RankedTester = rankWith(1, uiTypeIs('L
45
44
  /**
46
45
  * Default renderer for a label.
47
46
  */
48
- export const MaterialLabelRenderer = ({ uischema, visible }: OwnPropsOfRenderer) => {
49
- const labelElement: LabelElement = uischema as LabelElement;
47
+ export const MaterialLabelRenderer = ({ text, visible }: LabelProps ) => {
50
48
  return (
51
49
  <Hidden xsUp={!visible}>
52
50
  <Typography variant='h6'>
53
- {labelElement.text !== undefined && labelElement.text !== null && labelElement.text}
51
+ {text}
54
52
  </Typography>
55
53
  </Hidden>
56
54
  );
57
55
  };
58
56
 
59
- export default withJsonFormsLayoutProps(MaterialLabelRenderer);
57
+ export default withJsonFormsLabelProps(MaterialLabelRenderer);
@@ -30,10 +30,10 @@ import {
30
30
  rankWith,
31
31
  WithClassname
32
32
  } from '@jsonforms/core';
33
- import { withJsonFormsEnumCellProps } from '@jsonforms/react';
33
+ import { TranslateProps, withJsonFormsEnumCellProps, withTranslateProps } from '@jsonforms/react';
34
34
  import { MuiSelect } from '../mui-controls/MuiSelect';
35
35
 
36
- export const MaterialEnumCell = (props: EnumCellProps & WithClassname) => (
36
+ export const MaterialEnumCell = (props: EnumCellProps & WithClassname & TranslateProps) => (
37
37
  <MuiSelect {...props} />
38
38
  );
39
39
 
@@ -43,4 +43,5 @@ export const MaterialEnumCell = (props: EnumCellProps & WithClassname) => (
43
43
  */
44
44
  export const materialEnumCellTester: RankedTester = rankWith(2, isEnumControl);
45
45
 
46
- export default withJsonFormsEnumCellProps(MaterialEnumCell);
46
+ // HOC order can be reversed with https://github.com/eclipsesource/jsonforms/issues/1987
47
+ export default withJsonFormsEnumCellProps(withTranslateProps(React.memo(MaterialEnumCell)), false);
@@ -30,10 +30,10 @@ import {
30
30
  rankWith,
31
31
  WithClassname
32
32
  } from '@jsonforms/core';
33
- import { withJsonFormsOneOfEnumCellProps } from '@jsonforms/react';
33
+ import { TranslateProps, withJsonFormsOneOfEnumCellProps, withTranslateProps } from '@jsonforms/react';
34
34
  import { MuiSelect } from '../mui-controls/MuiSelect';
35
35
 
36
- export const MaterialOneOfEnumCell = (props: EnumCellProps & WithClassname) => (
36
+ export const MaterialOneOfEnumCell = (props: EnumCellProps & WithClassname & TranslateProps) => (
37
37
  <MuiSelect {...props} />
38
38
  );
39
39
 
@@ -43,4 +43,4 @@ export const MaterialOneOfEnumCell = (props: EnumCellProps & WithClassname) => (
43
43
  */
44
44
  export const materialOneOfEnumCellTester: RankedTester = rankWith(2, isOneOfEnumControl);
45
45
 
46
- export default withJsonFormsOneOfEnumCellProps(MaterialOneOfEnumCell);
46
+ export default withJsonFormsOneOfEnumCellProps(withTranslateProps(React.memo(MaterialOneOfEnumCell)), false);
@@ -30,19 +30,25 @@ import {
30
30
  RankedTester,
31
31
  rankWith,
32
32
  } from '@jsonforms/core';
33
- import { withJsonFormsEnumProps } from '@jsonforms/react';
33
+ import { TranslateProps, withJsonFormsEnumProps, withTranslateProps } from '@jsonforms/react';
34
34
  import { MuiSelect } from '../mui-controls/MuiSelect';
35
35
  import merge from 'lodash/merge';
36
36
  import { MaterialInputControl } from './MaterialInputControl';
37
37
  import { MuiAutocomplete, WithOptionLabel } from '../mui-controls/MuiAutocomplete';
38
38
 
39
- export const MaterialEnumControl = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel) => {
40
- const {config, uischema} = props;
39
+ export const MaterialEnumControl = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel & TranslateProps) => {
40
+ const {config, uischema, errors} = props;
41
41
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
42
+ const isValid = errors.length === 0;
42
43
  return (
44
+ appliedUiSchemaOptions.autocomplete === false ?
43
45
  <MaterialInputControl
44
46
  {...props}
45
- input={appliedUiSchemaOptions.autocomplete === false ? MuiSelect : MuiAutocomplete}
47
+ input={MuiSelect}
48
+ />:
49
+ <MuiAutocomplete
50
+ {...props}
51
+ isValid={isValid}
46
52
  />
47
53
  );
48
54
  };
@@ -52,4 +58,5 @@ export const materialEnumControlTester: RankedTester = rankWith(
52
58
  isEnumControl
53
59
  );
54
60
 
55
- export default withJsonFormsEnumProps(MaterialEnumControl);
61
+ // HOC order can be reversed with https://github.com/eclipsesource/jsonforms/issues/1987
62
+ export default withJsonFormsEnumProps(withTranslateProps(React.memo(MaterialEnumControl)), false);
@@ -30,19 +30,26 @@ import {
30
30
  RankedTester,
31
31
  rankWith,
32
32
  } from '@jsonforms/core';
33
- import { withJsonFormsOneOfEnumProps } from '@jsonforms/react';
33
+ import { TranslateProps, withJsonFormsOneOfEnumProps, withTranslateProps } from '@jsonforms/react';
34
34
  import { MuiAutocomplete, WithOptionLabel } from '../mui-controls/MuiAutocomplete';
35
35
  import { MuiSelect } from '../mui-controls/MuiSelect';
36
36
  import { MaterialInputControl } from '../controls/MaterialInputControl';
37
37
  import merge from 'lodash/merge';
38
38
 
39
- export const MaterialOneOfEnumControl = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel) => {
40
- const {config, uischema} = props;
39
+ export const MaterialOneOfEnumControl = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel & TranslateProps) => {
40
+ const {config, uischema, errors} = props;
41
41
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
42
+ const isValid = errors.length === 0;
43
+
42
44
  return (
45
+ appliedUiSchemaOptions.autocomplete === false ?
43
46
  <MaterialInputControl
44
47
  {...props}
45
- input={appliedUiSchemaOptions.autocomplete === false ? MuiSelect : MuiAutocomplete}
48
+ input={MuiSelect}
49
+ />:
50
+ <MuiAutocomplete
51
+ {...props}
52
+ isValid={isValid}
46
53
  />
47
54
  );
48
55
  };
@@ -52,4 +59,5 @@ export const materialOneOfEnumControlTester: RankedTester = rankWith(
52
59
  isOneOfEnumControl
53
60
  );
54
61
 
55
- export default withJsonFormsOneOfEnumProps(MaterialOneOfEnumControl);
62
+ // HOC order can be reversed with https://github.com/eclipsesource/jsonforms/issues/1987
63
+ export default withJsonFormsOneOfEnumProps(withTranslateProps(React.memo(MaterialOneOfEnumControl)), false);
@@ -22,12 +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, {useState} from 'react';
25
+ import React, {useState, useMemo} from 'react';
26
26
  import { AppBar, Hidden, Tab, Tabs } from '@mui/material';
27
27
  import {
28
28
  and,
29
29
  Categorization,
30
30
  Category,
31
+ deriveLabelForUISchemaElement,
31
32
  isVisible,
32
33
  RankedTester,
33
34
  rankWith,
@@ -36,7 +37,7 @@ import {
36
37
  UISchemaElement,
37
38
  uiTypeIs
38
39
  } from '@jsonforms/core';
39
- import { withJsonFormsLayoutProps } from '@jsonforms/react';
40
+ import { TranslateProps, withJsonFormsLayoutProps, withTranslateProps } from '@jsonforms/react';
40
41
  import {
41
42
  AjvProps,
42
43
  MaterialLayoutRenderer,
@@ -68,7 +69,7 @@ export interface CategorizationState {
68
69
  }
69
70
 
70
71
  export interface MaterialCategorizationLayoutRendererProps
71
- extends StatePropsOfLayout, AjvProps {
72
+ extends StatePropsOfLayout, AjvProps, TranslateProps {
72
73
  selected?: number;
73
74
  ownState?: boolean;
74
75
  data?: any;
@@ -87,13 +88,14 @@ export const MaterialCategorizationLayoutRenderer = (props: MaterialCategorizati
87
88
  enabled,
88
89
  selected,
89
90
  onChange,
90
- ajv
91
+ ajv,
92
+ t
91
93
  } = props;
92
94
  const categorization = uischema as Categorization;
93
95
  const [activeCategory, setActiveCategory]= useState<number|undefined>(selected??0);
94
- const categories = categorization.elements.filter((category: Category) =>
96
+ const categories = useMemo(() => categorization.elements.filter((category: Category) =>
95
97
  isVisible(category, data, undefined, ajv)
96
- );
98
+ ),[categorization, data, ajv]);
97
99
  const childProps: MaterialLayoutRendererProps = {
98
100
  elements: categories[activeCategory].elements,
99
101
  schema,
@@ -110,12 +112,19 @@ export const MaterialCategorizationLayoutRenderer = (props: MaterialCategorizati
110
112
  }
111
113
  setActiveCategory(value);
112
114
  };
115
+
116
+ const tabLabels = useMemo(() => {
117
+ return categories.map((e: Category) =>
118
+ deriveLabelForUISchemaElement(e, t)
119
+ )
120
+ }, [categories, t])
121
+
113
122
  return (
114
123
  <Hidden xsUp={!visible}>
115
124
  <AppBar position='static'>
116
125
  <Tabs value={activeCategory} onChange={onTabChange} textColor='inherit' indicatorColor='secondary' variant='scrollable'>
117
- {categories.map((e: Category, idx: number) => (
118
- <Tab key={idx} label={e.label} />
126
+ {categories.map((_, idx: number) => (
127
+ <Tab key={idx} label={tabLabels[idx]} />
119
128
  ))}
120
129
  </Tabs>
121
130
  </AppBar>
@@ -126,4 +135,4 @@ export const MaterialCategorizationLayoutRenderer = (props: MaterialCategorizati
126
135
  );
127
136
  };
128
137
 
129
- export default withJsonFormsLayoutProps(withAjvProps(MaterialCategorizationLayoutRenderer));
138
+ export default withAjvProps(withTranslateProps(withJsonFormsLayoutProps(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, {useState} from 'react';
25
+ import React, {useState, useMemo} from 'react';
26
26
  import merge from 'lodash/merge';
27
27
  import { Button, Hidden, Step, StepButton, Stepper } from '@mui/material';
28
28
  import {
@@ -30,6 +30,7 @@ import {
30
30
  Categorization,
31
31
  categorizationHasCategory,
32
32
  Category,
33
+ deriveLabelForUISchemaElement,
33
34
  isVisible,
34
35
  optionIs,
35
36
  RankedTester,
@@ -37,7 +38,7 @@ import {
37
38
  StatePropsOfLayout,
38
39
  uiTypeIs
39
40
  } from '@jsonforms/core';
40
- import { withJsonFormsLayoutProps } from '@jsonforms/react';
41
+ import { TranslateProps, withJsonFormsLayoutProps, withTranslateProps } from '@jsonforms/react';
41
42
  import {
42
43
  AjvProps,
43
44
  MaterialLayoutRenderer,
@@ -59,7 +60,7 @@ export interface CategorizationStepperState {
59
60
  }
60
61
 
61
62
  export interface MaterialCategorizationStepperLayoutRendererProps
62
- extends StatePropsOfLayout, AjvProps {
63
+ extends StatePropsOfLayout, AjvProps, TranslateProps {
63
64
  data: any;
64
65
  }
65
66
 
@@ -79,7 +80,8 @@ export const MaterialCategorizationStepperLayoutRenderer = (props: MaterialCateg
79
80
  visible,
80
81
  cells,
81
82
  config,
82
- ajv
83
+ ajv,
84
+ t
83
85
  } = props;
84
86
  const categorization = uischema as Categorization;
85
87
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
@@ -94,9 +96,9 @@ export const MaterialCategorizationStepperLayoutRenderer = (props: MaterialCateg
94
96
  const buttonStyle = {
95
97
  marginRight: '1em'
96
98
  };
97
- const categories = categorization.elements.filter((category: Category) =>
99
+ const categories = useMemo(() => categorization.elements.filter((category: Category) =>
98
100
  isVisible(category, data, undefined, ajv)
99
- );
101
+ ),[categorization, data, ajv]);
100
102
  const childProps: MaterialLayoutRendererProps = {
101
103
  elements: categories[activeCategory].elements,
102
104
  schema,
@@ -106,13 +108,18 @@ export const MaterialCategorizationStepperLayoutRenderer = (props: MaterialCateg
106
108
  renderers,
107
109
  cells
108
110
  };
111
+ const tabLabels = useMemo(() => {
112
+ return categories.map((e: Category) =>
113
+ deriveLabelForUISchemaElement(e, t)
114
+ )
115
+ }, [categories, t])
109
116
  return (
110
117
  <Hidden xsUp={!visible}>
111
118
  <Stepper activeStep={activeCategory} nonLinear>
112
- {categories.map((e: Category, idx: number) => (
113
- <Step key={e.label}>
119
+ {categories.map((_: Category, idx: number) => (
120
+ <Step key={tabLabels[idx]}>
114
121
  <StepButton onClick={() => handleStep(idx)}>
115
- {e.label}
122
+ {tabLabels[idx]}
116
123
  </StepButton>
117
124
  </Step>
118
125
  ))}
@@ -144,6 +151,6 @@ export const MaterialCategorizationStepperLayoutRenderer = (props: MaterialCateg
144
151
  );
145
152
  };
146
153
 
147
- export default withJsonFormsLayoutProps(withAjvProps(
148
- MaterialCategorizationStepperLayoutRenderer
149
- ));
154
+ export default withAjvProps(withTranslateProps(
155
+ withJsonFormsLayoutProps(MaterialCategorizationStepperLayoutRenderer
156
+ )));
@@ -34,21 +34,21 @@ import {
34
34
  withIncreasedRank,
35
35
  } from '@jsonforms/core';
36
36
  import {
37
+ MaterialLabelableLayoutRendererProps,
37
38
  MaterialLayoutRenderer,
38
- MaterialLayoutRendererProps
39
39
  } from '../util/layout';
40
40
  import { withJsonFormsLayoutProps } from '@jsonforms/react';
41
41
 
42
42
  export const groupTester: RankedTester = rankWith(1, uiTypeIs('Group'));
43
43
  const style: { [x: string]: any } = { marginBottom: '10px' };
44
44
 
45
- const GroupComponent = React.memo(({ visible, enabled, uischema, ...props }: MaterialLayoutRendererProps) => {
45
+ const GroupComponent = React.memo(({ visible, enabled, uischema, label, ...props }: MaterialLabelableLayoutRendererProps) => {
46
46
  const groupLayout = uischema as GroupLayout;
47
47
  return (
48
48
  <Hidden xsUp={!visible}>
49
49
  <Card style={style}>
50
- {!isEmpty(groupLayout.label) && (
51
- <CardHeader title={groupLayout.label} />
50
+ {!isEmpty(label) && (
51
+ <CardHeader title={label} />
52
52
  )}
53
53
  <CardContent>
54
54
  <MaterialLayoutRenderer {...props} visible={visible} enabled={enabled} elements={groupLayout.elements} />
@@ -58,7 +58,7 @@ const GroupComponent = React.memo(({ visible, enabled, uischema, ...props }: Mat
58
58
  );
59
59
  });
60
60
 
61
- export const MaterializedGroupLayoutRenderer = ({ uischema, schema, path, visible, enabled, renderers, cells, direction }: LayoutProps) => {
61
+ export const MaterializedGroupLayoutRenderer = ({ uischema, schema, path, visible, enabled, renderers, cells, direction, label }: LayoutProps) => {
62
62
  const groupLayout = uischema as GroupLayout;
63
63
 
64
64
  return (
@@ -72,6 +72,7 @@ export const MaterializedGroupLayoutRenderer = ({ uischema, schema, path, visibl
72
72
  uischema={uischema}
73
73
  renderers={renderers}
74
74
  cells={cells}
75
+ label={label}
75
76
  />
76
77
  );
77
78
  };
@@ -23,15 +23,18 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
  import React, { ReactNode } from 'react';
26
- import { EnumCellProps, EnumOption, WithClassname } from '@jsonforms/core';
26
+ import { ControlProps, EnumCellProps, EnumOption, isDescriptionHidden, WithClassname } from '@jsonforms/core';
27
27
 
28
28
  import {
29
29
  Autocomplete,
30
30
  AutocompleteRenderOptionState,
31
- Input,
32
- FilterOptionsState
31
+ FilterOptionsState,
32
+ FormHelperText,
33
+ Hidden,
34
+ TextField
33
35
  } from '@mui/material';
34
36
  import merge from 'lodash/merge';
37
+ import { useFocus } from '../util/focus';
35
38
 
36
39
  export interface WithOptionLabel {
37
40
  getOptionLabel?(option: EnumOption) : string;
@@ -39,8 +42,13 @@ export interface WithOptionLabel {
39
42
  filterOptions?(options: EnumOption[], state: FilterOptionsState<EnumOption>) : EnumOption[];
40
43
  }
41
44
 
42
- export const MuiAutocomplete = (props: EnumCellProps & WithClassname & WithOptionLabel) => {
45
+ export const MuiAutocomplete = (props: ControlProps & EnumCellProps & WithClassname & WithOptionLabel) => {
43
46
  const {
47
+ description,
48
+ errors,
49
+ visible,
50
+ required,
51
+ label,
44
52
  data,
45
53
  className,
46
54
  id,
@@ -52,45 +60,80 @@ export const MuiAutocomplete = (props: EnumCellProps & WithClassname & WithOptio
52
60
  config,
53
61
  getOptionLabel,
54
62
  renderOption,
55
- filterOptions
63
+ filterOptions,
64
+ isValid
56
65
  } = props;
57
66
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
58
67
  const [inputValue, setInputValue] = React.useState(data ?? '');
68
+ const [focused, onFocus, onBlur] = useFocus();
59
69
 
60
70
  const findOption = options.find(o => o.value === data) ?? null;
71
+
72
+ const showDescription = !isDescriptionHidden(
73
+ visible,
74
+ description,
75
+ focused,
76
+ appliedUiSchemaOptions.showUnfocusedDescription
77
+ );
78
+
79
+ const firstFormHelperText = showDescription
80
+ ? description
81
+ : !isValid
82
+ ? errors
83
+ : null;
84
+ const secondFormHelperText = showDescription && !isValid ? errors : null;
85
+
61
86
  return (
62
- <Autocomplete
63
- className={className}
64
- id={id}
65
- disabled={!enabled}
66
- value={findOption}
67
- onChange={(_event: any, newValue: EnumOption | null) => {
68
- handleChange(path, newValue?.value);
69
- }}
70
- inputValue={inputValue}
71
- onInputChange={(_event, newInputValue) => {
72
- setInputValue(newInputValue);
73
- }}
74
- autoHighlight
75
- autoSelect
76
- autoComplete
77
- fullWidth
78
- options={options}
79
- getOptionLabel={getOptionLabel || (option => option?.label)}
80
- freeSolo={false}
81
- style={{ marginTop: 16 }}
82
- renderInput={params => (
83
- <Input
84
- style={{ width: '100%' }}
85
- type='text'
86
- inputProps={params.inputProps}
87
- inputRef={params.InputProps.ref}
88
- autoFocus={appliedUiSchemaOptions.focus}
89
- disabled={!enabled}
90
- />
91
- )}
92
- renderOption={renderOption}
93
- filterOptions={filterOptions}
94
- />
87
+ <Hidden xsUp={!visible}>
88
+ <Autocomplete
89
+ className={className}
90
+ id={id}
91
+ disabled={!enabled}
92
+ value={findOption}
93
+ onChange={(_event: any, newValue: EnumOption | null) => {
94
+ handleChange(path, newValue?.value);
95
+ }}
96
+ inputValue={inputValue}
97
+ onInputChange={(_event, newInputValue) => {
98
+ setInputValue(newInputValue);
99
+ }}
100
+ autoHighlight
101
+ autoSelect
102
+ autoComplete
103
+ fullWidth
104
+ options={options}
105
+ getOptionLabel={getOptionLabel || (option => option?.label)}
106
+ freeSolo={false}
107
+ renderInput={params => {
108
+ return(
109
+ <TextField
110
+ label={label}
111
+ variant={'standard'}
112
+ type='text'
113
+ inputProps={params.inputProps}
114
+ inputRef={params.InputProps.ref}
115
+ autoFocus={appliedUiSchemaOptions.focus}
116
+ disabled={!enabled}
117
+ {...params}
118
+ id={id + '-input'}
119
+ required={required && !appliedUiSchemaOptions.hideRequiredAsterisk}
120
+ error={!isValid}
121
+ fullWidth={!appliedUiSchemaOptions.trim}
122
+ InputLabelProps={data ? { shrink: true } : undefined}
123
+ onFocus={onFocus}
124
+ onBlur={onBlur}
125
+ focused={focused}
126
+ />
127
+ )}}
128
+ renderOption={renderOption}
129
+ filterOptions={filterOptions}
130
+ />
131
+ <FormHelperText error={!isValid && !showDescription}>
132
+ {firstFormHelperText}
133
+ </FormHelperText>
134
+ <FormHelperText error={!isValid}>
135
+ {secondFormHelperText}
136
+ </FormHelperText>
137
+ </Hidden>
95
138
  );
96
139
  };