Skip to content

Commit

Permalink
feat(cms-base): Improve CmsElementImage (#445)
Browse files Browse the repository at this point in the history
* fix(cms-base): add missing attributes to CmsElementImage
* feat(cms-base): add html video support
---------

Co-authored-by: Marc Peternell <[email protected]>
  • Loading branch information
BrocksiNet and Marc Peternell authored Oct 30, 2023
1 parent c5c13c9 commit c264bf5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/popular-spies-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@shopware-pwa/composables-next": minor
"@shopware-pwa/cms-base": minor
---

Adding the missing srcset attribute to the image tag in the CmsElementImage component. as well as adding support for HTML video elements as in Shopware management, it is possible for users to associate videos to any Cms image element.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const {
imageContainerAttrs,
imageAttrs,
imageLink,
isVideoElement,
mimeType,
} = useCmsElementImage(props.content);
const DEFAULT_THUMBNAIL_SIZE = 10;
Expand Down Expand Up @@ -51,16 +53,30 @@ const imageComputedContainerAttrs = computed(() => {
:style="containerStyle"
v-bind="imageComputedContainerAttrs"
>
<video
v-if="isVideoElement"
controls
:class="{
'h-full w-full': true,
'absolute inset-0': ['cover', 'stretch'].includes(displayMode),
'object-cover': displayMode === 'cover',
}"
>
<source :src="imageAttrs.src" :type="mimeType" />
Your browser does not support the video tag.
</video>
<img
v-else
ref="imageElement"
loading="lazy"
:class="{
'h-full w-full': true,
'absolute inset-0': ['cover', 'stretch'].includes(displayMode),
'object-cover': displayMode === 'cover',
}"
alt="Image link"
:alt="imageAttrs.alt"
:src="srcPath"
:srcset="imageAttrs.srcset"
/>
</component>
</template>
12 changes: 12 additions & 0 deletions packages/composables/src/cms/useCmsElementImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type UseCmsElementImage = {
imageContainerAttrs: ComputedRef<ImageContainerAttrs>;
imageLink: ComputedRef<{ newTab: boolean; url: string }>;
displayMode: ComputedRef<DisplayMode>;
isVideoElement: ComputedRef<boolean>;
mimeType: ComputedRef<string>;
};

/**
Expand Down Expand Up @@ -77,12 +79,22 @@ export function useCmsElementImage(
() => getConfigValue("displayMode") || "initial",
);

const isVideoElement = computed(() => {
return !!element.data?.media?.mimeType?.includes("video");
});

const mimeType = computed(() => {
return element.data?.media?.mimeType;
});

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

2 comments on commit c264bf5

@vercel
Copy link

@vercel vercel bot commented on c264bf5 Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo.vercel.app
frontends-demo-git-main-shopware-frontends.vercel.app
frontends-demo-shopware-frontends.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c264bf5 Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.