2019-09-05 17:47:50 +00:00
|
|
|
import { ComponentProps } from "./BaseComponent";
|
2019-11-04 10:57:19 +00:00
|
|
|
import { ContainerOrientation } from "../../../constants/WidgetConstants";
|
|
|
|
|
import styled from "../../../constants/DefaultTheme";
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
import React, {
|
|
|
|
|
createContext,
|
|
|
|
|
Context,
|
|
|
|
|
useRef,
|
|
|
|
|
useContext,
|
|
|
|
|
forwardRef,
|
|
|
|
|
} from "react";
|
2019-11-04 10:57:19 +00:00
|
|
|
import { FocusContext } from "../../../pages/Editor/Canvas";
|
|
|
|
|
import { getBorderCSSShorthand } from "../../../constants/DefaultTheme";
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-10-31 11:26:37 +00:00
|
|
|
export type StyledContainerProps = ContainerProps & {
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
focus?: boolean;
|
2019-10-31 11:26:37 +00:00
|
|
|
imageUrl?: string;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const StyledContainer = styled("div")<StyledContainerProps>`
|
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-10-31 11:26:37 +00:00
|
|
|
background: ${props => props.imageUrl}
|
2019-03-19 15:21:27 +00:00
|
|
|
background: ${props => props.style.backgroundColor};
|
2019-11-06 06:35:15 +00:00
|
|
|
color: ${props => props.theme.colors.textDefault};
|
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 {
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
content: "${props => (props.focus ? 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%;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
/* eslint-disable react/display-name */
|
|
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
|
type Ref = HTMLDivElement;
|
|
|
|
|
export const Container = forwardRef<Ref, ContainerProps>((props, ref) => {
|
|
|
|
|
const { isFocused } = useContext(FocusContext);
|
|
|
|
|
const focus = isFocused === props.widgetId;
|
|
|
|
|
|
|
|
|
|
return <StyledContainer ref={ref} {...props} focus={focus} />;
|
|
|
|
|
});
|
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({});
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
type ContainerComponentWrapperProps = ContainerStyleProps & {
|
|
|
|
|
isRoot?: boolean;
|
|
|
|
|
};
|
|
|
|
|
const ContainerComponentWrapper = styled.div<ContainerComponentWrapperProps>`
|
|
|
|
|
/* TODO(abhinav)(Issue: #107): this will changed based on the ContainerStyleProps */
|
|
|
|
|
border: ${props =>
|
|
|
|
|
!props.isRoot && getBorderCSSShorthand(props.theme.borders[2])};
|
|
|
|
|
box-shadow: ${props =>
|
|
|
|
|
!props.isRoot ? "0px 2px 4px rgba(67, 70, 74, 0.14)" : "none"};
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
`;
|
2019-10-01 20:07:43 +00:00
|
|
|
|
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}>
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
<ContainerComponentWrapper isRoot={props.isRoot}>
|
|
|
|
|
{props.children}
|
|
|
|
|
</ContainerComponentWrapper>
|
2019-10-01 20:07:43 +00:00
|
|
|
</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
|
|
|
}
|
|
|
|
|
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
type ContainerStyleProps = {
|
|
|
|
|
styleName?: "border" | "card" | "rounded-border";
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default ContainerComponent;
|