Created
June 20, 2024 14:17
-
-
Save kensleDev/6b338a6fcd5fd0e7be272b5ecc753a36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { useEffect, useState } from "react"; | |
import { HeadingBlock } from "./blocks/Heading"; | |
import { AccordionBlock } from "./blocks/Accordion"; | |
import { ImageCarouselBlock } from "./blocks/ImageCarousel"; | |
interface ComponentFilterProps { | |
component: any; | |
} | |
export function ComponentFilter({ component }: ComponentFilterProps) { | |
const [componentName] = useState(Object.keys(component)[0]); | |
const [componentData, setComponentData] = useState<any>( | |
Object.values(component)[0] | |
); | |
useEffect(() => { | |
if (componentData.items) { | |
setComponentData(componentData.items[0].content); | |
} | |
}, [componentData]); | |
if (componentData.contentType === "heading") { | |
return <HeadingBlock data={componentData} />; | |
} | |
if (componentData.contentType === "accordion") { | |
return <AccordionBlock data={componentData} />; | |
} | |
if (componentData.contentType === "imageCarousel") { | |
return <ImageCarouselBlock data={componentData} />; | |
} | |
return ( | |
<div> | |
<p>{componentName}</p> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment