2020-03-27 09:02:11 +00:00
|
|
|
import React, { ReactNode, useRef, useEffect, RefObject } from "react";
|
|
|
|
|
import styled, { css } from "styled-components";
|
2021-05-27 06:41:38 +00:00
|
|
|
import tinycolor from "tinycolor2";
|
2021-06-17 13:26:54 +00:00
|
|
|
import { invisible } from "constants/DefaultTheme";
|
2019-11-13 07:00:25 +00:00
|
|
|
import { Color } from "constants/Colors";
|
2020-03-27 09:02:11 +00:00
|
|
|
import { generateClassName, getCanvasClassName } from "utils/generators";
|
2021-09-16 04:21:31 +00:00
|
|
|
import WidgetStyleContainer, {
|
|
|
|
|
WidgetStyleContainerProps,
|
|
|
|
|
} from "components/designSystems/appsmith/WidgetStyleContainer";
|
|
|
|
|
import { pick } from "lodash";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { ComponentProps } from "widgets/BaseComponent";
|
2021-09-16 16:54:12 +00:00
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
2019-11-13 07:00:25 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
const scrollContents = css`
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledContainerComponent = styled.div<
|
|
|
|
|
ContainerComponentProps & {
|
|
|
|
|
ref: RefObject<HTMLDivElement>;
|
|
|
|
|
}
|
|
|
|
|
>`
|
2019-10-01 20:07:43 +00:00
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
2020-12-24 04:32:25 +00:00
|
|
|
background: ${(props) => props.backgroundColor};
|
2021-05-27 06:41:38 +00:00
|
|
|
opacity: ${(props) => (props.resizeDisabled ? "0.8" : "1")};
|
|
|
|
|
position: relative;
|
2020-12-24 04:32:25 +00:00
|
|
|
${(props) => (!props.isVisible ? invisible : "")};
|
2021-05-27 06:41:38 +00:00
|
|
|
box-shadow: ${(props) =>
|
2021-08-09 05:35:01 +00:00
|
|
|
props.selected ? "inset 0px 0px 0px 3px rgba(59,130,246,0.5)" : "none"};
|
2022-05-04 09:45:57 +00:00
|
|
|
border-radius: ${({ borderRadius }) => borderRadius};
|
|
|
|
|
|
2021-07-08 06:30:19 +00:00
|
|
|
${(props) =>
|
|
|
|
|
props.shouldScrollContents === true
|
|
|
|
|
? scrollContents
|
|
|
|
|
: props.shouldScrollContents === false
|
|
|
|
|
? css`
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
`
|
|
|
|
|
: ""}
|
2021-05-27 06:41:38 +00:00
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
z-index: ${(props) => (props.onClickCapture ? "2" : "1")};
|
|
|
|
|
cursor: ${(props) => (props.onClickCapture ? "pointer" : "inherit")};
|
2021-06-18 07:42:57 +00:00
|
|
|
background: ${(props) => {
|
|
|
|
|
return props.onClickCapture && props.backgroundColor
|
2021-05-27 06:41:38 +00:00
|
|
|
? tinycolor(props.backgroundColor)
|
|
|
|
|
.darken(5)
|
|
|
|
|
.toString()
|
2021-06-18 07:42:57 +00:00
|
|
|
: props.backgroundColor;
|
|
|
|
|
}};
|
2021-05-27 06:41:38 +00:00
|
|
|
}
|
2022-06-23 17:55:03 +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
|
|
|
|
2021-09-16 16:54:12 +00:00
|
|
|
function ContainerComponentWrapper(props: ContainerComponentProps) {
|
2020-03-27 09:02:11 +00:00
|
|
|
const containerStyle = props.containerStyle || "card";
|
|
|
|
|
const containerRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!props.shouldScrollContents) {
|
2021-01-07 05:06:25 +00:00
|
|
|
const supportsNativeSmoothScroll =
|
|
|
|
|
"scrollBehavior" in document.documentElement.style;
|
|
|
|
|
if (supportsNativeSmoothScroll) {
|
|
|
|
|
containerRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
|
} else {
|
|
|
|
|
if (containerRef.current) {
|
|
|
|
|
containerRef.current.scrollTop = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-27 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
}, [props.shouldScrollContents]);
|
|
|
|
|
return (
|
2021-09-16 16:54:12 +00:00
|
|
|
<StyledContainerComponent
|
|
|
|
|
{...props}
|
2022-12-30 14:52:11 +00:00
|
|
|
// Before you remove: generateClassName is used for bounding the resizables within this canvas
|
|
|
|
|
// getCanvasClassName is used to add a scrollable parent.
|
2021-09-16 16:54:12 +00:00
|
|
|
className={`${
|
|
|
|
|
props.shouldScrollContents ? getCanvasClassName() : ""
|
|
|
|
|
} ${generateClassName(props.widgetId)}`}
|
|
|
|
|
containerStyle={containerStyle}
|
|
|
|
|
ref={containerRef}
|
2022-12-30 14:52:11 +00:00
|
|
|
tabIndex={props.shouldScrollContents ? undefined : 0}
|
2021-09-16 16:54:12 +00:00
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</StyledContainerComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ContainerComponent(props: ContainerComponentProps) {
|
|
|
|
|
return props.widgetId === MAIN_CONTAINER_WIDGET_ID ? (
|
|
|
|
|
<ContainerComponentWrapper {...props} />
|
|
|
|
|
) : (
|
2021-09-16 04:21:31 +00:00
|
|
|
<WidgetStyleContainer
|
|
|
|
|
{...pick(props, [
|
|
|
|
|
"widgetId",
|
|
|
|
|
"containerStyle",
|
2022-06-23 17:55:03 +00:00
|
|
|
"backgroundColor",
|
2021-09-16 04:21:31 +00:00
|
|
|
"borderColor",
|
|
|
|
|
"borderWidth",
|
|
|
|
|
"borderRadius",
|
|
|
|
|
"boxShadow",
|
|
|
|
|
])}
|
2020-03-27 09:02:11 +00:00
|
|
|
>
|
2021-09-16 16:54:12 +00:00
|
|
|
<ContainerComponentWrapper {...props} />
|
2021-09-16 04:21:31 +00:00
|
|
|
</WidgetStyleContainer>
|
2020-03-27 09:02:11 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-01 20:07:43 +00:00
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
export type ContainerStyle = "border" | "card" | "rounded-border" | "none";
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2021-09-16 04:21:31 +00:00
|
|
|
export interface ContainerComponentProps
|
|
|
|
|
extends ComponentProps,
|
|
|
|
|
WidgetStyleContainerProps {
|
2019-11-13 07:00:25 +00:00
|
|
|
children?: ReactNode;
|
|
|
|
|
className?: string;
|
|
|
|
|
backgroundColor?: Color;
|
2020-03-27 09:02:11 +00:00
|
|
|
shouldScrollContents?: boolean;
|
2021-04-23 05:43:13 +00:00
|
|
|
resizeDisabled?: boolean;
|
2021-05-27 06:41:38 +00:00
|
|
|
selected?: boolean;
|
2021-06-18 07:42:57 +00:00
|
|
|
focused?: boolean;
|
2021-06-28 07:11:47 +00:00
|
|
|
minHeight?: number;
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default ContainerComponent;
|