PromucFlow_constructor/app/client/src/editorComponents/ContainerComponent.tsx

47 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-08-29 11:22:09 +00:00
import { IComponentProps } from "./BaseComponent";
import { ContainerOrientation } from "../constants/WidgetConstants";
import styled from "../constants/DefaultTheme";
import { useDrop } from "react-dnd"
import { WidgetTypes } from "../constants/WidgetConstants"
import { DraggableWidget } from "../widgets/BaseWidget"
import React from "react";
2019-03-21 12:10:32 +00:00
export const Container = styled("div")<IContainerProps>`
2019-08-20 13:19:19 +00:00
display: flex;
2019-08-20 09:39:08 +00:00
flex-direction: ${props => {
2019-03-21 12:10:32 +00:00
return props.orientation === "HORIZONTAL" ? "row" : "column"
}};
2019-03-19 15:21:27 +00:00
background: ${props => props.style.backgroundColor};
color: ${props => props.theme.primaryColor};
2019-03-21 12:10:32 +00:00
position: ${props => {
return props.style.positionType === "ABSOLUTE" ? "absolute" : "relative"
}};
left: ${props => {
return props.style.positionType !== "ABSOLUTE" ? undefined : props.style.xPosition + props.style.xPositionUnit
}};
top: ${props => {
return props.style.positionType !== "ABSOLUTE" ? undefined : props.style.yPosition + props.style.yPositionUnit
}};
2019-08-29 11:22:09 +00:00
`;
const ContainerComponent = (props: ContainerProps) => {
const addWidgetFn = props.addWidget;
const [, drop] = useDrop({
accept: Object.values(WidgetTypes),
drop(item: DraggableWidget, monitor) {
if (addWidgetFn && monitor.isOver({shallow: true})){
addWidgetFn(item.type);
}
return undefined
},
})
return <Container ref={drop} {...props}>{props.children}</Container>
}
2019-08-29 11:22:09 +00:00
export interface ContainerProps extends IComponentProps {
children?: JSX.Element[] | JSX.Element;
orientation?: ContainerOrientation;
addWidget?: Function;
}
export default ContainerComponent