2019-03-13 15:05:24 +00:00
|
|
|
import BaseWidget, { IWidgetProps, IWidgetState } from "./BaseWidget";
|
2019-02-10 13:06:05 +00:00
|
|
|
import ContainerComponent, {
|
|
|
|
|
IContainerProps
|
2019-03-13 15:05:24 +00:00
|
|
|
} from "../editorComponents/ContainerComponent";
|
|
|
|
|
import {
|
|
|
|
|
ContainerOrientation,
|
|
|
|
|
WidgetType,
|
|
|
|
|
CSSUnits
|
|
|
|
|
} from "../constants/WidgetConstants";
|
|
|
|
|
import WidgetFactory from "../utils/WidgetFactory";
|
|
|
|
|
import React from "react";
|
|
|
|
|
import _ from "lodash";
|
2019-02-11 18:22:23 +00:00
|
|
|
|
2019-03-13 15:05:24 +00:00
|
|
|
const DEFAULT_NUM_COLS = 13;
|
|
|
|
|
const DEFAULT_NUM_ROWS = 13;
|
2019-02-10 13:06:05 +00:00
|
|
|
|
|
|
|
|
class ContainerWidget extends BaseWidget<
|
2019-02-10 16:39:09 +00:00
|
|
|
IContainerWidgetProps<IWidgetProps>,
|
2019-02-11 18:22:23 +00:00
|
|
|
IWidgetState
|
2019-02-10 13:06:05 +00:00
|
|
|
> {
|
2019-03-13 15:05:24 +00:00
|
|
|
snapColumnSpace: number = 100;
|
|
|
|
|
snapRowSpace: number = 100;
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-02-11 18:22:23 +00:00
|
|
|
constructor(props: IContainerWidgetProps<IWidgetProps>) {
|
2019-03-13 15:05:24 +00:00
|
|
|
super(props);
|
|
|
|
|
this.renderChildWidget = this.renderChildWidget.bind(this);
|
2019-02-11 18:22:23 +00:00
|
|
|
this.state = {
|
|
|
|
|
height: 0,
|
|
|
|
|
width: 0
|
2019-03-13 15:05:24 +00:00
|
|
|
};
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-11 18:22:23 +00:00
|
|
|
componentWillReceiveProps(
|
|
|
|
|
previousProps: IContainerWidgetProps<IWidgetProps>,
|
|
|
|
|
nextProps: IContainerWidgetProps<IWidgetProps>
|
|
|
|
|
) {
|
2019-03-13 15:05:24 +00:00
|
|
|
super.componentWillReceiveProps(previousProps, nextProps);
|
2019-02-11 18:22:23 +00:00
|
|
|
this.snapColumnSpace =
|
2019-03-13 15:05:24 +00:00
|
|
|
this.state.width / (nextProps.snapColumns || DEFAULT_NUM_COLS);
|
2019-02-11 18:22:23 +00:00
|
|
|
this.snapRowSpace =
|
2019-03-13 15:05:24 +00:00
|
|
|
this.state.height / (nextProps.snapRows || DEFAULT_NUM_ROWS);
|
2019-02-11 18:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderChildWidget(childWidgetData: IWidgetProps) {
|
2019-03-13 15:05:24 +00:00
|
|
|
childWidgetData.parentColumnSpace = this.snapColumnSpace;
|
|
|
|
|
childWidgetData.parentRowSpace = this.snapRowSpace;
|
|
|
|
|
return WidgetFactory.createWidget(childWidgetData);
|
2019-02-11 18:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetView() {
|
2019-02-10 13:06:05 +00:00
|
|
|
return (
|
2019-02-11 18:22:23 +00:00
|
|
|
<ContainerComponent
|
|
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
style={{
|
|
|
|
|
height: this.state.height,
|
|
|
|
|
width: this.state.width,
|
|
|
|
|
positionType: "ABSOLUTE",
|
|
|
|
|
yPosition: this.props.topRow * this.props.parentRowSpace,
|
|
|
|
|
xPosition: this.props.leftColumn * this.props.parentColumnSpace,
|
|
|
|
|
xPositionUnit: CSSUnits.PIXEL,
|
|
|
|
|
yPositionUnit: CSSUnits.PIXEL
|
|
|
|
|
}}
|
|
|
|
|
snapColumnSpace={this.snapColumnSpace}
|
|
|
|
|
snapRowSpace={this.snapRowSpace}
|
|
|
|
|
snapColumns={this.props.snapColumns || DEFAULT_NUM_COLS}
|
|
|
|
|
snapRows={this.props.snapRows || DEFAULT_NUM_ROWS}
|
|
|
|
|
orientation={this.props.orientation || "VERTICAL"}
|
|
|
|
|
>
|
|
|
|
|
{_.map(this.props.children, this.renderChildWidget)}
|
2019-02-10 13:06:05 +00:00
|
|
|
</ContainerComponent>
|
2019-03-13 15:05:24 +00:00
|
|
|
);
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetType(): WidgetType {
|
2019-03-13 15:05:24 +00:00
|
|
|
return "CONTAINER_WIDGET";
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 18:22:23 +00:00
|
|
|
export interface IContainerWidgetProps<T extends IWidgetProps>
|
|
|
|
|
extends IWidgetProps {
|
2019-03-13 15:05:24 +00:00
|
|
|
children?: T[];
|
|
|
|
|
snapColumns?: number;
|
|
|
|
|
snapRows?: number;
|
|
|
|
|
orientation?: ContainerOrientation;
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:05:24 +00:00
|
|
|
export default ContainerWidget;
|