2020-03-27 09:02:11 +00:00
|
|
|
import React, { ReactNode } from "react";
|
2019-11-13 07:00:25 +00:00
|
|
|
import { BaseStyle } from "widgets/BaseWidget";
|
2020-03-06 09:33:20 +00:00
|
|
|
import { WIDGET_PADDING } from "constants/WidgetConstants";
|
2020-03-27 09:02:11 +00:00
|
|
|
import { generateClassName } from "utils/generators";
|
2020-06-10 17:31:20 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
|
|
const PositionedWidget = styled.div`
|
|
|
|
|
&:hover {
|
|
|
|
|
z-index: 1;
|
|
|
|
|
}
|
|
|
|
|
`;
|
2019-11-13 07:00:25 +00:00
|
|
|
type PositionedContainerProps = {
|
|
|
|
|
style: BaseStyle;
|
2020-03-27 09:02:11 +00:00
|
|
|
children: ReactNode;
|
|
|
|
|
widgetId: string;
|
2020-05-21 06:15:12 +00:00
|
|
|
widgetType: string;
|
2019-11-13 07:00:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const PositionedContainer = (props: PositionedContainerProps) => {
|
2020-03-04 08:10:40 +00:00
|
|
|
const x = props.style.xPosition + (props.style.xPositionUnit || "px");
|
2020-03-27 09:02:11 +00:00
|
|
|
const y = props.style.yPosition + (props.style.yPositionUnit || "px");
|
|
|
|
|
const padding = WIDGET_PADDING;
|
2019-11-13 07:00:25 +00:00
|
|
|
return (
|
2020-06-10 17:31:20 +00:00
|
|
|
<PositionedWidget
|
2019-11-13 07:00:25 +00:00
|
|
|
style={{
|
2020-03-06 09:33:20 +00:00
|
|
|
position: "absolute",
|
|
|
|
|
left: x,
|
|
|
|
|
top: y,
|
2019-11-13 07:00:25 +00:00
|
|
|
height: props.style.componentHeight + (props.style.heightUnit || "px"),
|
|
|
|
|
width: props.style.componentWidth + (props.style.widthUnit || "px"),
|
2020-03-27 09:02:11 +00:00
|
|
|
padding: padding + "px",
|
2019-11-13 07:00:25 +00:00
|
|
|
}}
|
2020-03-27 09:02:11 +00:00
|
|
|
//Before you remove: This is used by property pane to reference the element
|
2020-05-21 06:15:12 +00:00
|
|
|
className={
|
|
|
|
|
generateClassName(props.widgetId) +
|
|
|
|
|
" " +
|
|
|
|
|
`t--widget-${props.widgetType
|
|
|
|
|
.split("_")
|
|
|
|
|
.join("")
|
|
|
|
|
.toLowerCase()}`
|
|
|
|
|
}
|
2019-11-13 07:00:25 +00:00
|
|
|
>
|
|
|
|
|
{props.children}
|
2020-06-10 17:31:20 +00:00
|
|
|
</PositionedWidget>
|
2019-11-13 07:00:25 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-16 11:46:21 +00:00
|
|
|
PositionedContainer.padding = WIDGET_PADDING;
|
2019-11-13 07:00:25 +00:00
|
|
|
|
|
|
|
|
export default PositionedContainer;
|