Skip to content

Commit 251f234

Browse files
yordan-stgjulivan
authored andcommitted
feat: enhance image properties with min/max height and new units
1 parent e1a72b8 commit 251f234

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@ export function getProperties(
7272
hidePropertyIn(defaultProperties, values, "defaultImageDynamic");
7373
}
7474

75-
if (values.heightUnit === "auto") {
75+
if (values.widthUnit === "auto") {
76+
hidePropertyIn(defaultProperties, values, "width");
77+
}
78+
79+
if (values.heightUnit !== "auto") {
80+
hidePropertiesIn(defaultProperties, values, ["minHeightUnit", "maxHeightUnit", "minHeight", "maxHeight"]);
81+
} else {
7682
hidePropertyIn(defaultProperties, values, "height");
7783
}
7884

79-
if (values.widthUnit === "auto") {
80-
hidePropertyIn(defaultProperties, values, "width");
85+
if (values.minHeightUnit === "none") {
86+
hidePropertyIn(defaultProperties, values, "minHeight");
87+
}
88+
89+
if (values.maxHeightUnit === "none") {
90+
hidePropertyIn(defaultProperties, values, "maxHeight");
8191
}
8292

8393
if (values.datasource === "icon" && (values.imageIcon?.type === "glyph" || values.imageIcon?.type === "icon")) {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ValueStatus } from "mendix";
22
import { createElement, FunctionComponent, useCallback } from "react";
33
import { ImageContainerProps } from "../typings/ImageProps";
44
import { Image as ImageComponent, ImageType } from "./components/Image/Image";
5+
import { constructStyleObject } from "./utils/helpers";
56

67
function getImageProps({
78
datasource,
@@ -60,11 +61,22 @@ export const Image: FunctionComponent<ImageContainerProps> = props => {
6061
const { type, image } = getImageProps(props);
6162

6263
const altText = props.alternativeText?.status === ValueStatus.Available ? props.alternativeText.value : undefined;
64+
const styleObject = constructStyleObject(props);
65+
66+
const imageStyle = { ...props.style, ...styleObject };
67+
console.warn("Image styling debug:", {
68+
name: props.name,
69+
heightUnit: props.heightUnit,
70+
minHeightUnit: props.minHeightUnit,
71+
minHeight: props.minHeight,
72+
styleObject,
73+
finalImageStyle: imageStyle
74+
});
6375

6476
return (
6577
<ImageComponent
6678
class={props.class}
67-
style={props.style}
79+
style={imageStyle}
6880
widthUnit={props.widthUnit}
6981
width={props.width}
7082
heightUnit={props.heightUnit}

packages/pluggableWidgets/image-web/src/Image.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,42 @@
8888
<enumerationValues>
8989
<enumerationValue key="auto">Auto</enumerationValue>
9090
<enumerationValue key="pixels">Pixels</enumerationValue>
91+
<enumerationValue key="percentage">Percentage</enumerationValue>
92+
<enumerationValue key="viewport">Viewport</enumerationValue>
9193
</enumerationValues>
9294
</property>
9395
<property key="height" type="integer" defaultValue="100">
9496
<caption>Height</caption>
9597
<description />
9698
</property>
99+
<property key="minHeightUnit" type="enumeration" defaultValue="none">
100+
<caption>Minimum Height unit</caption>
101+
<description />
102+
<enumerationValues>
103+
<enumerationValue key="none">None</enumerationValue>
104+
<enumerationValue key="pixels">Pixels</enumerationValue>
105+
<enumerationValue key="percentage">Percentage</enumerationValue>
106+
<enumerationValue key="viewport">Viewport</enumerationValue>
107+
</enumerationValues>
108+
</property>
109+
<property key="minHeight" type="integer" required="true" defaultValue="0">
110+
<caption>Minimum height</caption>
111+
<description />
112+
</property>
113+
<property key="maxHeightUnit" type="enumeration" defaultValue="none">
114+
<caption>Maximum Height unit</caption>
115+
<description />
116+
<enumerationValues>
117+
<enumerationValue key="none">None</enumerationValue>
118+
<enumerationValue key="pixels">Pixels</enumerationValue>
119+
<enumerationValue key="percentage">Percentage</enumerationValue>
120+
<enumerationValue key="viewport">Viewport</enumerationValue>
121+
</enumerationValues>
122+
</property>
123+
<property key="maxHeight" type="integer" required="true" defaultValue="0">
124+
<caption>Maximum height</caption>
125+
<description />
126+
</property>
97127
<property key="iconSize" type="integer" defaultValue="14">
98128
<caption>Icon size</caption>
99129
<description>The size of the icon in pixels.</description>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { CSSProperties } from "react";
2+
import { ImageContainerProps } from "typings/ImageProps";
3+
4+
function getHeightScale(height: number, heightUnit: "pixels" | "percentage" | "viewport"): string {
5+
return `${height}${heightUnit === "pixels" ? "px" : heightUnit === "viewport" ? "vh" : "%"}`;
6+
}
7+
8+
export function constructStyleObject(props: ImageContainerProps): CSSProperties {
9+
const { widthUnit, heightUnit, minHeightUnit, maxHeightUnit, width, height, minHeight, maxHeight } = props;
10+
11+
const imageStyle: Pick<CSSProperties, "width" | "height" | "minHeight" | "maxHeight" | "maxWidth"> = {};
12+
13+
imageStyle.width = `${width}${widthUnit === "pixels" ? "px" : "%"}`;
14+
if (heightUnit === "auto") {
15+
imageStyle.height = "auto";
16+
17+
if (minHeightUnit !== "none" && minHeight > 0) {
18+
console.warn(minHeight);
19+
imageStyle.minHeight = getHeightScale(minHeight, minHeightUnit);
20+
}
21+
22+
if (maxHeightUnit !== "none" && maxHeight > 0) {
23+
imageStyle.maxHeight = getHeightScale(maxHeight, maxHeightUnit);
24+
}
25+
} else {
26+
imageStyle.height = getHeightScale(height, heightUnit);
27+
}
28+
29+
return imageStyle;
30+
}

packages/pluggableWidgets/image-web/typings/ImageProps.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export type OnClickTypeEnum = "action" | "enlarge";
1212

1313
export type WidthUnitEnum = "auto" | "pixels" | "percentage";
1414

15-
export type HeightUnitEnum = "auto" | "pixels";
15+
export type HeightUnitEnum = "auto" | "pixels" | "percentage" | "viewport";
16+
17+
export type MinHeightUnitEnum = "none" | "pixels" | "percentage" | "viewport";
18+
19+
export type MaxHeightUnitEnum = "none" | "pixels" | "percentage" | "viewport";
1620

1721
export type DisplayAsEnum = "fullImage" | "thumbnail";
1822

@@ -35,6 +39,10 @@ export interface ImageContainerProps {
3539
width: number;
3640
heightUnit: HeightUnitEnum;
3741
height: number;
42+
minHeightUnit: MinHeightUnitEnum;
43+
minHeight: number;
44+
maxHeightUnit: MaxHeightUnitEnum;
45+
maxHeight: number;
3846
iconSize: number;
3947
displayAs: DisplayAsEnum;
4048
responsive: boolean;
@@ -65,6 +73,10 @@ export interface ImagePreviewProps {
6573
width: number | null;
6674
heightUnit: HeightUnitEnum;
6775
height: number | null;
76+
minHeightUnit: MinHeightUnitEnum;
77+
minHeight: number | null;
78+
maxHeightUnit: MaxHeightUnitEnum;
79+
maxHeight: number | null;
6880
iconSize: number | null;
6981
displayAs: DisplayAsEnum;
7082
responsive: boolean;

0 commit comments

Comments
 (0)