|
| 1 | +import { ContainerStyleType } from "comps/controls/styleControlConstants"; |
| 2 | +import { EditorContext } from "comps/editorState"; |
| 3 | +import { BackgroundColorContext } from "comps/utils/backgroundColorContext"; |
| 4 | +import { HintPlaceHolder, ScrollBar } from "lowcoder-design"; |
| 5 | +import { ReactNode, useContext, useEffect, useState } from "react"; |
| 6 | +import styled, { css } from "styled-components"; |
| 7 | +import { checkIsMobile } from "util/commonUtils"; |
| 8 | +import { |
| 9 | + gridItemCompToGridItems, |
| 10 | + InnerGrid, |
| 11 | +} from "../containerComp/containerView"; |
| 12 | +import { TriContainerViewProps } from "../triContainerComp/triContainerCompBuilder"; |
| 13 | +import { Coolshape } from "coolshapes-react"; |
| 14 | + |
| 15 | +const getStyle = (style: ContainerStyleType) => { |
| 16 | + return css` |
| 17 | + border-color: ${style.border}; |
| 18 | + border-width: ${style.borderWidth}; |
| 19 | + border-radius: ${style.radius}; |
| 20 | + overflow: hidden; |
| 21 | + padding: ${style.padding}; |
| 22 | + ${style.background && `background-color: ${style.background};`} |
| 23 | + ${style.backgroundImage && `background-image: ${style.backgroundImage};`} |
| 24 | + ${style.backgroundImageRepeat && |
| 25 | + `background-repeat: ${style.backgroundImageRepeat};`} |
| 26 | + ${style.backgroundImageSize && |
| 27 | + `background-size: ${style.backgroundImageSize};`} |
| 28 | + ${style.backgroundImagePosition && |
| 29 | + `background-position: ${style.backgroundImagePosition};`} |
| 30 | + ${style.backgroundImageOrigin && |
| 31 | + `background-origin: ${style.backgroundImageOrigin};`} |
| 32 | + `; |
| 33 | +}; |
| 34 | + |
| 35 | +const Wrapper = styled.div<{ $style: ContainerStyleType }>` |
| 36 | + display: flex; |
| 37 | + flex-flow: column; |
| 38 | + height: 100%; |
| 39 | + border: 1px solid #d7d9e0; |
| 40 | + border-radius: 4px; |
| 41 | + ${(props) => props.$style && getStyle(props.$style)} |
| 42 | +`; |
| 43 | + |
| 44 | +const BodyInnerGrid = styled(InnerGrid)<{ |
| 45 | + $showBorder: boolean; |
| 46 | + $backgroundColor: string; |
| 47 | + $borderColor: string; |
| 48 | + $borderWidth: string; |
| 49 | + $backgroundImage: string; |
| 50 | + $backgroundImageRepeat: string; |
| 51 | + $backgroundImageSize: string; |
| 52 | + $backgroundImagePosition: string; |
| 53 | + $backgroundImageOrigin: string; |
| 54 | +}>` |
| 55 | + border-top: ${(props) => |
| 56 | + `${props.$showBorder ? props.$borderWidth : 0} solid ${props.$borderColor}`}; |
| 57 | + flex: 1; |
| 58 | + ${(props) => |
| 59 | + props.$backgroundColor && `background-color: ${props.$backgroundColor};`} |
| 60 | + border-radius: 0; |
| 61 | + ${(props) => |
| 62 | + props.$backgroundImage && `background-image: ${props.$backgroundImage};`} |
| 63 | + ${(props) => |
| 64 | + props.$backgroundImageRepeat && |
| 65 | + `background-repeat: ${props.$backgroundImageRepeat};`} |
| 66 | + ${(props) => |
| 67 | + props.$backgroundImageSize && |
| 68 | + `background-size: ${props.$backgroundImageSize};`} |
| 69 | + ${(props) => |
| 70 | + props.$backgroundImagePosition && |
| 71 | + `background-position: ${props.$backgroundImagePosition};`} |
| 72 | + ${(props) => |
| 73 | + props.$backgroundImageOrigin && |
| 74 | + `background-origin: ${props.$backgroundImageOrigin};`} |
| 75 | +`; |
| 76 | + |
| 77 | +export type TriContainerProps = TriContainerViewProps & { |
| 78 | + hintPlaceholder?: ReactNode; |
| 79 | + icon: any; |
| 80 | +}; |
| 81 | + |
| 82 | +export function ShapeTriContainer(props: TriContainerProps) { |
| 83 | + const { container, icon } = props; |
| 84 | + const { showHeader, showFooter } = container; |
| 85 | + // When the header and footer are not displayed, the body must be displayed |
| 86 | + const showBody = container.showBody || (!showHeader && !showFooter); |
| 87 | + const scrollbars = container.scrollbars; |
| 88 | + |
| 89 | + const { items: headerItems, ...otherHeaderProps } = container.header; |
| 90 | + const { items: bodyItems, ...otherBodyProps } = |
| 91 | + container.body["0"].children.view.getView(); |
| 92 | + const { items: footerItems, ...otherFooterProps } = container.footer; |
| 93 | + const { style, headerStyle, bodyStyle, footerStyle } = container; |
| 94 | + |
| 95 | + const editorState = useContext(EditorContext); |
| 96 | + const maxWidth = editorState.getAppSettings().maxWidth; |
| 97 | + const isMobile = checkIsMobile(maxWidth); |
| 98 | + const paddingWidth = isMobile ? 8 : 0; |
| 99 | + |
| 100 | + let [shape, setShape] = useState({ value: "star", index: 0 }); |
| 101 | + useEffect(() => { |
| 102 | + if (icon.props?.value) { |
| 103 | + let shapeDetails = icon.props?.value; |
| 104 | + setShape({ |
| 105 | + index: parseInt(shapeDetails?.split("_")[0]), |
| 106 | + value: shapeDetails?.split("_")[1], |
| 107 | + }); |
| 108 | + } |
| 109 | + }, [icon.props]); |
| 110 | + |
| 111 | + return ( |
| 112 | + <div style={{ padding: style.margin, height: "100%" }}> |
| 113 | + <Wrapper $style={style}> |
| 114 | + <BackgroundColorContext.Provider value={bodyStyle.background}> |
| 115 | + <ScrollBar |
| 116 | + style={{ |
| 117 | + height: container.autoHeight ? "auto" : "100%", |
| 118 | + margin: "0px", |
| 119 | + padding: "0px", |
| 120 | + }} |
| 121 | + hideScrollbar={!scrollbars} |
| 122 | + > |
| 123 | + <div style={{ position: "relative", height: "100%" }}> |
| 124 | + <Coolshape |
| 125 | + type={shape?.value as any} |
| 126 | + index={shape.index} |
| 127 | + styles={{ |
| 128 | + position: "absolute", |
| 129 | + top: "0", |
| 130 | + left: "50%", |
| 131 | + transform: "translateX(-50%)", |
| 132 | + }} |
| 133 | + /> |
| 134 | + <BodyInnerGrid |
| 135 | + $showBorder={false} |
| 136 | + {...otherBodyProps} |
| 137 | + items={gridItemCompToGridItems(bodyItems)} |
| 138 | + autoHeight={container.autoHeight} |
| 139 | + emptyRows={14} |
| 140 | + minHeight={"142px"} |
| 141 | + hintPlaceholder={props.hintPlaceholder ?? HintPlaceHolder} |
| 142 | + $backgroundColor={bodyStyle?.background || "transparent"} |
| 143 | + $borderColor={style?.border} |
| 144 | + $borderWidth={style?.borderWidth} |
| 145 | + $backgroundImage={bodyStyle?.backgroundImage} |
| 146 | + $backgroundImageRepeat={bodyStyle?.backgroundImageRepeat} |
| 147 | + $backgroundImageSize={bodyStyle?.backgroundImageSize} |
| 148 | + $backgroundImagePosition={bodyStyle?.backgroundImagePosition} |
| 149 | + $backgroundImageOrigin={bodyStyle?.backgroundImageOrigin} |
| 150 | + style={{ |
| 151 | + zIndex: 999, |
| 152 | + }} |
| 153 | + /> |
| 154 | + </div> |
| 155 | + </ScrollBar> |
| 156 | + </BackgroundColorContext.Provider> |
| 157 | + </Wrapper> |
| 158 | + </div> |
| 159 | + ); |
| 160 | +} |
0 commit comments