allowing switch form to MUI using ui:theme mui in the ui schema (#1482)

Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
Kevin Burnett 2024-05-03 17:32:57 +00:00 committed by GitHub
parent 84feef321d
commit d8da94c233
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 3 deletions

View File

@ -59,6 +59,20 @@ export default function CustomForm({
'numeric-range': NumericRangeField,
};
let reactJsonSchemaFormTheme = reactJsonSchemaForm;
if ('ui:theme' in uiSchema) {
if (uiSchema['ui:theme'] === 'carbon') {
reactJsonSchemaFormTheme = 'carbon';
} else if (uiSchema['ui:theme'] === 'mui') {
reactJsonSchemaFormTheme = 'mui';
} else {
console.error(
`Unsupported theme: ${uiSchema['ui:theme']}. Defaulting to mui`
);
reactJsonSchemaFormTheme = 'mui';
}
}
const rjsfTemplates: any = {};
if (restrictedWidth) {
rjsfTemplates.ObjectFieldTemplate = ObjectFieldRestrictedGridTemplate;
@ -475,16 +489,16 @@ export default function CustomForm({
templates: rjsfTemplates,
omitExtraData: true,
};
if (reactJsonSchemaForm === 'carbon') {
if (reactJsonSchemaFormTheme === 'carbon') {
// eslint-disable-next-line react/jsx-props-no-spreading
return <CarbonForm {...formProps}>{childrenToUse}</CarbonForm>;
}
if (reactJsonSchemaForm === 'mui') {
if (reactJsonSchemaFormTheme === 'mui') {
// eslint-disable-next-line react/jsx-props-no-spreading
return <MuiForm {...formProps}>{childrenToUse}</MuiForm>;
}
console.error(`Unsupported form type: ${reactJsonSchemaForm}`);
console.error(`Unsupported form type: ${reactJsonSchemaFormTheme}`);
return null;
}