generated from wrappid/wrappid-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): ⚡ add CoreComponentRenderer
changes to render CoreComponents ref: #54
- Loading branch information
1 parent
740ed76
commit f3c4535
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/components/page-builder/content-components/ReactComponentRenderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { CoreComponentsRegistry } from "@wrappid/core"; | ||
|
||
const CoreComponentRenderer = ({ componentData }) => { | ||
const renderCoreComponent = (data) => { | ||
if (!data || typeof data !== 'object') { | ||
return null; | ||
} | ||
|
||
const ComponentInfo = CoreComponentsRegistry[data.component]; | ||
const ComponentToRender = ComponentInfo?.comp; | ||
|
||
if (!ComponentToRender) { | ||
console.warn(`Component ${data.component} not found in CoreComponentsRegistry`); | ||
return null; | ||
} | ||
|
||
const childrenElements = (data.children || []).map((child, index) => | ||
renderCoreComponent({ ...child, key: index }) | ||
); | ||
|
||
// Add default Props | ||
|
||
// Add default props for specific components | ||
let defaultProps = { }; | ||
if (data.component === 'CoreIcon') { | ||
defaultProps = { ...defaultProps, icon: 'star' }; // Example default icon | ||
} else if (data.component === 'CoreAvatar') { | ||
defaultProps = { ...defaultProps, alt: 'User' }; | ||
} | ||
// Add more component-specific default props as needed | ||
|
||
return React.createElement( | ||
ComponentToRender, | ||
{ | ||
key: data.key, | ||
...defaultProps, | ||
// Pass props here | ||
}, | ||
childrenElements.length > 0 ? childrenElements : null | ||
); | ||
}; | ||
|
||
return renderCoreComponent(componentData); | ||
}; | ||
|
||
export default CoreComponentRenderer; |