@abgov/jsonforms-components 0.0.1 → 1.1.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 (123) hide show
  1. package/index.esm.d.ts +1 -0
  2. package/index.esm.js +4752 -0
  3. package/package.json +5 -2
  4. package/src/index.d.ts +5 -0
  5. package/src/lib/Additional/HelpContent.d.ts +21 -0
  6. package/src/lib/Additional/styled-components.d.ts +1 -0
  7. package/src/lib/Cells/DateCell.d.ts +6 -0
  8. package/src/lib/Cells/IntegerCell.d.ts +6 -0
  9. package/src/lib/Cells/NumberCell.d.ts +6 -0
  10. package/src/lib/Cells/TextCell.d.ts +6 -0
  11. package/src/lib/Cells/TimeCell.d.ts +6 -0
  12. package/src/lib/Cells/index.d.ts +2 -0
  13. package/src/lib/Context/index.d.ts +39 -0
  14. package/src/lib/Controls/FileUploader/ContextMenu.d.ts +18 -0
  15. package/src/lib/Controls/FileUploader/FileUploaderControl.d.ts +4 -0
  16. package/src/lib/Controls/FileUploader/FileUploaderTester.d.ts +2 -0
  17. package/src/lib/Controls/FileUploader/styled-components.d.ts +1 -0
  18. package/src/lib/Controls/FormStepper/FormStepperControl.d.ts +10 -0
  19. package/src/lib/Controls/FormStepper/FormStepperTester.d.ts +2 -0
  20. package/src/lib/Controls/FormStepper/styled-components.d.ts +3 -0
  21. package/src/lib/Controls/Inputs/InputBaseControl.d.ts +7 -0
  22. package/src/lib/Controls/Inputs/InputBooleanControl.d.ts +6 -0
  23. package/src/lib/Controls/Inputs/InputBooleanRadioControl.d.ts +6 -0
  24. package/src/lib/Controls/Inputs/InputDateControl.d.ts +9 -0
  25. package/src/lib/Controls/Inputs/InputDateTimeControl.d.ts +9 -0
  26. package/src/lib/Controls/Inputs/InputEnum.d.ts +12 -0
  27. package/src/lib/Controls/Inputs/InputEnumAutoComplete.d.ts +10 -0
  28. package/src/lib/Controls/Inputs/InputEnumRadios.d.ts +12 -0
  29. package/src/lib/Controls/Inputs/InputIntegerControl.d.ts +9 -0
  30. package/src/lib/Controls/Inputs/InputMultiLineTextControl.d.ts +9 -0
  31. package/src/lib/Controls/Inputs/InputNumberControl.d.ts +9 -0
  32. package/src/lib/Controls/Inputs/InputTextControl.d.ts +9 -0
  33. package/src/lib/Controls/Inputs/InputTimeControl.d.ts +9 -0
  34. package/src/lib/Controls/Inputs/{type.ts → type.d.ts} +1 -1
  35. package/src/lib/Controls/ObjectArray/DeleteDialog.d.ts +12 -0
  36. package/src/lib/Controls/ObjectArray/ObjectArray.d.ts +6 -0
  37. package/src/lib/Controls/ObjectArray/ObjectArrayToolBar.d.ts +16 -0
  38. package/src/lib/Controls/ObjectArray/ObjectListControl.d.ts +24 -0
  39. package/src/lib/Controls/ObjectArray/styled-components.d.ts +3 -0
  40. package/src/lib/ErrorHandling/GoAErrorControl.d.ts +15 -0
  41. package/src/lib/ErrorHandling/{MessageControl.tsx → MessageControl.d.ts} +1 -8
  42. package/src/lib/ErrorHandling/errorCheck.d.ts +14 -0
  43. package/src/lib/ErrorHandling/schemaValidation.d.ts +11 -0
  44. package/src/lib/common/Grid.d.ts +11 -0
  45. package/src/lib/jsonforms-components.d.ts +4 -0
  46. package/src/lib/layouts/GroupControl.d.ts +5 -0
  47. package/src/lib/layouts/HorizontalLayoutControl.d.ts +5 -0
  48. package/src/lib/layouts/VerticalLayoutControl.d.ts +4 -0
  49. package/src/lib/util/layout.d.ts +8 -0
  50. package/src/lib/util/schemaUtils.d.ts +1 -0
  51. package/src/lib/util/stringUtils.d.ts +33 -0
  52. package/src/lib/util/style-component.d.ts +1 -0
  53. package/.babelrc +0 -12
  54. package/.eslintrc.json +0 -36
  55. package/.releaserc.json +0 -25
  56. package/jest.config.ts +0 -11
  57. package/project.json +0 -55
  58. package/rollup.config.js +0 -14
  59. package/src/index.ts +0 -166
  60. package/src/lib/Additional/HelpContent.tsx +0 -95
  61. package/src/lib/Additional/styled-components.ts +0 -27
  62. package/src/lib/Cells/DateCell.tsx +0 -10
  63. package/src/lib/Cells/IntegerCell.tsx +0 -10
  64. package/src/lib/Cells/NumberCell.tsx +0 -10
  65. package/src/lib/Cells/TextCell.tsx +0 -10
  66. package/src/lib/Cells/TimeCell.tsx +0 -10
  67. package/src/lib/Cells/index.tsx +0 -14
  68. package/src/lib/Context/index.tsx +0 -172
  69. package/src/lib/Controls/FileUploader/ContextMenu.tsx +0 -50
  70. package/src/lib/Controls/FileUploader/FileUploaderControl.tsx +0 -131
  71. package/src/lib/Controls/FileUploader/FileUploaderTester.tsx +0 -3
  72. package/src/lib/Controls/FileUploader/styled-components.tsx +0 -10
  73. package/src/lib/Controls/FormStepper/FormStepperControl.tsx +0 -269
  74. package/src/lib/Controls/FormStepper/FormStepperTester.tsx +0 -22
  75. package/src/lib/Controls/FormStepper/styled-components.tsx +0 -17
  76. package/src/lib/Controls/Inputs/InputBaseControl.tsx +0 -52
  77. package/src/lib/Controls/Inputs/InputBooleanControl.tsx +0 -67
  78. package/src/lib/Controls/Inputs/InputBooleanRadioControl.tsx +0 -74
  79. package/src/lib/Controls/Inputs/InputDateControl.tsx +0 -90
  80. package/src/lib/Controls/Inputs/InputDateTimeControl.tsx +0 -46
  81. package/src/lib/Controls/Inputs/InputEnum.tsx +0 -74
  82. package/src/lib/Controls/Inputs/InputEnumAutoComplete.tsx +0 -73
  83. package/src/lib/Controls/Inputs/InputEnumRadios.tsx +0 -43
  84. package/src/lib/Controls/Inputs/InputIntegerControl.tsx +0 -63
  85. package/src/lib/Controls/Inputs/InputMultiLineTextControl.tsx +0 -63
  86. package/src/lib/Controls/Inputs/InputNumberControl.tsx +0 -63
  87. package/src/lib/Controls/Inputs/InputTextControl.tsx +0 -62
  88. package/src/lib/Controls/Inputs/InputTimeControl.tsx +0 -46
  89. package/src/lib/Controls/Inputs/inputControl.spec.ts +0 -84
  90. package/src/lib/Controls/ObjectArray/DeleteDialog.tsx +0 -49
  91. package/src/lib/Controls/ObjectArray/ObjectArray.tsx +0 -59
  92. package/src/lib/Controls/ObjectArray/ObjectArrayToolBar.tsx +0 -51
  93. package/src/lib/Controls/ObjectArray/ObjectListControl.tsx +0 -368
  94. package/src/lib/Controls/ObjectArray/styled-components.tsx +0 -13
  95. package/src/lib/ErrorHandling/GoAErrorControl.tsx +0 -53
  96. package/src/lib/ErrorHandling/categorizationValidation.spec.ts +0 -98
  97. package/src/lib/ErrorHandling/controlValildation.spec.ts +0 -57
  98. package/src/lib/ErrorHandling/errorCheck.spec.ts +0 -185
  99. package/src/lib/ErrorHandling/errorCheck.tsx +0 -86
  100. package/src/lib/ErrorHandling/layoutValildation.spec.ts +0 -47
  101. package/src/lib/ErrorHandling/otherValildation.spec.ts +0 -74
  102. package/src/lib/ErrorHandling/schemaValidation.ts +0 -115
  103. package/src/lib/common/Grid.tsx +0 -55
  104. package/src/lib/jsonforms-components.module.scss +0 -7
  105. package/src/lib/jsonforms-components.spec.tsx +0 -10
  106. package/src/lib/jsonforms-components.tsx +0 -14
  107. package/src/lib/layouts/GroupControl.tsx +0 -25
  108. package/src/lib/layouts/HorizontalLayoutControl.tsx +0 -30
  109. package/src/lib/layouts/VerticalLayoutControl.tsx +0 -28
  110. package/src/lib/util/layout.tsx +0 -68
  111. package/src/lib/util/schemaUtils.ts +0 -9
  112. package/src/lib/util/stringUtils.ts +0 -98
  113. package/src/lib/util/style-component.ts +0 -8
  114. package/tsconfig.json +0 -20
  115. package/tsconfig.lib.json +0 -19
  116. package/tsconfig.spec.json +0 -20
  117. /package/src/lib/Additional/{index.ts → index.d.ts} +0 -0
  118. /package/src/lib/Controls/FileUploader/{index.tsx → index.d.ts} +0 -0
  119. /package/src/lib/Controls/FormStepper/{index.tsx → index.d.ts} +0 -0
  120. /package/src/lib/Controls/Inputs/{index.tsx → index.d.ts} +0 -0
  121. /package/src/lib/Controls/ObjectArray/{index.tsx → index.d.ts} +0 -0
  122. /package/src/lib/Controls/{index.tsx → index.d.ts} +0 -0
  123. /package/src/lib/layouts/{index.ts → index.d.ts} +0 -0
