|
1 | 1 | import React from 'react'; |
2 | 2 | import { isEnumControl, RankedTester, rankWith, ControlProps } from '@jsonforms/core'; |
3 | 3 | import { withJsonFormsControlProps } from '@jsonforms/react'; |
4 | | -import { |
5 | | - MaterialTextControl, |
6 | | - materialTextControlTester, |
7 | | - MaterialNumberControl, |
8 | | - materialNumberControlTester, |
9 | | - MaterialIntegerControl, |
10 | | - materialIntegerControlTester, |
11 | | - MaterialDateControl, |
12 | | - materialDateControlTester, |
13 | | - MaterialDateTimeControl, |
14 | | - materialDateTimeControlTester, |
15 | | - MaterialTimeControl, |
16 | | - materialTimeControlTester, |
17 | | - MaterialEnumControl, |
18 | | - materialEnumControlTester, |
19 | | - MaterialOneOfEnumControl, |
20 | | - materialOneOfEnumControlTester, |
21 | | - MaterialRadioGroupControl, |
22 | | - materialRadioGroupControlTester, |
23 | | -} from '@jsonforms/material-renderers'; |
24 | 4 | import { Card, CardActionArea, CardContent, Typography, Box } from '@mui/material'; |
25 | 5 | import QuestionShell from './QuestionShell'; |
26 | 6 |
|
27 | 7 | type AnyControlProps = ControlProps & { errors?: string }; |
28 | 8 |
|
29 | | -const wrapWithShell = |
30 | | - (Inner: React.ComponentType<any>) => |
31 | | - (props: ControlProps): React.ReactElement => { |
32 | | - const { schema, uischema, errors } = props; |
33 | | - const label = (uischema as any)?.label || schema.title; |
34 | | - const description = schema.description; |
35 | | - const required = Boolean( |
36 | | - (uischema as any)?.options?.required ?? (schema as any)?.options?.required, |
37 | | - ); |
38 | | - |
39 | | - return ( |
40 | | - <QuestionShell title={label} description={description} required={required} error={errors}> |
41 | | - <Inner {...(props as any)} /> |
42 | | - </QuestionShell> |
43 | | - ); |
44 | | - }; |
45 | | - |
46 | 9 | const cardEnumControlTester: RankedTester = rankWith(6, isEnumControl); |
47 | 10 |
|
48 | 11 | const CardEnumControl = (props: AnyControlProps) => { |
@@ -92,43 +55,11 @@ const CardEnumControl = (props: AnyControlProps) => { |
92 | 55 | ); |
93 | 56 | }; |
94 | 57 |
|
| 58 | +// NOTE: We removed the shell wrappers for text/number/integer/date controls because |
| 59 | +// they interfere with JSONForms' internal cell rendering mechanism. |
| 60 | +// The default materialRenderers handle these controls properly. |
| 61 | +// Only export custom renderers that don't break cell rendering. |
95 | 62 | export const shellMaterialRenderers = [ |
96 | | - { |
97 | | - tester: materialTextControlTester, |
98 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialTextControl)), |
99 | | - }, |
100 | | - { |
101 | | - tester: materialNumberControlTester, |
102 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialNumberControl)), |
103 | | - }, |
104 | | - { |
105 | | - tester: materialIntegerControlTester, |
106 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialIntegerControl)), |
107 | | - }, |
108 | | - { |
109 | | - tester: materialDateControlTester, |
110 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialDateControl)), |
111 | | - }, |
112 | | - { |
113 | | - tester: materialDateTimeControlTester, |
114 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialDateTimeControl)), |
115 | | - }, |
116 | | - { |
117 | | - tester: materialTimeControlTester, |
118 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialTimeControl)), |
119 | | - }, |
120 | | - // Card-style select/oneOf/radio |
| 63 | + // Card-style enum control - a custom renderer that uses QuestionShell |
121 | 64 | { tester: cardEnumControlTester, renderer: withJsonFormsControlProps(CardEnumControl) }, |
122 | | - { |
123 | | - tester: materialEnumControlTester, |
124 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialEnumControl)), |
125 | | - }, |
126 | | - { |
127 | | - tester: materialOneOfEnumControlTester, |
128 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialOneOfEnumControl)), |
129 | | - }, |
130 | | - { |
131 | | - tester: materialRadioGroupControlTester, |
132 | | - renderer: withJsonFormsControlProps(wrapWithShell(MaterialRadioGroupControl)), |
133 | | - }, |
134 | 65 | ]; |
0 commit comments