Skip to content

Commit 6c9a0a8

Browse files
committed
chore: fix issue with previews not respecting min/max height settings
1 parent 61babca commit 6c9a0a8

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

packages/pluggableWidgets/image-web/src/Image.editorConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ export function getPreview(
202202
}
203203
if (values.heightUnit === "pixels" && values.height) {
204204
height = values.height;
205+
} else if (values.heightUnit === "auto") {
206+
// Mirror the min/max height constraints applied at runtime in constructStyleObject
207+
if (values.maxHeightUnit === "pixels" && values.maxHeight) {
208+
height = values.maxHeight;
209+
} else if (values.minHeightUnit === "pixels" && values.minHeight) {
210+
height = values.minHeight;
211+
}
205212
}
206213
if (width || height) {
207214
return [width, height, previewImage];

packages/pluggableWidgets/image-web/src/Image.editorPreview.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { parseStyle } from "@mendix/widget-plugin-platform/preview/parse-style";
21
import { WebIcon } from "mendix";
32
import { ReactElement } from "react";
3+
import { parseStyle } from "@mendix/widget-plugin-platform/preview/parse-style";
44
import { ImagePreviewProps } from "../typings/ImageProps";
5-
import { Image as ImageComponent } from "./components/Image/Image";
65

76
import ImagePlaceholder from "./assets/placeholder.svg";
7+
import { Image as ImageComponent } from "./components/Image/Image";
8+
import { constructStyleObject } from "./utils/helpers";
89

910
declare function require(name: string): string;
1011

@@ -39,10 +40,16 @@ export function preview(props: ImagePreviewProps): ReactElement | null {
3940
break;
4041
}
4142

43+
const type = props.datasource === "icon" && props.imageIcon ? props.imageIcon.type : "image";
44+
45+
const styleObject = type === "image" && constructStyleObject(props);
46+
47+
const imageStyle = { ...parseStyle(props.style), ...styleObject };
48+
4249
return (
4350
<ImageComponent
44-
class={props.className}
45-
style={parseStyle(props.style)}
51+
class={props.class}
52+
style={imageStyle}
4653
widthUnit={props.widthUnit}
4754
width={props.width ?? 100}
4855
heightUnit={props.heightUnit}
@@ -51,7 +58,7 @@ export function preview(props: ImagePreviewProps): ReactElement | null {
5158
responsive={props.responsive}
5259
onClickType={props.onClickType}
5360
onClick={undefined}
54-
type={props.datasource === "icon" && props.imageIcon ? props.imageIcon.type : "image"}
61+
type={type}
5562
image={image}
5663
displayAs={props.displayAs}
5764
renderAsBackground={props.datasource !== "icon" && props.isBackgroundImage}

packages/pluggableWidgets/image-web/src/utils/helpers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { CSSProperties } from "react";
2-
import { ImageContainerProps } from "typings/ImageProps";
2+
import { ImageContainerProps, ImagePreviewProps } from "typings/ImageProps";
33

44
function getHeightScale(height: number, heightUnit: "pixels" | "percentage" | "viewport"): string {
55
return `${height}${heightUnit === "pixels" ? "px" : heightUnit === "viewport" ? "vh" : "%"}`;
66
}
77

8-
export function constructStyleObject(props: ImageContainerProps): CSSProperties {
8+
export function constructStyleObject(props: ImageContainerProps | ImagePreviewProps): CSSProperties {
99
const { widthUnit, heightUnit, minHeightUnit, maxHeightUnit, width, height, minHeight, maxHeight } = props;
1010

1111
const imageStyle: Pick<CSSProperties, "width" | "height" | "minHeight" | "maxHeight" | "maxWidth"> = {};
@@ -14,15 +14,15 @@ export function constructStyleObject(props: ImageContainerProps): CSSProperties
1414
if (heightUnit === "auto") {
1515
imageStyle.height = "auto";
1616

17-
if (minHeightUnit !== "none" && minHeight > 0) {
18-
imageStyle.minHeight = getHeightScale(minHeight, minHeightUnit);
17+
if (minHeightUnit !== "none" && minHeight! > 0) {
18+
imageStyle.minHeight = getHeightScale(minHeight!, minHeightUnit);
1919
}
2020

21-
if (maxHeightUnit !== "none" && maxHeight > 0) {
22-
imageStyle.maxHeight = getHeightScale(maxHeight, maxHeightUnit);
21+
if (maxHeightUnit !== "none" && maxHeight! > 0) {
22+
imageStyle.maxHeight = getHeightScale(maxHeight!, maxHeightUnit);
2323
}
2424
} else {
25-
imageStyle.height = getHeightScale(height, heightUnit);
25+
imageStyle.height = getHeightScale(height!, heightUnit);
2626
}
2727

2828
return imageStyle;

0 commit comments

Comments
 (0)