* update meta properties + default properties map * update widget registery * update get meta property * update metahoc + widgetfactory + data tree evaluator * try sending function as string to worker * revert data tree evaluator update * pass default props map from dataTreeWidget file * wip * save child meta properties * remove console.log * save meta and default map in list * update listwidget * remove console.log + unused variables * revert getMetaPropertiesMap function * fix data tree test * fix list widget test * fix entity definition test * fix overriting of item in updatedItems * remove todo comments * fix meta prop issue * revert making meta properties from undefiend to "" & fix filepicker bug * fix test case * change items to listData and updatedItems to items * remove console.log * fix test * extract derived properties to dervied.js * disabled top, left, right resize handler list widget container * add test for dervied js * add test for selectedItem * fix background color bug on hover * remove console.log * fix chart widget inside list widget * fix checkbox issue + points raised by yogesh * revert the createImmerReducer usage * fix parse derived properties * remove internal props object that fails the test * fix import typo * allow bottom resize handler * fix template height check * fix template height check * update template size check * fix the is visible invalid prop issue * fix migration of list widget phase 2 * fix migration * remove unused import * fix migration * fix migration * remove console.log * hide delete option for container in entity explorer * fix testcases * remove unused import * fix switch widget meta prop Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
95 lines
3.0 KiB
TypeScript
95 lines
3.0 KiB
TypeScript
import React, { ReactNode, useRef, useEffect, RefObject } from "react";
|
|
import styled, { css } from "styled-components";
|
|
import tinycolor from "tinycolor2";
|
|
import { ComponentProps } from "./BaseComponent";
|
|
import { invisible } from "constants/DefaultTheme";
|
|
import { Color } from "constants/Colors";
|
|
import { generateClassName, getCanvasClassName } from "utils/generators";
|
|
|
|
const scrollContents = css`
|
|
overflow-y: auto;
|
|
`;
|
|
|
|
const StyledContainerComponent = styled.div<
|
|
ContainerComponentProps & {
|
|
ref: RefObject<HTMLDivElement>;
|
|
}
|
|
>`
|
|
${(props) =>
|
|
props.containerStyle !== "none"
|
|
? `
|
|
box-shadow: 0px 0px 0px 1px #E7E7E7;
|
|
border-radius: 0;`
|
|
: ""}
|
|
height: 100%;
|
|
width: 100%;
|
|
background: ${(props) => props.backgroundColor};
|
|
opacity: ${(props) => (props.resizeDisabled ? "0.8" : "1")};
|
|
position: relative;
|
|
${(props) => (!props.isVisible ? invisible : "")};
|
|
box-shadow: ${(props) =>
|
|
props.selected ? "0px 0px 0px 3px rgba(59,130,246,0.5)" : "none"};
|
|
z-index: ${(props) => (props.focused ? "3" : props.selected ? "2" : "1")};
|
|
${(props) => (props.shouldScrollContents ? scrollContents : "")}
|
|
|
|
&:hover {
|
|
z-index: ${(props) => (props.onClickCapture ? "2" : "1")};
|
|
cursor: ${(props) => (props.onClickCapture ? "pointer" : "inherit")};
|
|
background: ${(props) => {
|
|
return props.onClickCapture && props.backgroundColor
|
|
? tinycolor(props.backgroundColor)
|
|
.darken(5)
|
|
.toString()
|
|
: props.backgroundColor;
|
|
}};
|
|
}
|
|
}`;
|
|
|
|
function ContainerComponent(props: ContainerComponentProps) {
|
|
const containerStyle = props.containerStyle || "card";
|
|
const containerRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (!props.shouldScrollContents) {
|
|
const supportsNativeSmoothScroll =
|
|
"scrollBehavior" in document.documentElement.style;
|
|
if (supportsNativeSmoothScroll) {
|
|
containerRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
|
} else {
|
|
if (containerRef.current) {
|
|
containerRef.current.scrollTop = 0;
|
|
}
|
|
}
|
|
}
|
|
}, [props.shouldScrollContents]);
|
|
return (
|
|
<StyledContainerComponent
|
|
{...props}
|
|
className={`${
|
|
props.shouldScrollContents ? getCanvasClassName() : ""
|
|
} ${generateClassName(props.widgetId)}`}
|
|
containerStyle={containerStyle}
|
|
// Before you remove: generateClassName is used for bounding the resizables within this canvas
|
|
// getCanvasClassName is used to add a scrollable parent.
|
|
ref={containerRef}
|
|
>
|
|
{props.children}
|
|
</StyledContainerComponent>
|
|
);
|
|
}
|
|
|
|
export type ContainerStyle = "border" | "card" | "rounded-border" | "none";
|
|
|
|
export interface ContainerComponentProps extends ComponentProps {
|
|
containerStyle?: ContainerStyle;
|
|
children?: ReactNode;
|
|
className?: string;
|
|
backgroundColor?: Color;
|
|
shouldScrollContents?: boolean;
|
|
resizeDisabled?: boolean;
|
|
selected?: boolean;
|
|
focused?: boolean;
|
|
}
|
|
|
|
export default ContainerComponent;
|