Skip to content

Commit

Permalink
allowing switch form to MUI using ui:theme mui in the ui schema (#1482)
Browse files Browse the repository at this point in the history
Co-authored-by: burnettk <[email protected]>
  • Loading branch information
burnettk and burnettk authored May 3, 2024
1 parent 84feef3 commit d8da94c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions spiffworkflow-frontend/src/components/CustomForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

0 comments on commit d8da94c

Please sign in to comment.