2019-09-05 17:47:50 +00:00
|
|
|
import { ComponentProps } from "./BaseComponent";
|
2019-08-29 11:22:09 +00:00
|
|
|
import { ContainerOrientation } from "../constants/WidgetConstants";
|
|
|
|
|
import styled from "../constants/DefaultTheme";
|
2019-10-03 11:04:11 +00:00
|
|
|
import React, { createContext, Context, useRef } from "react";
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-09-02 12:25:17 +00:00
|
|
|
export const Container = styled("div")<ContainerProps>`
|
2019-08-20 13:19:19 +00:00
|
|
|
display: flex;
|
2019-08-20 09:39:08 +00:00
|
|
|
flex-direction: ${props => {
|
2019-09-09 09:08:54 +00:00
|
|
|
return props.orientation === "HORIZONTAL" ? "row" : "column";
|
2019-03-21 12:10:32 +00:00
|
|
|
}};
|
2019-03-19 15:21:27 +00:00
|
|
|
background: ${props => props.style.backgroundColor};
|
2019-09-05 17:47:50 +00:00
|
|
|
color: ${props => props.theme.colors.primary};
|
2019-03-21 12:10:32 +00:00
|
|
|
position: ${props => {
|
2019-09-09 09:08:54 +00:00
|
|
|
return props.style.positionType === "ABSOLUTE" ? "absolute" : "relative";
|
2019-03-21 12:10:32 +00:00
|
|
|
}};
|
2019-10-01 20:07:43 +00:00
|
|
|
height: 100%;
|
|
|
|
|
left: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
width: 100%;
|
2019-10-21 15:12:45 +00:00
|
|
|
padding: ${props => props.theme.spaces[1]}px;
|
2019-10-02 18:13:04 +00:00
|
|
|
&:after {
|
2019-10-02 21:56:25 +00:00
|
|
|
content: "${props => props.widgetName}";
|
2019-10-02 18:13:04 +00:00
|
|
|
position: absolute;
|
2019-10-21 15:12:45 +00:00
|
|
|
top: -${props => props.theme.spaces[8]}px;
|
2019-10-02 18:13:04 +00:00
|
|
|
font-size: ${props => props.theme.fontSizes[2]}px;
|
2019-10-02 19:42:25 +00:00
|
|
|
color: ${props => props.theme.colors.containerBorder};
|
2019-10-02 18:13:04 +00:00
|
|
|
text-align: left;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
2019-08-29 11:22:09 +00:00
|
|
|
`;
|
2019-09-17 10:09:00 +00:00
|
|
|
|
2019-10-01 20:07:43 +00:00
|
|
|
export const ParentBoundsContext: Context<{
|
|
|
|
|
boundingParent?: React.RefObject<HTMLDivElement>;
|
|
|
|
|
}> = createContext({});
|
|
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
const ContainerComponent = (props: ContainerProps) => {
|
2019-10-01 20:07:43 +00:00
|
|
|
const container = useRef(null);
|
2019-10-03 11:04:11 +00:00
|
|
|
return (
|
2019-10-01 20:07:43 +00:00
|
|
|
<ParentBoundsContext.Provider value={{ boundingParent: container }}>
|
|
|
|
|
<Container ref={container} {...props}>
|
|
|
|
|
{props.children}
|
|
|
|
|
</Container>
|
|
|
|
|
</ParentBoundsContext.Provider>
|
|
|
|
|
);
|
2019-09-09 09:08:54 +00:00
|
|
|
};
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-09-05 17:47:50 +00:00
|
|
|
export interface ContainerProps extends ComponentProps {
|
2019-08-29 11:22:09 +00:00
|
|
|
children?: JSX.Element[] | JSX.Element;
|
|
|
|
|
orientation?: ContainerOrientation;
|
2019-10-01 20:07:43 +00:00
|
|
|
isRoot?: boolean;
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default ContainerComponent;
|