Skip to content

Commit 7caae84

Browse files
moushengludomikula
authored andcommitted
fix_widthCalculator_and_heightCalculator
1 parent 5dc46c0 commit 7caae84

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -959,45 +959,42 @@ export type ResponsiveLayoutRowStyleType = StyleConfigType<typeof ResponsiveLayo
959959
export type ResponsiveLayoutColStyleType = StyleConfigType<typeof ResponsiveLayoutColStyle>;
960960

961961
export function widthCalculator(margin: string) {
962-
const marginArr = margin?.trim().split(" ") || "";
962+
const marginArr = margin?.trim().replace(/\s+/g,' ').split(" ") || "";
963963
if (marginArr.length === 1) {
964964
return `calc(100% - ${
965-
parseInt(margin.replace(/[^\d.]/g, "")) * 2 + margin.replace(/[0-9]/g, "")
965+
parseInt(margin.replace(/[^\d.]/g, "")) * 2 +
966+
(margin.replace(/[0-9]/g, "") || "px")
966967
})`;
967968
} else if (marginArr.length === 2 || marginArr.length === 3) {
968969
return `calc(100% - ${
969970
parseInt(marginArr[1].replace(/[^\d.]/g, "")) * 2 +
970-
marginArr[1].replace(/[0-9]/g, "")
971+
(marginArr[1].replace(/[0-9]/g, "") || 'px')
971972
})`;
972973
} else {
973974
return `calc(100% - ${
974975
parseInt(marginArr[1]?.replace(/[^\d.]/g, "") || "0") +
975-
marginArr[1]?.replace(/[0-9]/g, "" || "px")
976+
(marginArr[1]?.replace(/[0-9]/g, "") || "px")
976977
} - ${
977978
parseInt(marginArr[3]?.replace(/[^\d.]/g, "") || "0") +
978-
marginArr[3]?.replace(/[0-9]/g, "" || "px")
979+
(marginArr[3]?.replace(/[0-9]/g, "") || "px")
979980
})`;
980981
}
981982
}
982983

983984
export function heightCalculator(margin: string) {
984985
const marginArr = margin?.trim().split(" ") || "";
985-
if (marginArr.length === 1) {
986-
return `calc(100% - ${
987-
parseInt(margin.replace(/[^\d.]/g, "")) * 2 + margin.replace(/[0-9]/g, "")
988-
})`;
989-
} else if (marginArr.length === 2) {
986+
if (marginArr.length === 1 || marginArr.length === 2) {
990987
return `calc(100% - ${
991-
parseInt(marginArr[0].replace(/[^\d.]/g, "")) * 2 +
992-
marginArr[0].replace(/[0-9]/g, "")
988+
parseInt(marginArr[0].replace(/[^\d.]/g, "")) * 2 +
989+
(marginArr[0].replace(/[0-9]/g, "") || 'px')
993990
})`;
994-
} else {
991+
}else if(marginArr.length >2){
995992
return `calc(100% - ${
996993
parseInt(marginArr[0]?.replace(/[^\d.]/g, "") || "0") +
997-
marginArr[0]?.replace(/[0-9]/g, "") || "px"
994+
(marginArr[0]?.replace(/[0-9]/g, "") || "px")
998995
} - ${
999996
parseInt(marginArr[2]?.replace(/[^\d.]/g, "") || "0") +
1000-
marginArr[2]?.replace(/[0-9]/g, "") || "px"
997+
(marginArr[2]?.replace(/[0-9]/g, "") || "px")
1001998
})`;
1002999
}
10031000
}

0 commit comments

Comments
 (0)