@jsonforms/material-renderers 3.1.1-alpha.0 → 3.2.0-alpha.1

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 (34) hide show
  1. package/lib/cells/MaterialDateCell.d.ts +2 -1
  2. package/lib/complex/MaterialAnyOfRenderer.d.ts +2 -2
  3. package/lib/complex/TabSwitchConfirmDialog.d.ts +9 -0
  4. package/lib/complex/unwrapped.d.ts +1 -1
  5. package/lib/index.d.ts +1 -1
  6. package/lib/jsonforms-react-material.cjs.js +102 -43
  7. package/lib/jsonforms-react-material.cjs.js.map +1 -1
  8. package/lib/jsonforms-react-material.esm.js +90 -42
  9. package/lib/jsonforms-react-material.esm.js.map +1 -1
  10. package/lib/mui-controls/MuiInputInteger.d.ts +2 -1
  11. package/lib/mui-controls/MuiInputNumber.d.ts +2 -1
  12. package/lib/mui-controls/MuiInputNumberFormat.d.ts +2 -1
  13. package/lib/mui-controls/MuiInputText.d.ts +2 -1
  14. package/lib/mui-controls/MuiInputTime.d.ts +2 -1
  15. package/lib/mui-controls/MuiSelect.d.ts +2 -1
  16. package/lib/util/theme.d.ts +8 -1
  17. package/package.json +8 -8
  18. package/src/cells/MaterialDateCell.tsx +21 -6
  19. package/src/complex/MaterialAnyOfRenderer.tsx +49 -6
  20. package/src/complex/MaterialOneOfRenderer.tsx +21 -45
  21. package/src/complex/TabSwitchConfirmDialog.tsx +56 -0
  22. package/src/controls/MaterialAnyOfStringOrEnumControl.tsx +9 -4
  23. package/src/controls/MaterialDateControl.tsx +0 -1
  24. package/src/controls/MaterialDateTimeControl.tsx +0 -1
  25. package/src/controls/MaterialInputControl.tsx +3 -2
  26. package/src/controls/MaterialTimeControl.tsx +0 -1
  27. package/src/mui-controls/MuiAutocomplete.tsx +0 -1
  28. package/src/mui-controls/MuiInputInteger.tsx +16 -6
  29. package/src/mui-controls/MuiInputNumber.tsx +20 -10
  30. package/src/mui-controls/MuiInputNumberFormat.tsx +6 -4
  31. package/src/mui-controls/MuiInputText.tsx +11 -4
  32. package/src/mui-controls/MuiInputTime.tsx +20 -10
  33. package/src/mui-controls/MuiSelect.tsx +4 -3
  34. package/src/util/theme.ts +40 -5
@@ -24,12 +24,11 @@
24
24
  */
25
25
  import React, { useCallback } from 'react';
26
26
  import { CellProps, Formatted, WithClassname } from '@jsonforms/core';
27
- import { Input } from '@mui/material';
28
27
  import merge from 'lodash/merge';
29
- import { useDebouncedChange } from '../util';
28
+ import { useDebouncedChange, useInputComponent, WithInputProps } from '../util';
30
29
 
