import * as React from "react"; import { get } from "lodash"; import * as WebComponents from ".."; import { Container } from ".."; import { ComponentTypes } from "../types"; import { EditorMode } from "@sc/modules/v2/Editor/types"; interface SwitchProps { mode?: EditorMode; style?: any; globalStyle?: any; actionItems?: ISwitchItems[] | undefined | any; containerItems: ISwitchItems[] | undefined | any; } interface ISwitchItems { type?: ComponentTypes; style?: any; html?: string | React.ReactNode; } export const Switch: React.FC = ({ actionItems = [], containerItems = [], globalStyle, }) => { const [containerIndex, setContainerIndex] = React.useState( get(containerItems[0], "id", false) ); const ActionItems = () => actionItems((n) => setContainerIndex(n)).map((itm: ISwitchItems | any) => { const Component: any = WebComponents[itm.type]; return ( {itm.html} ); }); const ContainerItems = () => containerItems .filter((itm) => get(itm, "id") === containerIndex) .map((itm: ISwitchItems | any) => { const TheContainer = itm.children; return ( ); }); return (
); }; export default Switch;