Skip to content

Commit

Permalink
fix: min-height display behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
divide29 committed Jan 10, 2025
1 parent cb816e2 commit feb9b50
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-llamas-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-pwa/composables-next": patch
---

fix: min-height display behaviour
21 changes: 20 additions & 1 deletion packages/composables/src/cms/useCmsElementImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { useCmsElementImage } from "./useCmsElementImage";
describe("useCmsElementImage", () => {
describe("computed", () => {
describe("containerStyle", () => {
it("should return minHeight css property", () => {
it("should return minHeight css property when displayMode is cover", () => {
const { containerStyle } = useCmsElementImage({
config: {
displayMode: {
value: "cover",
},
minHeight: {
value: "100px",
},
Expand All @@ -16,6 +19,22 @@ describe("useCmsElementImage", () => {

expect(containerStyle.value).toEqual({ minHeight: "100px" });
});

it("should not return minHeight css property when displayMode is not cover", () => {
const { containerStyle } = useCmsElementImage({
config: {
displayMode: {
value: "contain",
},
minHeight: {
value: "100px",
},
},
} as CmsElementImage);

expect(containerStyle.value).toEqual({});
});

it("should return anchorAttrs", () => {
const { anchorAttrs } = useCmsElementImage({
config: {
Expand Down
16 changes: 10 additions & 6 deletions packages/composables/src/cms/useCmsElementImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ export function useCmsElementImage(
): UseCmsElementImage {
const { getConfigValue } = useCmsElementConfig(element);

const displayMode = computed(
() => getConfigValue("displayMode") || "initial",
);

const minHeight = computed(() =>
displayMode.value === "cover" ? getConfigValue("minHeight") : undefined,
);

const containerStyle: ComputedRef<CSSProperties> = computed(() => ({
minHeight: getConfigValue("minHeight"),
...(minHeight.value !== undefined && { minHeight: minHeight.value }),
}));

const anchorAttrs = computed(() => ({
Expand Down Expand Up @@ -78,10 +86,6 @@ export function useCmsElementImage(
srcset: getSrcSetForMedia(element.data?.media),
}));

const displayMode = computed(
() => getConfigValue("displayMode") || "initial",
);

const isVideoElement = computed(() => {
return !!element.data?.media?.mimeType?.includes("video");
});
Expand All @@ -91,12 +95,12 @@ export function useCmsElementImage(
});

return {
displayMode,
containerStyle,
anchorAttrs,
imageAttrs,
imageContainerAttrs,
imageLink,
displayMode,
isVideoElement,
mimeType,
};
Expand Down

0 comments on commit feb9b50

Please sign in to comment.