2019-02-10 13:06:05 +00:00
|
|
|
import * as React from "react"
|
|
|
|
|
import BaseWidget, { IWidgetProps } from "./BaseWidget"
|
|
|
|
|
import ContainerComponent, {
|
|
|
|
|
IContainerProps
|
|
|
|
|
} from "../editorComponents/ContainerComponent"
|
|
|
|
|
import { ContainerOrientation, WidgetType } from "../constants/WidgetConstants"
|
|
|
|
|
import WidgetFactory from "../utils/WidgetFactory"
|
|
|
|
|
|
|
|
|
|
class ContainerWidget extends BaseWidget<
|
2019-02-10 16:39:09 +00:00
|
|
|
IContainerWidgetProps<IWidgetProps>,
|
2019-02-10 13:06:05 +00:00
|
|
|
IContainerProps
|
|
|
|
|
> {
|
2019-02-10 16:39:09 +00:00
|
|
|
constructor(widgetProps: IContainerWidgetProps<IWidgetProps>) {
|
2019-02-10 13:06:05 +00:00
|
|
|
super(widgetProps)
|
2019-02-10 14:14:58 +00:00
|
|
|
this.widgetData.snapColumns = 13
|
|
|
|
|
this.widgetData.snapColumnSpace = this.width / this.widgetData.snapColumns
|
|
|
|
|
this.widgetData.snapRowSpace = 100
|
|
|
|
|
this.widgetData.snapRows = this.height / this.widgetData.snapRowSpace
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getComponentProps(): IContainerProps {
|
|
|
|
|
return {
|
|
|
|
|
widgetId: this.widgetData.widgetId,
|
|
|
|
|
snapColumnSpace: this.widgetData.snapColumnSpace,
|
|
|
|
|
snapRowSpace: this.widgetData.snapRowSpace,
|
|
|
|
|
snapColumns: this.widgetData.snapColumns,
|
|
|
|
|
snapRows: this.widgetData.snapRows,
|
|
|
|
|
orientation: this.widgetData.orientation
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetView(): any {
|
|
|
|
|
return (
|
|
|
|
|
<ContainerComponent {...this.getComponentProps()}>
|
|
|
|
|
{this.widgetData.children
|
|
|
|
|
? this.widgetData.children.map(childWidgetData => {
|
2019-02-10 14:14:58 +00:00
|
|
|
childWidgetData.parentColumnSpace = this.widgetData
|
|
|
|
|
.snapColumnSpace
|
|
|
|
|
? this.widgetData.snapColumnSpace
|
|
|
|
|
: 0
|
2019-02-10 13:06:05 +00:00
|
|
|
childWidgetData.parentRowSpace = this.widgetData.snapRowSpace
|
2019-02-10 14:14:58 +00:00
|
|
|
? this.widgetData.snapRowSpace
|
|
|
|
|
: 0
|
2019-02-10 13:06:05 +00:00
|
|
|
return WidgetFactory.createWidget(childWidgetData).getWidgetView()
|
|
|
|
|
})
|
|
|
|
|
: undefined}
|
|
|
|
|
</ContainerComponent>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetType(): WidgetType {
|
|
|
|
|
return "CONTAINER_WIDGET"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 16:39:09 +00:00
|
|
|
export interface IContainerWidgetProps<T extends IWidgetProps> extends IWidgetProps {
|
|
|
|
|
children?: T[]
|
2019-02-10 14:14:58 +00:00
|
|
|
snapColumnSpace?: number
|
|
|
|
|
snapRowSpace?: number
|
|
|
|
|
snapColumns?: number
|
|
|
|
|
snapRows?: number
|
|
|
|
|
orientation?: ContainerOrientation
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ContainerWidget
|