2023-02-03 05:47:40 +00:00
|
|
|
import React, {
|
|
|
|
|
MouseEventHandler,
|
|
|
|
|
PropsWithChildren,
|
|
|
|
|
ReactNode,
|
|
|
|
|
RefObject,
|
|
|
|
|
useEffect,
|
|
|
|
|
useRef,
|
|
|
|
|
} from "react";
|
|
|
|
|
import styled from "styled-components";
|
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";
|
2023-02-03 05:47:40 +00:00
|
|
|
import tinycolor from "tinycolor2";
|
|
|
|
|
import { WidgetType } from "utils/WidgetFactory";
|
|
|
|
|
import { scrollCSS } from "widgets/WidgetUtils";
|
2020-03-27 09:02:11 +00:00
|
|
|
|
|
|
|
|
const StyledContainerComponent = styled.div<
|
2023-02-03 05:47:40 +00:00
|
|
|
Omit<ContainerWrapperProps, "widgetId">
|
2020-03-27 09:02:11 +00:00
|
|
|
>`
|
2019-10-01 20:07:43 +00:00
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
2023-02-03 05:47:40 +00:00
|
|
|
overflow: hidden;
|
|
|
|
|
${(props) => (props.shouldScrollContents ? scrollCSS : ``)}
|
2021-05-27 06:41:38 +00:00
|
|
|
opacity: ${(props) => (props.resizeDisabled ? "0.8" : "1")};
|
|
|
|
|
|
2023-02-03 05:47:40 +00:00
|
|
|
background: ${(props) => props.backgroundColor};
|
2021-05-27 06:41:38 +00:00
|
|
|
&:hover {
|
2023-02-03 05:47:40 +00:00
|
|
|
background-color: ${(props) => {
|
2021-06-18 07:42:57 +00:00
|
|
|
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;
|
|
|
|
|
}};
|
2023-02-03 05:47:40 +00:00
|
|
|
z-index: ${(props) => (props.onClickCapture ? "2" : "1")};
|
|
|
|
|
cursor: ${(props) => (props.onClickCapture ? "pointer" : "inherit")};
|
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
|
|
|
|
2023-02-03 05:47:40 +00:00
|
|
|
interface ContainerWrapperProps {
|
|
|
|
|
onClickCapture?: MouseEventHandler<HTMLDivElement>;
|
|
|
|
|
resizeDisabled?: boolean;
|
|
|
|
|
shouldScrollContents?: boolean;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
widgetId: string;
|
|
|
|
|
type: WidgetType;
|
|
|
|
|
}
|
|
|
|
|
function ContainerComponentWrapper(
|
|
|
|
|
props: PropsWithChildren<ContainerWrapperProps>,
|
|
|
|
|
) {
|
2020-03-27 09:02:11 +00:00
|
|
|
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
|
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.
|
2023-02-03 05:47:40 +00:00
|
|
|
backgroundColor={props.backgroundColor}
|
2021-09-16 16:54:12 +00:00
|
|
|
className={`${
|
|
|
|
|
props.shouldScrollContents ? getCanvasClassName() : ""
|
2023-02-03 05:47:40 +00:00
|
|
|
} ${generateClassName(props.widgetId)} container-with-scrollbar`}
|
|
|
|
|
onClickCapture={props.onClickCapture}
|
2021-09-16 16:54:12 +00:00
|
|
|
ref={containerRef}
|
2023-02-03 05:47:40 +00:00
|
|
|
resizeDisabled={props.resizeDisabled}
|
|
|
|
|
shouldScrollContents={!!props.shouldScrollContents}
|
2022-12-30 14:52:11 +00:00
|
|
|
tabIndex={props.shouldScrollContents ? undefined : 0}
|
2023-02-03 05:47:40 +00:00
|
|
|
type={props.type}
|
2021-09-16 16:54:12 +00:00
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</StyledContainerComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ContainerComponent(props: ContainerComponentProps) {
|
2023-02-03 05:47:40 +00:00
|
|
|
if (props.detachFromLayout) {
|
|
|
|
|
return (
|
|
|
|
|
<ContainerComponentWrapper
|
|
|
|
|
onClickCapture={props.onClickCapture}
|
|
|
|
|
resizeDisabled={props.resizeDisabled}
|
|
|
|
|
shouldScrollContents={props.shouldScrollContents}
|
|
|
|
|
type={props.type}
|
|
|
|
|
widgetId={props.widgetId}
|
|
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</ContainerComponentWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
2021-09-16 04:21:31 +00:00
|
|
|
<WidgetStyleContainer
|
2023-02-03 05:47:40 +00:00
|
|
|
backgroundColor={props.backgroundColor}
|
|
|
|
|
borderColor={props.borderColor}
|
|
|
|
|
borderRadius={props.borderRadius}
|
|
|
|
|
borderWidth={props.borderWidth}
|
|
|
|
|
boxShadow={props.boxShadow}
|
|
|
|
|
className="style-container"
|
|
|
|
|
containerStyle={props.containerStyle}
|
|
|
|
|
widgetId={props.widgetId}
|
2020-03-27 09:02:11 +00:00
|
|
|
>
|
2023-02-03 05:47:40 +00:00
|
|
|
<ContainerComponentWrapper
|
|
|
|
|
backgroundColor={props.backgroundColor}
|
|
|
|
|
onClickCapture={props.onClickCapture}
|
|
|
|
|
resizeDisabled={props.resizeDisabled}
|
|
|
|
|
shouldScrollContents={props.shouldScrollContents}
|
|
|
|
|
type={props.type}
|
|
|
|
|
widgetId={props.widgetId}
|
|
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</ContainerComponentWrapper>
|
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
|
|
|
|
2023-02-03 05:47:40 +00:00
|
|
|
export interface ContainerComponentProps extends WidgetStyleContainerProps {
|
2019-11-13 07:00:25 +00:00
|
|
|
children?: ReactNode;
|
2020-03-27 09:02:11 +00:00
|
|
|
shouldScrollContents?: boolean;
|
2021-04-23 05:43:13 +00:00
|
|
|
resizeDisabled?: boolean;
|
2023-02-03 05:47:40 +00:00
|
|
|
detachFromLayout?: boolean;
|
|
|
|
|
onClickCapture?: MouseEventHandler<HTMLDivElement>;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
type: WidgetType;
|
|
|
|
|
noScroll?: boolean;
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default ContainerComponent;
|