2023-02-03 05:47:40 +00:00
|
|
|
import React, {
|
|
|
|
|
MouseEventHandler,
|
|
|
|
|
PropsWithChildren,
|
|
|
|
|
ReactNode,
|
|
|
|
|
RefObject,
|
2023-02-14 16:07:31 +00:00
|
|
|
useCallback,
|
2023-02-03 05:47:40 +00:00
|
|
|
useEffect,
|
|
|
|
|
useRef,
|
|
|
|
|
} from "react";
|
|
|
|
|
import styled from "styled-components";
|
2023-02-14 16:07:31 +00:00
|
|
|
import tinycolor from "tinycolor2";
|
|
|
|
|
import fastdom from "fastdom";
|
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 { 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;
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
${(props) => (!!props.dropDisabled ? `position: relative;` : ``)}
|
|
|
|
|
|
2023-02-03 05:47:40 +00:00
|
|
|
${(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 {
|
2023-02-14 16:07:31 +00:00
|
|
|
onClick?: MouseEventHandler<HTMLDivElement>;
|
2023-02-03 05:47:40 +00:00
|
|
|
onClickCapture?: MouseEventHandler<HTMLDivElement>;
|
|
|
|
|
resizeDisabled?: boolean;
|
|
|
|
|
shouldScrollContents?: boolean;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
widgetId: string;
|
|
|
|
|
type: WidgetType;
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
dropDisabled?: boolean;
|
2023-02-03 05:47:40 +00:00
|
|
|
}
|
|
|
|
|
function ContainerComponentWrapper(
|
|
|
|
|
props: PropsWithChildren<ContainerWrapperProps>,
|
|
|
|
|
) {
|
2020-03-27 09:02:11 +00:00
|
|
|
const containerRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
|
2023-02-14 16:07:31 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!props.shouldScrollContents) {
|
2021-01-07 05:06:25 +00:00
|
|
|
const supportsNativeSmoothScroll =
|
|
|
|
|
"scrollBehavior" in document.documentElement.style;
|
2023-02-14 16:07:31 +00:00
|
|
|
|
|
|
|
|
fastdom.mutate(() => {
|
|
|
|
|
if (supportsNativeSmoothScroll) {
|
|
|
|
|
containerRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
|
} else {
|
|
|
|
|
if (containerRef.current) {
|
|
|
|
|
containerRef.current.scrollTop = 0;
|
|
|
|
|
}
|
2021-01-07 05:06:25 +00:00
|
|
|
}
|
2023-02-14 16:07:31 +00:00
|
|
|
});
|
2020-03-27 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
}, [props.shouldScrollContents]);
|
2023-02-14 16:07:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is for all the container widgets that have the onClickCapture method.
|
|
|
|
|
* The mouse over event makes sure to add the class `hover-styles` so that a
|
|
|
|
|
* darker shade of the background color takes effect to induce the hover effect.
|
|
|
|
|
*
|
|
|
|
|
* Why not use the :hover css selector?
|
|
|
|
|
* For cases like List widget, it can have inner list widgets; so there can be
|
|
|
|
|
* containers inside containers. When the inner container is hovered, the parent container's
|
|
|
|
|
* :hover selector is also triggered making the outer and inner container both having this
|
|
|
|
|
* hover effect.
|
|
|
|
|
*/
|
|
|
|
|
const onMouseOver = useCallback(
|
|
|
|
|
(e: React.MouseEvent<HTMLDivElement>) => {
|
|
|
|
|
const el = e.currentTarget;
|
|
|
|
|
const widgetType = el.getAttribute("type");
|
|
|
|
|
const widgetId = el.dataset.widgetid;
|
|
|
|
|
const isMainContainer = widgetId === "0";
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
(widgetType === "CONTAINER_WIDGET" && props.onClickCapture) ||
|
|
|
|
|
isMainContainer
|
|
|
|
|
) {
|
|
|
|
|
const elementsHovered = document.getElementsByClassName(
|
|
|
|
|
"hover-styles",
|
|
|
|
|
) as HTMLCollectionOf<HTMLDivElement>;
|
|
|
|
|
|
|
|
|
|
fastdom.mutate(() => {
|
|
|
|
|
for (const elHovered of elementsHovered) {
|
|
|
|
|
elHovered.classList.remove("hover-styles");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isMainContainer) {
|
|
|
|
|
el.classList.add("hover-styles");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[props.onClickCapture],
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
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`}
|
2023-02-14 16:07:31 +00:00
|
|
|
data-widgetId={props.widgetId}
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
dropDisabled={props.dropDisabled}
|
2023-02-14 16:07:31 +00:00
|
|
|
onClick={props.onClick}
|
2023-02-03 05:47:40 +00:00
|
|
|
onClickCapture={props.onClickCapture}
|
2023-02-14 16:07:31 +00:00
|
|
|
onMouseOver={onMouseOver}
|
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
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
dropDisabled={props.dropDisabled}
|
2023-02-14 16:07:31 +00:00
|
|
|
onClick={props.onClick}
|
2023-02-03 05:47:40 +00:00
|
|
|
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}
|
2023-02-14 16:07:31 +00:00
|
|
|
selected={props.selected}
|
2023-02-03 05:47:40 +00:00
|
|
|
widgetId={props.widgetId}
|
2020-03-27 09:02:11 +00:00
|
|
|
>
|
2023-02-03 05:47:40 +00:00
|
|
|
<ContainerComponentWrapper
|
|
|
|
|
backgroundColor={props.backgroundColor}
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
dropDisabled={props.dropDisabled}
|
2023-02-14 16:07:31 +00:00
|
|
|
onClick={props.onClick}
|
2023-02-03 05:47:40 +00:00
|
|
|
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-14 16:07:31 +00:00
|
|
|
selected?: boolean;
|
|
|
|
|
focused?: boolean;
|
2023-02-03 05:47:40 +00:00
|
|
|
detachFromLayout?: boolean;
|
2023-02-14 16:07:31 +00:00
|
|
|
onClick?: MouseEventHandler<HTMLDivElement>;
|
2023-02-03 05:47:40 +00:00
|
|
|
onClickCapture?: MouseEventHandler<HTMLDivElement>;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
type: WidgetType;
|
|
|
|
|
noScroll?: boolean;
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
dropDisabled?: boolean;
|
2019-02-10 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default ContainerComponent;
|