From 874f497d30a0a268e2781b5eb7fdc1482c12bc22 Mon Sep 17 00:00:00 2001 From: burnettk Date: Thu, 2 May 2024 17:17:16 -0400 Subject: [PATCH] allowing switch form to MUI using ui:theme mui in the ui schema --- .../src/components/CustomForm.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spiffworkflow-frontend/src/components/CustomForm.tsx b/spiffworkflow-frontend/src/components/CustomForm.tsx index ea115e6ad..db04738dc 100644 --- a/spiffworkflow-frontend/src/components/CustomForm.tsx +++ b/spiffworkflow-frontend/src/components/CustomForm.tsx @@ -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 {childrenToUse}; } - if (reactJsonSchemaForm === 'mui') { + if (reactJsonSchemaFormTheme === 'mui') { // eslint-disable-next-line react/jsx-props-no-spreading return {childrenToUse}; } - console.error(`Unsupported form type: ${reactJsonSchemaForm}`); + console.error(`Unsupported form type: ${reactJsonSchemaFormTheme}`); return null; }