PromucFlow_constructor/app/client/src/components/designSystems/appsmith/ContainerComponent.tsx
Pawan Kumar 3e53df8b64
Update Default styles of Widgets (#2823)
* update default styling of widgets

* [CodeFactor] Apply fixes

* update widgets styles

* fix eslint bug

* update button colors

* update primary button color

* update primary button color

* remove px in 0px in css

* incorporate abhinav review feedbacks

* fixed global styling of popover

Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
Co-authored-by: codefactor-io <support@codefactor.io>
2021-02-08 13:00:01 +05:30

76 lines
2.3 KiB
TypeScript

import React, { ReactNode, useRef, useEffect, RefObject } from "react";
import styled, { css } from "styled-components";
import { ComponentProps } from "./BaseComponent";
import { getBorderCSSShorthand, invisible } from "constants/DefaultTheme";
import { Color } from "constants/Colors";
import { generateClassName, getCanvasClassName } from "utils/generators";
const scrollContents = css`
overflow-y: auto;
position: absolute;
`;
const StyledContainerComponent = styled.div<
ContainerComponentProps & {
ref: RefObject<HTMLDivElement>;
}
>`
${(props) =>
props.containerStyle !== "none"
? `
border: ${getBorderCSSShorthand(props.theme.borders[2])};
border-radius: 0;`
: ""}
height: 100%;
width: 100%;
background: ${(props) => props.backgroundColor};
${(props) => (!props.isVisible ? invisible : "")};
overflow: hidden;
${(props) => (props.shouldScrollContents ? scrollContents : "")}
}`;
const 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}
ref={containerRef}
containerStyle={containerStyle}
// Before you remove: generateClassName is used for bounding the resizables within this canvas
// getCanvasClassName is used to add a scrollable parent.
className={`${
props.shouldScrollContents ? getCanvasClassName() : ""
} ${generateClassName(props.widgetId)}`}
>
{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;
}
export default ContainerComponent;