31
30
  export const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(
32
- props: CellProps & WithClassname & Formatted<number>
31
+ props: CellProps & WithClassname & Formatted<number> & WithInputProps
33
32
  ) {
34
33
  const {
35
34
  className,
@@ -41,7 +40,9 @@ export const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(
41
40
  handleChange,
42
41
  schema,
43
42
  config,
43
+ label,
44
44
  } = props;
45
+ const InputComponent = useInputComponent();
45
46
  const maxLength = schema.maxLength;
46
47
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
47
48
  let inputProps;
@@ -65,12 +66,13 @@ export const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(
65
66
  );
66
67
 
67
68
  return (
68
- <Input
69
+ <InputComponent
69
70
  type='text'
70
71
  value={inputValue}
71
72
  onChange={onChange}
72
73
  className={className}
73
74
  id={id}
75
+ label={label}
74
76
  disabled={!enabled}
75
77
  autoFocus={appliedUiSchemaOptions.focus}
76
78
  multiline={appliedUiSchemaOptions.multi}
@@ -26,7 +26,6 @@ import React, { useState } from 'react';
26
26
  import { CellProps, WithClassname } from '@jsonforms/core';
27
27
  import {
28
28
  IconButton,
29
- Input,
30
29
  InputAdornment,
31
30
  InputBaseComponentProps,
32
31
  InputProps,
@@ -34,7 +33,12 @@ import {
34
33
  } from '@mui/material';
35
34
  import merge from 'lodash/merge';
36
35
  import Close from '@mui/icons-material/Close';
37
- import { JsonFormsTheme, useDebouncedChange } from '../util';
36
+ import {
37
+ JsonFormsTheme,
38
+ WithInputProps,
39
+ useDebouncedChange,
40
+ useInputComponent,
41
+ } from '../util';
38
42
 
39
43
  interface MuiTextInputProps {
40
44
  muiInputProps?: InputProps['inputProps'];
@@ -45,7 +49,7 @@ const eventToValue = (ev: any) =>
45
49
  ev.target.value === '' ? undefined : ev.target.value;
46
50
 
47
51
  export const MuiInputText = React.memo(function MuiInputText(
48
- props: CellProps & WithClassname & MuiTextInputProps
52
+ props: CellProps & WithClassname & MuiTextInputProps & WithInputProps
49
53
  ) {
50
54
  const [showAdornment, setShowAdornment] = useState(false);
51
55
  const {
@@ -60,8 +64,10 @@ export const MuiInputText = React.memo(function MuiInputText(
60
64
  handleChange,
61
65
  schema,
62
66
  muiInputProps,
67
+ label,
63
68
  inputComponent,
64
69
  } = props;
70
+ const InputComponent = useInputComponent();
65
71
  const maxLength = schema.maxLength;
66
72
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
67
73
  let inputProps: InputBaseComponentProps;
@@ -97,7 +103,8 @@ export const MuiInputText = React.memo(function MuiInputText(
97
103
  };
98
104
 
99
105
  return (
100
- <Input
106
+ <InputComponent
107
+ label={label}
101
108
  type={appliedUiSchemaOptions.format === 'password' ? 'password' : 'text'}
102
109
  value={inputText}
103
110
  onChange={onChange}
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2017-2019 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
8
8
  of this software and associated documentation files (the "Software"), to deal
9
9
  in the Software without restriction, including without limitation the rights
10
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
11
  copies of the Software, and to permit persons to whom the Software is
12
12
  furnished to do so, subject to the following conditions:
13
-
13
+
14
14
  The above copyright notice and this permission notice shall be included in
15
15
  all copies or substantial portions of the Software.
16
-
16
+
17
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -24,15 +24,24 @@
24
24
  */
25
25
  import React from 'react';
26
26
  import { CellProps, WithClassname } from '@jsonforms/core';
27
- import { Input } from '@mui/material';
28
27
  import merge from 'lodash/merge';
29
- import { useDebouncedChange } from '../util';
28
+ import { WithInputProps, useDebouncedChange, useInputComponent } from '../util';
30
29
 
31
30
  export const MuiInputTime = React.memo(function MuiInputTime(
32
- props: CellProps & WithClassname
31
+ props: CellProps & WithClassname & WithInputProps
33
32
  ) {
34
- const { data, className, id, enabled, uischema, path, handleChange, config } =
35
- props;
33
+ const {
34
+ data,
35
+ className,
36
+ id,
37
+ enabled,
38
+ uischema,
39
+ path,
40
+ handleChange,
41
+ config,
42
+ label,
43
+ } = props;
44
+ const InputComponent = useInputComponent();
36
45
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
37
46
  const [inputValue, onChange] = useDebouncedChange(
38
47
  handleChange,
@@ -42,12 +51,13 @@ export const MuiInputTime = React.memo(function MuiInputTime(
42
51
  );
43
52
 
44
53
  return (
45
- <Input
54
+ <InputComponent
46
55
  type='time'
47
56
  value={inputValue}
48
57
  onChange={onChange}
49
58
  className={className}
50
59
  id={id}
60
+ label={label}
51
61
  disabled={!enabled}
52
62
  autoFocus={appliedUiSchemaOptions.focus}
53
63
  fullWidth={true}
@@ -28,10 +28,10 @@ import { EnumCellProps, WithClassname } from '@jsonforms/core';
28
28
  import { MenuItem, Select } from '@mui/material';
29
29
  import merge from 'lodash/merge';
30
30
  import { TranslateProps } from '@jsonforms/react';
31
- import { i18nDefaults } from '../util';
31
+ import { i18nDefaults, WithInputProps } from '../util';
32
32
 
33
33
  export const MuiSelect = React.memo(function MuiSelect(
34
- props: EnumCellProps & WithClassname & TranslateProps
34
+ props: EnumCellProps & WithClassname & TranslateProps & WithInputProps
35
35
  ) {
36
36
  const {
37
37
  data,
@@ -44,6 +44,7 @@ export const MuiSelect = React.memo(function MuiSelect(
44
44
  handleChange,
45
45
  options,
46
46
  config,
47
+ label,
47
48
  t,
48
49
  } = props;
49
50
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
@@ -56,12 +57,12 @@ export const MuiSelect = React.memo(function MuiSelect(
56
57
  <Select
57
58
  className={className}
58
59
  id={id}
60
+ label={label}
59
61
  disabled={!enabled}
60
62
  autoFocus={appliedUiSchemaOptions.focus}
61
63
  value={data !== undefined ? data : ''}
62
64
  onChange={(ev) => handleChange(path, ev.target.value || undefined)}
63
65
  fullWidth={true}
64
- variant={'standard'}
65
66
  >
66
67
  {[
67
68
  <MenuItem value={''} key='jsonforms.enum.none'>
package/src/util/theme.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2017-2019 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
8
8
  of this software and associated documentation files (the "Software"), to deal
9
9
  in the Software without restriction, including without limitation the rights
10
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
11
  copies of the Software, and to permit persons to whom the Software is
12
12
  furnished to do so, subject to the following conditions:
13
-
13
+
14
14
  The above copyright notice and this permission notice shall be included in
15
15
  all copies or substantial portions of the Software.
16
-
16
+
17
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -22,7 +22,15 @@
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 { Theme } from '@mui/material';
25
+ import {
26
+ Theme,
27
+ FilledInput,
28
+ Input,
29
+ OutlinedInput,
30
+ TextFieldProps,
31
+ useThemeProps,
32
+ InputBaseProps,
33
+ } from '@mui/material';
26
34
 
27
35
  export interface JsonFormsTheme extends Theme {
28
36
  jsonforms?: {
@@ -33,3 +41,30 @@ export interface JsonFormsTheme extends Theme {
33
41
  };
34
42
  };
35
43
  }
44
+
45
+ export interface WithInputProps {
46
+ label?: string;
47
+ }
48
+
49
+ const variantToInput = {
50
+ standard: Input,
51
+ filled: FilledInput,
52
+ outlined: OutlinedInput,
53
+ };
54
+
55
+ export const defaultInputVariant: TextFieldProps['variant'] = 'standard';
56
+
57
+ export function useInputVariant(): TextFieldProps['variant'] {
58
+ const { variant = defaultInputVariant } = useThemeProps({
59
+ props: {} as TextFieldProps,
60
+ name: 'MuiTextField',
61
+ });
62
+ return variant;
63
+ }
64
+
65
+ export function useInputComponent(): React.JSXElementConstructor<
66
+ InputBaseProps & WithInputProps
67
+ > {
68
+ const variant = useInputVariant();
69
+ return variantToInput[variant] ?? variantToInput[defaultInputVariant];
70
+ }