|
| 1 | +import { |
| 2 | + ContainerStyleType, |
| 3 | + heightCalculator, |
| 4 | + widthCalculator, |
| 5 | +} from "comps/controls/styleControlConstants"; |
| 6 | +import { EditorContext } from "comps/editorState"; |
| 7 | +import { BackgroundColorContext } from "comps/utils/backgroundColorContext"; |
| 8 | +import { HintPlaceHolder, TacoMarkDown } from "lowcoder-design"; |
| 9 | +import { ReactNode, useContext } from "react"; |
| 10 | +import styled, { css } from "styled-components"; |
| 11 | +import { checkIsMobile } from "util/commonUtils"; |
| 12 | +import { |
| 13 | + gridItemCompToGridItems, |
| 14 | + InnerGrid, |
| 15 | +} from "../containerComp/containerView"; |
| 16 | +import { TriContainerViewProps } from "../triContainerComp/triContainerCompBuilder"; |
| 17 | + |
| 18 | +const getStyle = (style: ContainerStyleType) => { |
| 19 | + return css` |
| 20 | + border-color: ${style.border}; |
| 21 | + border-radius: ${style.radius}; |
| 22 | + border-width: ${style.borderWidth}; |
| 23 | + overflow: hidden; |
| 24 | + margin: ${style.margin}; |
| 25 | + padding: ${style.padding}; |
| 26 | +
|
| 27 | + width: ${widthCalculator(style.margin)}; |
| 28 | + height: ${heightCalculator(style.margin)}; |
| 29 | + `; |
| 30 | +}; |
| 31 | + |
| 32 | +const Wrapper = styled.div<{ $style: ContainerStyleType }>` |
| 33 | + display: flex; |
| 34 | + flex-flow: column; |
| 35 | + height: 100%; |
| 36 | + border: 1px solid #d7d9e0; |
| 37 | + border-radius: 4px; |
| 38 | + ${(props) => props.$style && getStyle(props.$style)} |
| 39 | +`; |
| 40 | + |
| 41 | +const HeaderInnerGrid = styled(InnerGrid)<{ backgroundColor: string }>` |
| 42 | + overflow: visible; |
| 43 | + ${(props) => |
| 44 | + props.backgroundColor && `background-color: ${props.backgroundColor};`} |
| 45 | + border-radius: 0; |
| 46 | +`; |
| 47 | + |
| 48 | +const BodyInnerGrid = styled(InnerGrid)<{ |
| 49 | + showBorder: boolean; |
| 50 | + backgroundColor: string; |
| 51 | + borderColor: string; |
| 52 | +}>` |
| 53 | + border-top: ${(props) => |
| 54 | + `${props.showBorder ? 1 : 0}px solid ${props.borderColor}`}; |
| 55 | + flex: 1; |
| 56 | + ${(props) => |
| 57 | + props.backgroundColor && `background-color: ${props.backgroundColor};`} |
| 58 | + border-radius: 0; |
| 59 | +`; |
| 60 | + |
| 61 | +const FooterInnerGrid = styled(InnerGrid)<{ |
| 62 | + showBorder: boolean; |
| 63 | + backgroundColor: string; |
| 64 | + borderColor: string; |
| 65 | +}>` |
| 66 | + border-top: ${(props) => |
| 67 | + `${props.showBorder ? 1 : 0}px solid ${props.borderColor}`}; |
| 68 | + overflow: visible; |
| 69 | + ${(props) => |
| 70 | + props.backgroundColor && `background-color: ${props.backgroundColor};`} |
| 71 | + border-radius: 0; |
| 72 | +`; |
| 73 | + |
| 74 | +export type TriContainerProps = TriContainerViewProps & { |
| 75 | + hintPlaceholder?: ReactNode; |
| 76 | + text: { |
| 77 | + value: string; |
| 78 | + }; |
| 79 | + type: string; |
| 80 | + float: string; |
| 81 | + width: string; |
| 82 | +}; |
| 83 | + |
| 84 | +export function TriContainer(props: TriContainerProps) { |
| 85 | + const { container, text } = props; |
| 86 | + const { showHeader, showFooter } = container; |
| 87 | + // When the header and footer are not displayed, the body must be displayed |
| 88 | + const showBody = container.showBody || (!showHeader && !showFooter); |
| 89 | + |
| 90 | + const { items: headerItems, ...otherHeaderProps } = container.header; |
| 91 | + const { items: bodyItems, ...otherBodyProps } = |
| 92 | + container.body["0"].children.view.getView(); |
| 93 | + const { items: footerItems, ...otherFooterProps } = container.footer; |
| 94 | + const { style } = container; |
| 95 | + |
| 96 | + const editorState = useContext(EditorContext); |
| 97 | + const maxWidth = editorState.getAppSettings().maxWidth; |
| 98 | + const isMobile = checkIsMobile(maxWidth); |
| 99 | + const paddingWidth = isMobile ? 7 : 19; |
| 100 | + |
| 101 | + return ( |
| 102 | + <Wrapper $style={style}> |
| 103 | + {showHeader && ( |
| 104 | + <BackgroundColorContext.Provider |
| 105 | + value={container.style.background} |
| 106 | + > |
| 107 | + <HeaderInnerGrid |
| 108 | + {...otherHeaderProps} |
| 109 | + items={gridItemCompToGridItems(headerItems)} |
| 110 | + autoHeight={true} |
| 111 | + emptyRows={5} |
| 112 | + minHeight="46px" |
| 113 | + containerPadding={[paddingWidth, 3]} |
| 114 | + showName={{ bottom: showBody || showFooter ? 20 : 0 }} |
| 115 | + backgroundColor={style?.background} |
| 116 | + /> |
| 117 | + </BackgroundColorContext.Provider> |
| 118 | + )} |
| 119 | + {showBody && ( |
| 120 | + <BackgroundColorContext.Provider value={container.style.background}> |
| 121 | + <div |
| 122 | + style={{ |
| 123 | + overflowY: "scroll", |
| 124 | + background: `${container.style.background}`, |
| 125 | + }} |
| 126 | + > |
| 127 | + <BodyInnerGrid |
| 128 | + showBorder={showHeader} |
| 129 | + {...otherBodyProps} |
| 130 | + items={gridItemCompToGridItems(bodyItems)} |
| 131 | + autoHeight={container.autoHeight} |
| 132 | + emptyRows={14} |
| 133 | + minHeight={showHeader ? "143px" : "142px"} |
| 134 | + containerPadding={ |
| 135 | + (showHeader && showFooter) || showHeader |
| 136 | + ? [paddingWidth, 11.5] |
| 137 | + : [paddingWidth, 11] |
| 138 | + } |
| 139 | + hintPlaceholder={props.hintPlaceholder ?? HintPlaceHolder} |
| 140 | + backgroundColor={style?.background} |
| 141 | + borderColor={style?.border} |
| 142 | + style={{ |
| 143 | + float: `${props.float}`, |
| 144 | + width: `${props.float === "none" ? "100%" : `${props.width}%`}`, |
| 145 | + height: "100%", |
| 146 | + }} |
| 147 | + /> |
| 148 | + <p style={{ textAlign: "justify", margin: "20px 30px" }}> |
| 149 | + {props.type === "markdown" ? ( |
| 150 | + <TacoMarkDown>{text.value}</TacoMarkDown> |
| 151 | + ) : ( |
| 152 | + text.value |
| 153 | + )} |
| 154 | + </p> |
| 155 | + </div> |
| 156 | + </BackgroundColorContext.Provider> |
| 157 | + )} |
| 158 | + {showFooter && ( |
| 159 | + <BackgroundColorContext.Provider |
| 160 | + value={container.style.background} |
| 161 | + > |
| 162 | + <FooterInnerGrid |
| 163 | + showBorder={showHeader || showBody} |
| 164 | + {...otherFooterProps} |
| 165 | + items={gridItemCompToGridItems(footerItems)} |
| 166 | + autoHeight={true} |
| 167 | + emptyRows={5} |
| 168 | + minHeight={showBody ? "47px" : "46px"} |
| 169 | + containerPadding={ |
| 170 | + showBody || showHeader ? [paddingWidth, 3.5] : [paddingWidth, 3] |
| 171 | + } |
| 172 | + showName={{ top: showHeader || showBody ? 20 : 0 }} |
| 173 | + backgroundColor={style?.background} |
| 174 | + borderColor={style?.border} |
| 175 | + /> |
| 176 | + </BackgroundColorContext.Provider> |
| 177 | + )} |
| 178 | + </Wrapper> |
| 179 | + ); |
| 180 | +} |
0 commit comments