Skip to content

Commit 7d3e326

Browse files
authored
Merge pull request #949 from lowcoder-org/fix/column-layout-comp-height
Fix/ColumnLayoutComp layout issues
2 parents 085a33c + 080c631 commit 7d3e326

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

client/packages/lowcoder/src/comps/comps/columnLayout/columnLayout.tsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,20 @@ import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUt
4242
import { DisabledContext } from "comps/generators/uiCompBuilder";
4343

4444
const ContainWrapper = styled.div<{
45-
$style: ContainerStyleType | undefined;
45+
$style: ContainerStyleType & {
46+
display: string,
47+
gridTemplateColumns: string,
48+
columnGap: string,
49+
gridTemplateRows: string,
50+
rowGap: string,
51+
} | undefined;
4652
}>`
53+
display: ${(props) => props.$style?.display};
54+
grid-template-columns: ${(props) => props.$style?.gridTemplateColumns};
55+
grid-template-rows: ${(props) => props.$style?.gridTemplateRows};
56+
column-gap: ${(props) => props.$style?.columnGap};
57+
row-gap: ${(props) => props.$style?.rowGap};
58+
4759
background-color: ${(props) => props.$style?.background} !important;
4860
border-radius: ${(props) => props.$style?.radius};
4961
border-width: ${(props) => props.$style?.borderWidth};
@@ -59,7 +71,7 @@ const ColWrapper = styled(Col)<{
5971
$matchColumnsHeight: boolean,
6072
}>`
6173
> div {
62-
height: ${(props) => props.$matchColumnsHeight ? '100%' : 'auto'};
74+
height: ${(props) => props.$matchColumnsHeight ? `calc(100% - ${props.$style?.padding || 0} - ${props.$style?.padding || 0})` : 'auto'};
6375
background-color: ${(props) => props.$style?.background} !important;
6476
border-radius: ${(props) => props.$style?.radius};
6577
border-width: ${(props) => props.$style?.borderWidth};
@@ -121,17 +133,24 @@ const ColumnLayout = (props: ColumnLayoutProps) => {
121133
} = props;
122134

123135
return (
124-
<BackgroundColorContext.Provider value={"none"}>
136+
<BackgroundColorContext.Provider value={props.style.background}>
125137
<DisabledContext.Provider value={props.disabled}>
126-
<ContainWrapper $style={props.style}>
127-
<div style={{display: "grid", gridTemplateColumns: templateColumns, columnGap, gridTemplateRows: templateRows, rowGap}}>
128-
{columns.map(column => {
129-
const id = String(column.id);
130-
const childDispatch = wrapDispatch(wrapDispatch(dispatch, "containers"), id);
131-
if(!containers[id]) return null
132-
const containerProps = containers[id].children;
133-
const noOfColumns = columns.length;
134-
return (
138+
<ContainWrapper $style={{
139+
...props.style,
140+
display: "grid",
141+
gridTemplateColumns: templateColumns,
142+
columnGap,
143+
gridTemplateRows: templateRows,
144+
rowGap,
145+
}}>
146+
{columns.map(column => {
147+
const id = String(column.id);
148+
const childDispatch = wrapDispatch(wrapDispatch(dispatch, "containers"), id);
149+
if(!containers[id]) return null
150+
const containerProps = containers[id].children;
151+
const noOfColumns = columns.length;
152+
return (
153+
<BackgroundColorContext.Provider value={props.columnStyle.background}>
135154
<ColWrapper
136155
key={id}
137156
$style={props.columnStyle}
@@ -147,12 +166,12 @@ const ColumnLayout = (props: ColumnLayoutProps) => {
147166
style={columnStyle}
148167
/>
149168
</ColWrapper>
150-
)
151-
})
152-
}
153-
</div>
169+
</BackgroundColorContext.Provider>
170+
)
171+
})
172+
}
154173
</ContainWrapper>
155-
</DisabledContext.Provider>
174+
</DisabledContext.Provider>
156175
</BackgroundColorContext.Provider>
157176
);
158177
};

client/packages/lowcoder/src/layout/gridItem.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,12 @@ export function GridItem(props: GridItemProps) {
441441
cssTransforms: true,
442442
}),
443443
style: {
444-
...setTransform(pos,props.name),
444+
...setTransform(
445+
pos,
446+
props.name,
447+
props.autoHeight,
448+
Boolean(draggingUtils.isDragging())
449+
),
445450
opacity: layoutHide ? 0 : undefined,
446451
pointerEvents: layoutHide ? "none" : "auto",
447452
},

client/packages/lowcoder/src/layout/utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,21 @@ export function getStatics(layout: Layout): Layout {
199199
return _.pickBy(layout, (l) => l.static);
200200
}
201201

202-
export function setTransform({ top, left, width, height }: Position,name?:string): Record<string, any> {
202+
export function setTransform(
203+
{top, left, width, height }: Position,
204+
name ?: string,
205+
autoHeight?: boolean,
206+
isDragging?: boolean,
207+
): Record<string, any> {
203208
// Replace unitless items with px
204209
const translate = `translate(${left}px,${top}px)`;
205210
function containsChart(str:string) {
206211
return /chart/i.test(str);
207212
}
213+
let updatedHeight = 'auto';
214+
if (isDragging || !autoHeight || (name && containsChart(name))) {
215+
updatedHeight = `${height}px`;
216+
}
208217

209218
return {
210219
transform: translate,
@@ -213,7 +222,7 @@ export function setTransform({ top, left, width, height }: Position,name?:string
213222
msTransform: translate,
214223
OTransform: translate,
215224
width: `${width}px`,
216-
height: name ?containsChart(name)?`${height}px`:'auto':`${height}px`,
225+
height: updatedHeight,
217226
position: 'absolute',
218227
};
219228
}

0 commit comments

Comments
 (0)