@@ -1,74 +0,0 @@
1
- import React from 'react';
2
- import { isBooleanControl, RankedTester, rankWith, ControlProps, optionIs, and } from '@jsonforms/core';
3
- import { withJsonFormsControlProps } from '@jsonforms/react';
4
- import { Hidden } from '@mui/material';
5
- import { GoARadioGroup, GoARadioItem, GoAFormItem } from '@abgov/react-components-new';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity, getLabelText } from '../../util/stringUtils';
8
-
9
- export const BooleanRadioComponent = ({
10
- data,
11
- visible,
12
- enabled,
13
- uischema,
14
- handleChange,
15
- path,
16
- config,
17
- label,
18
- required,
19
- errors,
20
- description,
21
- }: ControlProps) => {
22
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
23
- const TrueValue = appliedUiSchemaOptions?.textForTrue || 'Yes';
24
- const FalseValue = appliedUiSchemaOptions?.textForFalse || 'No';
25
- const EnableDescription = appliedUiSchemaOptions?.enableDescription === true;
26
- const TrueDescription = description || appliedUiSchemaOptions?.descriptionForTrue;
27
- const FalseDescription = description || appliedUiSchemaOptions?.descriptionForFalse;
28
- const BaseTestId = appliedUiSchemaOptions?.testId || `${path}-boolean-radio-jsonform`;
29
- const errorsFormInput = checkFieldValidity({
30
- data,
31
- uischema,
32
- label,
33
- required,
34
- errors,
35
- } as ControlProps);
36
-
37
- return (
38
- <Hidden xsUp={!visible}>
39
- <GoARadioGroup
40
- error={errorsFormInput.length > 0}
41
- name={`${label}`}
42
- value={data === true ? TrueValue : data === false ? FalseValue : null}
43
- disabled={!enabled}
44
- testId={BaseTestId}
45
- onChange={(_name, value) => {
46
- if (value === TrueValue) {
47
- handleChange(path, true);
48
- }
49
- if (value === FalseValue) {
50
- handleChange(path, false);
51
- }
52
- }}
53
- {...uischema?.options?.componentProps}
54
- >
55
- <GoARadioItem
56
- value={TrueValue}
57
- testId={`${BaseTestId}-yes-option`}
58
- description={EnableDescription ? TrueDescription : null}
59
- />
60
- <GoARadioItem
61
- value={FalseValue}
62
- testId={`${BaseTestId}-no-option`}
63
- description={EnableDescription ? FalseDescription : null}
64
- />
65
- </GoARadioGroup>
66
- </Hidden>
67
- );
68
- };
69
- export const BooleanRadioControl = (props: ControlProps) => (
70
- <GoAInputBaseControl {...{ ...props }} input={BooleanRadioComponent} />
71
- );
72
-
73
- export const GoABooleanRadioControlTester: RankedTester = rankWith(3, and(isBooleanControl, optionIs('radio', true)));
74
- export const GoABooleanRadioControl = withJsonFormsControlProps(BooleanRadioControl);
@@ -1,90 +0,0 @@
1
- import React from 'react';
2
- import { CellProps, WithClassname, ControlProps, isDateControl, RankedTester, rankWith } from '@jsonforms/core';
3
- import { GoAInputDate } from '@abgov/react-components-new';
4
- import { WithInputProps } from './type';
5
- import { withJsonFormsControlProps } from '@jsonforms/react';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity, getLabelText, isValidDate } from '../../util/stringUtils';
8
- import { MessageControl } from '../../ErrorHandling/MessageControl';
9
-
10
- export type GoAInputDateProps = CellProps & WithClassname & WithInputProps;
11
- export const errMalformedDate = (scope: string, type: string): string => {
12
- return `${type}-date for variable '${scope}' has an incorrect format.`;
13
- };
14
-
15
- const standardizeDate = (date: Date | string): string | undefined => {
16
- try {
17
- const stdDate = new Date(date).toISOString().substring(0, 10);
18
- return stdDate;
19
- } catch (e) {
20
- const err = e as Error;
21
- return undefined;
22
- }
23
- };
24
-
25
- const isValidDateFormat = (date: string): boolean => {
26
- const standardized = standardizeDate(date);
27
- return standardized !== undefined;
28
- };
29
-
30
- const invalidDateFormat = (scope: string, type: string): JSX.Element => {
31
- return MessageControl(errMalformedDate(scope, type));
32
- };
33
-
34
- const reformatDateProps = (props: object): object => {
35
- if (props) {
36
- if ('min' in props && typeof props.min === 'string') {
37
- props['min'] = standardizeDate(props.min);
38
- }
39
- if ('max' in props && typeof props.max === 'string') {
40
- props['max'] = standardizeDate(props.max as string);
41
- }
42
- }
43
- return props;
44
- };
45
-
46
- export const GoADateInput = (props: GoAInputDateProps): JSX.Element => {
47
- const { data, config, id, enabled, uischema, path, handleChange, label } = props;
48
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
49
-
50
- const minDate = uischema?.options?.componentProps?.min;
51
- if (minDate && !isValidDateFormat(minDate)) {
52
- return invalidDateFormat(uischema.scope, 'Min');
53
- }
54
-
55
- const maxDate = uischema?.options?.componentProps?.max;
56
- if (maxDate && !isValidDateFormat(maxDate)) {
57
- return invalidDateFormat(uischema.scope, 'Max');
58
- }
59
-
60
- return (
61
- <GoAInputDate
62
- error={checkFieldValidity(props as ControlProps).length > 0}
63
- width="100%"
64
- name={appliedUiSchemaOptions?.name || `${id || label}-input`}
65
- value={standardizeDate(data) || ''}
66
- testId={appliedUiSchemaOptions?.testId || `${id}-input`}
67
- disabled={!enabled}
68
- // Don't use handleChange in the onChange event, use the keyPress or onBlur.
69
- // If you use it onChange along with keyPress event it will cause a
70
- // side effect that causes the validation to render when it shouldn't.
71
- onChange={(name, value) => {}}
72
- onKeyPress={(name: string, value: Date | string, key: string) => {
73
- if (!(key === 'Tab' || key === 'Shift')) {
74
- value = standardizeDate(value) || '';
75
- handleChange(path, value);
76
- }
77
- }}
78
- onBlur={(name: string, value: Date | string) => {
79
- value = standardizeDate(value) || '';
80
- handleChange(path, value);
81
- }}
82
- {...reformatDateProps(uischema?.options?.componentProps)}
83
- />
84
- );
85
- };
86
-
87
- export const GoADateControl = (props: ControlProps) => <GoAInputBaseControl {...props} input={GoADateInput} />;
88
-
89
- export const GoADateControlTester: RankedTester = rankWith(4, isDateControl);
90
- export const GoAInputDateControl = withJsonFormsControlProps(GoADateControl);
@@ -1,46 +0,0 @@
1
- import React from 'react';
2
- import { CellProps, WithClassname, ControlProps, isDateTimeControl, RankedTester, rankWith } from '@jsonforms/core';
3
- import { GoAInputDateTime } from '@abgov/react-components-new';
4
- import { WithInputProps } from './type';
5
- import { withJsonFormsControlProps } from '@jsonforms/react';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity, isValidDate } from '../../util/stringUtils';
8
- type GoAInputDateTimeProps = CellProps & WithClassname & WithInputProps;
9
-
10
- export const GoADateTimeInput = (props: GoAInputDateTimeProps): JSX.Element => {
11
- // eslint-disable-next-line
12
- const { data, config, id, enabled, uischema, isValid, path, errors, handleChange, schema, label } = props;
13
-
14
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
15
-
16
- return (
17
- <GoAInputDateTime
18
- error={checkFieldValidity(props as ControlProps).length > 0}
19
- width="100%"
20
- name={appliedUiSchemaOptions?.name || `${id || label}-input`}
21
- value={data ? new Date(data).toISOString() : ''}
22
- testId={appliedUiSchemaOptions?.testId || `${id}-input`}
23
- disabled={!enabled}
24
- // Dont use handleChange in the onChange event, use the keyPress or onBlur.
25
- // If you use it onChange along with keyPress event it will cause a
26
- // side effect that causes the validation to render when it shouldnt.
27
- onChange={(name, value) => {}}
28
- onKeyPress={(name: string, value: string, key: string) => {
29
- if (!(key === 'Tab' || key === 'Shift')) {
30
- value = isValidDate(value) ? new Date(value)?.toISOString() : '';
31
- handleChange(path, value);
32
- }
33
- }}
34
- onBlur={(name: string, value: string) => {
35
- value = isValidDate(value) ? new Date(value).toISOString() : '';
36
- handleChange(path, value);
37
- }}
38
- {...uischema?.options?.componentProps}
39
- />
40
- );
41
- };
42
-
43
- export const GoADateTimeControl = (props: ControlProps) => <GoAInputBaseControl {...props} input={GoADateTimeInput} />;
44
-
45
- export const GoADateTimeControlTester: RankedTester = rankWith(2, isDateTimeControl);
46
- export const GoAInputDateTimeControl = withJsonFormsControlProps(GoADateTimeControl);
@@ -1,74 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { ControlProps, isEnumControl, OwnPropsOfEnum, RankedTester, rankWith } from '@jsonforms/core';
3
- import { TranslateProps, withJsonFormsEnumProps, withTranslateProps } from '@jsonforms/react';
4
- import { WithInputProps } from './type';
5
- import merge from 'lodash/merge';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { WithOptionLabel } from '@jsonforms/material-renderers';
8
- import { GoADropdown, GoADropdownItem } from '@abgov/react-components-new';
9
- import { EnumCellProps, WithClassname } from '@jsonforms/core';
10
-
11
- import { addDataByOptions, getData } from '../../Context';
12
- import { checkFieldValidity } from '../../util/stringUtils';
13
-
14
- type EnumSelectProp = EnumCellProps & WithClassname & TranslateProps & WithInputProps;
15
-
16
- export const EnumSelect = (props: EnumSelectProp): JSX.Element => {
17
- const { data, id, enabled, errors, schema, path, handleChange, options, config, label, uischema } = props;
18
- const { required } = props as ControlProps;
19
-
20
- let enumData: unknown[] = schema?.enum || [];
21
-
22
- const appliedUiSchemaOptions = merge({}, config, props.uischema.options, options);
23
-
24
- const dataKey = uischema?.options?.enumContext?.key;
25
-
26
- const url = uischema?.options?.enumContext?.url;
27
- const location = uischema?.options?.enumContext?.location;
28
- const type = uischema?.options?.enumContext?.type;
29
- const values = uischema?.options?.enumContext?.values;
30
-
31
- const errorsFormInput = checkFieldValidity(props as ControlProps);
32
-
33
- useEffect(() => {
34
- if (dataKey && url) {
35
- addDataByOptions(dataKey, url, location, type, values);
36
- }
37
- }, [url, location, type, values, dataKey]);
38
-
39
- if (dataKey && getData(dataKey)) {
40
- const newData = getData(dataKey) as unknown[];
41
-
42
- enumData = newData;
43
- }
44
-
45
- return (
46
- <GoADropdown
47
- error={errorsFormInput.length > 0}
48
- name={`${label}`}
49
- value={data}
50
- disabled={!enabled}
51
- relative={true}
52
- key={`${id}-jsonform-key`}
53
- testId={`${id || label}-jsonform`}
54
- {...appliedUiSchemaOptions}
55
- onChange={(name, value) => {
56
- handleChange(path, value);
57
- }}
58
- {...uischema?.options?.componentProps}
59
- >
60
- {enumData?.map((item) => {
61
- return <GoADropdownItem key={`json-form-dropdown-${item}`} value={`${item}`} label={`${item}`} />;
62
- })}
63
- </GoADropdown>
64
- );
65
- };
66
-
67
- export const numControl = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel & TranslateProps) => {
68
- return <GoAInputBaseControl {...props} input={EnumSelect} />;
69
- };
70
-
71
- export const GoAEnumControlTester: RankedTester = rankWith(2, isEnumControl);
72
-
73
- // HOC order can be reversed with https://github.com/eclipsesource/jsonforms/issues/1987
74
- export const GoAEnumControl = withJsonFormsEnumProps(withTranslateProps(numControl), true);
@@ -1,73 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { ControlProps, isEnumControl, and, optionIs, OwnPropsOfEnum, RankedTester, rankWith } from '@jsonforms/core';
3
- import { TranslateProps, withJsonFormsEnumProps, withTranslateProps } from '@jsonforms/react';
4
- import { WithInputProps } from './type';
5
- import { GoAInputBaseControl } from './InputBaseControl';
6
- import { WithOptionLabel } from '@jsonforms/material-renderers';
7
- import { EnumCellProps, WithClassname } from '@jsonforms/core';
8
- import TextField from '@mui/material/TextField';
9
- import Autocomplete from '@mui/material/Autocomplete';
10
-
11
- import { addDataByOptions, getData } from '../../Context';
12
-
13
- type EnumSelectAutoCompleteProp = EnumCellProps & WithClassname & TranslateProps & WithInputProps;
14
-
15
- export const EnumSelectAutoComplete = (props: EnumSelectAutoCompleteProp): JSX.Element => {
16
- const { data, schema, path, handleChange, uischema } = props;
17
- let enumData = schema?.enum || [];
18
-
19
- const dataKey = uischema?.options?.enumContext?.key;
20
-
21
- const url = uischema?.options?.enumContext?.url;
22
- const location = uischema?.options?.enumContext?.location;
23
- const type = uischema?.options?.enumContext?.type;
24
- const values = uischema?.options?.enumContext?.values;
25
-
26
- const defaultProps = {
27
- options: enumData,
28
- getOptionLabel: (option: Array<string>) => option,
29
- };
30
-
31
- const [inputValue, setInputValue] = React.useState('');
32
-
33
- useEffect(() => {
34
- if (dataKey && url) {
35
- addDataByOptions(dataKey, url, location, type, values);
36
- }
37
- }, [url, location, type, values, dataKey]);
38
-
39
- if (dataKey && getData(dataKey)) {
40
- const newData = getData(dataKey);
41
- // eslint-disable-next-line
42
- enumData = newData as any[];
43
- defaultProps.options = enumData;
44
- }
45
-
46
- return (
47
- <Autocomplete
48
- {...defaultProps}
49
- id="autocomplete"
50
- getOptionLabel={(option) => option}
51
- isOptionEqualToValue={(option, value) => option.id === value.id}
52
- value={data || null}
53
- onChange={(name, value) => {
54
- handleChange(path, value);
55
- setInputValue(value);
56
- }}
57
- renderInput={(params) => {
58
- return <TextField {...params} variant="outlined" size="small" placeholder={schema?.description} />;
59
- }}
60
- />
61
- );
62
- };
63
-
64
- const numControlAutoComplete = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel & TranslateProps) => {
65
- return <GoAInputBaseControl {...props} input={EnumSelectAutoComplete} />;
66
- };
67
-
68
- export const GoAEnumControlAutoCompleteTester: RankedTester = rankWith(
69
- 3,
70
- and(isEnumControl, optionIs('autocomplete', true))
71
- );
72
-
73
- export const GoAEnumAutoCompleteControl = withJsonFormsEnumProps(withTranslateProps(numControlAutoComplete), true);
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
- import { ControlProps, isEnumControl, OwnPropsOfEnum, RankedTester, rankWith, optionIs, and } from '@jsonforms/core';
3
- import { TranslateProps, withJsonFormsEnumProps, withTranslateProps } from '@jsonforms/react';
4
- import { WithInputProps } from './type';
5
- import merge from 'lodash/merge';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { WithOptionLabel } from '@jsonforms/material-renderers';
8
- import { GoARadioGroup, GoARadioItem } from '@abgov/react-components-new';
9
- import { EnumCellProps, WithClassname } from '@jsonforms/core';
10
- import { checkFieldValidity } from '../../util/stringUtils';
11
-
12
- type RadioGroupProp = EnumCellProps & WithClassname & TranslateProps & WithInputProps;
13
-
14
- export const RadioGroup = (props: RadioGroupProp): JSX.Element => {
15
- const { data, className, id, enabled, schema, uischema, path, handleChange, options, config, label, t } = props;
16
- const enumData = schema?.enum || [];
17
- const appliedUiSchemaOptions = merge({}, config, props.uischema.options, uischema, options);
18
- const errorsFormInput = checkFieldValidity(props as ControlProps);
19
-
20
- return (
21
- <GoARadioGroup
22
- error={errorsFormInput.length > 0}
23
- name={`${options || appliedUiSchemaOptions.label}`}
24
- testId={`${id || label}-jsonform-dropdown`}
25
- value={data}
26
- disabled={!enabled}
27
- {...appliedUiSchemaOptions}
28
- onChange={(name: string, value: string) => handleChange(path, value)}
29
- {...uischema?.options?.componentProps}
30
- >
31
- {enumData.map((value) => {
32
- return <GoARadioItem name={value} value={`${value}`} label={value} {...appliedUiSchemaOptions} />;
33
- })}
34
- </GoARadioGroup>
35
- );
36
- };
37
-
38
- export const EnumRadioControl = (props: ControlProps & OwnPropsOfEnum & WithOptionLabel & TranslateProps) => {
39
- return <GoAInputBaseControl {...props} input={RadioGroup} />;
40
- };
41
-
42
- export const GoAEnumRadioGroupControl = withJsonFormsEnumProps(withTranslateProps(EnumRadioControl), true);
43
- export const GoARadioGroupControlTester: RankedTester = rankWith(20, and(isEnumControl, optionIs('format', 'radio')));
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
- import { CellProps, WithClassname, ControlProps, isIntegerControl, RankedTester, rankWith } from '@jsonforms/core';
3
- import { GoAInput, GoAInputNumber } from '@abgov/react-components-new';
4
- import { WithInputProps } from './type';
5
- import { withJsonFormsControlProps } from '@jsonforms/react';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity, isValidDate } from '../../util/stringUtils';
8
- type GoAInputIntegerProps = CellProps & WithClassname & WithInputProps;
9
-
10
- export const GoAInputInteger = (props: GoAInputIntegerProps): JSX.Element => {
11
- // eslint-disable-next-line
12
- const { data, config, id, enabled, uischema, isValid, path, handleChange, schema, label } = props;
13
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
14
- const placeholder = appliedUiSchemaOptions?.placeholder || schema?.description || '';
15
- const InputValue = data && data !== undefined ? data : '';
16
- const clonedSchema = JSON.parse(JSON.stringify(schema));
17
- const StepValue = clonedSchema.multipleOf ? clonedSchema.multipleOf : 0;
18
- const MinValue = clonedSchema.minimum ? clonedSchema.minimum : '';
19
- const MaxValue = clonedSchema.exclusiveMaximum ? clonedSchema.exclusiveMaximum : '';
20
- const errorsFormInput = checkFieldValidity(props as ControlProps);
21
-
22
- return (
23
- <GoAInput
24
- type="number"
25
- error={errorsFormInput.length > 0}
26
- width="100%"
27
- disabled={!enabled}
28
- value={InputValue}
29
- step={StepValue}
30
- min={MinValue}
31
- max={MaxValue}
32
- placeholder={placeholder}
33
- name={appliedUiSchemaOptions?.name || `${id || label}-input`}
34
- testId={appliedUiSchemaOptions?.testId || `${id}-input`}
35
- onKeyPress={(name: string, value: string, key: string) => {
36
- if (!(key === 'Tab' || key === 'Shift')) {
37
- let newValue: string | number = '';
38
- if (value !== '') {
39
- newValue = +value;
40
- }
41
-
42
- handleChange(path, newValue);
43
- }
44
- }}
45
- onBlur={(name: string, value: string) => {
46
- let newValue: string | number = '';
47
- if (value !== '') {
48
- newValue = +value;
49
- }
50
- handleChange(path, newValue);
51
- }}
52
- //Dont trigger the handleChange event on the onChange event as it will cause
53
- //issue with the error message from displaying, use keyPress or the onBlur event instead
54
- onChange={(name: string, value: string) => {}}
55
- {...uischema?.options?.componentProps}
56
- />
57
- );
58
- };
59
-
60
- export const GoAIntegerControl = (props: ControlProps) => <GoAInputBaseControl {...props} input={GoAInputInteger} />;
61
-
62
- export const GoAIntegerControlTester: RankedTester = rankWith(2, isIntegerControl);
63
- export const GoAInputIntegerControl = withJsonFormsControlProps(GoAIntegerControl);
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
- import {
3
- CellProps,
4
- WithClassname,
5
- ControlProps,
6
- isStringControl,
7
- RankedTester,
8
- rankWith,
9
- and,
10
- optionIs,
11
- } from '@jsonforms/core';
12
- import { GoATextArea } from '@abgov/react-components-new';
13
- import { WithInputProps } from './type';
14
- import { withJsonFormsControlProps } from '@jsonforms/react';
15
- import { GoAInputBaseControl } from './InputBaseControl';
16
- import { checkFieldValidity } from '../../util/stringUtils';
17
- type GoAInputTextProps = CellProps & WithClassname & WithInputProps;
18
-
19
- export const MultiLineText = (props: GoAInputTextProps): JSX.Element => {
20
- // eslint-disable-next-line
21
- const { data, config, id, enabled, uischema, path, handleChange, schema, label } = props;
22
-
23
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
24
- const placeholder = appliedUiSchemaOptions?.placeholder || schema?.description || '';
25
- const errorsFormInput = checkFieldValidity(props as ControlProps);
26
- const autoCapitalize =
27
- uischema?.options?.componentProps?.autoCapitalize === true || uischema?.options?.autoCapitalize === true;
28
-
29
- return (
30
- <GoATextArea
31
- error={errorsFormInput.length > 0}
32
- value={data}
33
- disabled={!enabled}
34
- placeholder={placeholder}
35
- testId={appliedUiSchemaOptions?.testId || `${id}-input`}
36
- name={`${label || path}-text-area`}
37
- width={'100%'}
38
- // Note: Paul Jan-09-2023. The latest ui-component come with the maxCount. We need to uncomment the following line when the component is updated
39
- // maxCount={schema.maxLength || 256}
40
- onKeyPress={(name: string, value: string, key: string) => {
41
- if (!(key === 'Tab' || key === 'Shift')) {
42
- if (autoCapitalize === true) {
43
- handleChange(path, value.toUpperCase());
44
- } else {
45
- handleChange(path, value);
46
- }
47
- }
48
- }}
49
- // Dont use handleChange in the onChange event, use the keyPress or onBlur.
50
- // If you use it onChange along with keyPress event it will cause a
51
- // side effect that causes the validation to render when it shouldnt.
52
- onChange={() => {}}
53
- {...uischema?.options?.componentProps}
54
- />
55
- );
56
- };
57
-
58
- export const MultiLineTextControlInput = (props: ControlProps) => (
59
- <GoAInputBaseControl {...props} input={MultiLineText} />
60
- );
61
-
62
- export const MultiLineTextControlTester: RankedTester = rankWith(3, and(isStringControl, optionIs('multi', true)));
63
- export const MultiLineTextControl = withJsonFormsControlProps(MultiLineTextControlInput);
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
- import { CellProps, WithClassname, ControlProps, isNumberControl, RankedTester, rankWith } from '@jsonforms/core';
3
- import { GoAInput } from '@abgov/react-components-new';
4
- import { WithInputProps } from './type';
5
- import { withJsonFormsControlProps } from '@jsonforms/react';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity } from '../../util/stringUtils';
8
- type GoAInputNumberProps = CellProps & WithClassname & WithInputProps;
9
-
10
- export const GoANumberInput = (props: GoAInputNumberProps): JSX.Element => {
11
- // eslint-disable-next-line
12
- const { data, config, id, enabled, uischema, isValid, path, handleChange, schema, label } = props;
13
-
14
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
15
- const placeholder = appliedUiSchemaOptions?.placeholder || schema?.description || '';
16
- const InputValue = data && data !== undefined ? data : '';
17
- const clonedSchema = JSON.parse(JSON.stringify(schema));
18
- const StepValue = clonedSchema.multipleOf ? clonedSchema.multipleOf : 0.01;
19
- const MinValue = clonedSchema.minimum ? clonedSchema.minimum : '';
20
- const MaxValue = clonedSchema.exclusiveMaximum ? clonedSchema.exclusiveMaximum : '';
21
- const errorsFormInput = checkFieldValidity(props as ControlProps);
22
-
23
- return (
24
- <GoAInput
25
- type="number"
26
- error={errorsFormInput.length > 0}
27
- disabled={!enabled}
28
- value={InputValue}
29
- placeholder={placeholder}
30
- step={StepValue}
31
- min={MinValue}
32
- max={MaxValue}
33
- width="100%"
34
- name={appliedUiSchemaOptions?.name || `${id || label}-input`}
35
- testId={appliedUiSchemaOptions?.testId || `${id}-input`}
36
- onKeyPress={(name: string, value: string, key: string) => {
37
- if (!(key === 'Tab' || key === 'Shift')) {
38
- let newValue: string | number = '';
39
- if (value !== '') {
40
- newValue = +value;
41
- }
42
- handleChange(path, newValue);
43
- }
44
- }}
45
- onBlur={(name: string, value: string) => {
46
- let newValue: string | number = '';
47
- if (value !== '') {
48
- newValue = +value;
49
- }
50
- handleChange(path, newValue);
51
- }}
52
- //Dont trigger the handleChange event on the onChange event as it will cause
53
- //issue with the error message from displaying, use keyPress or the onBlur event instead
54
- onChange={(name: string, value: string) => {}}
55
- {...uischema?.options?.componentProps}
56
- />
57
- );
58
- };
59
-
60
- export const GoANumberControl = (props: ControlProps) => <GoAInputBaseControl {...props} input={GoANumberInput} />;
61
-
62
- export const GoANumberControlTester: RankedTester = rankWith(2, isNumberControl);
63
- export const GoAInputNumberControl = withJsonFormsControlProps(GoANumberControl);
@@ -1,62 +0,0 @@
1
- import React from 'react';
2
- import { CellProps, WithClassname, ControlProps, isStringControl, RankedTester, rankWith } from '@jsonforms/core';
3
- import { withJsonFormsControlProps } from '@jsonforms/react';
4
- import { GoAInput, GoAFormItem } from '@abgov/react-components-new';
5
- import { WithInputProps } from './type';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity, getLabelText } from '../../util/stringUtils';
8
-
9
- type GoAInputTextProps = CellProps & WithClassname & WithInputProps;
10
-
11
- export const GoAInputText = (props: GoAInputTextProps): JSX.Element => {
12
- // eslint-disable-next-line
13
- const { data, config, id, enabled, uischema, isValid, errors, path, handleChange, schema, label } = props;
14
-
15
- const appliedUiSchemaOptions = { ...config, ...uischema?.options };
16
- const placeholder = appliedUiSchemaOptions?.placeholder || schema?.description || '';
17
-
18
- const errorsFormInput = checkFieldValidity(props as ControlProps);
19
-
20
- const autoCapitalize =
21
- uischema?.options?.componentProps?.autoCapitalize === true || uischema?.options?.autoCapitalize === true;
22
-
23
- return (
24
- <GoAInput
25
- error={errorsFormInput.length > 0}
26
- type={appliedUiSchemaOptions.format === 'password' ? 'password' : 'text'}
27
- disabled={!enabled}
28
- value={data}
29
- width={'100%'}
30
- placeholder={placeholder}
31
- // maxLength={appliedUiSchemaOptions?.maxLength}
32
- name={appliedUiSchemaOptions?.name || `${id || label}-input`}
33
- testId={appliedUiSchemaOptions?.testId || `${id}-input`}
34
- // Dont use handleChange in the onChange event, use the keyPress or onBlur.
35
- // If you use it onChange along with keyPress event it will cause a
36
- // side effect that causes the validation to render when it shouldnt.
37
- onChange={(name: string, value: string) => {}}
38
- onKeyPress={(name: string, value: string, key: string) => {
39
- if (!(key === 'Tab' || key === 'Shift')) {
40
- if (autoCapitalize === true) {
41
- handleChange(path, value.toUpperCase());
42
- } else {
43
- handleChange(path, value);
44
- }
45
- }
46
- }}
47
- onBlur={(name: string, value: string) => {
48
- if (autoCapitalize === true) {
49
- handleChange(path, value.toUpperCase());
50
- } else {
51
- handleChange(path, value);
52
- }
53
- }}
54
- {...uischema?.options?.componentProps}
55
- />
56
- );
57
- };
58
-
59
- export const GoATextControl = (props: ControlProps) => <GoAInputBaseControl {...props} input={GoAInputText} />;
60
-
61
- export const GoATextControlTester: RankedTester = rankWith(1, isStringControl);
62
- export const GoAInputTextControl = withJsonFormsControlProps(GoATextControl);