jungvonmatt / wekit

A Jamstack kit for Contentful, Hugo and Netlify.
https://www.wekit.dev
MIT License
14 stars 4 forks source link

Feature: Responsive media component #45

Open peterschewe opened 2 years ago

peterschewe commented 2 years ago

This PR merges all media components (c-image, c-video, c-media) into a new component c-responsive-media.

Todos

TBD

New component: Responsive media

The component simplifies the handling of images and short loop videos, which can be used in the hero or media module, for example.

The name (c-responsive-media instead of c-media) is also a clearer distinction from the module m-media.

Features

Contentful

image

Markup (simplified)

<!-- Example 1: Mobile image; desktop video; different ratios; image without lazy loading (for use above the fold) -->
<figure>
  <picture>
    <source srcset="poster-desktop.jpg" media="(min-width: 768px)" width="1920" height="1080">
    <source srcset="image-mobile.jpg" media="(max-width: 767px)" width="768" height="768">
    <img src="image-mobile.jpg" alt="Lorem ipsum" decoding="auto" fetchpriority="high">
  </picture>
  <video class="-md:u-hidden" poster="transparent data/base64 image">
    <source data-src="video-desktop.mp4" type="video/mp4">
  </video>
</figure> 

<!-- Example 2: Mobile video; desktop video; different sizes; image with lazy loading -->
<figure>
  <picture>
    <source srcset="poster-desktop.jpg" media="(min-width: 768px)" width="1920" height="1080">
    <source srcset="poster-mobile.jpg" media="(max-width: 767px)" width="768" height="432">
    <img src="poster-mobile.jpg" alt="Lorem ipsum" decoding="auto" loading="lazy">
  </picture>
  <video class="-md:u-hidden" poster="transparent data/base64 image">
    <source data-src="video-desktop.mp4" type="video/mp4">
  </video>
  <video class="md:u-hidden" poster="transparent data/base64 image">
    <source data-src="video-mobile.mp4" type="video/mp4">
  </video>
</figure> 

<!-- Example 3: Mobile image; desktop image; different ratios; image with lazy loading -->
<figure>
  <picture>
    <source srcset="image-desktop.jpg" media="(min-width: 768px)" width="1920" height="1080">
    <source srcset="image-mobile.jpg" media="(max-width: 767px)" width="768" height="768">
    <img src="image-mobile.jpg" alt="Lorem ipsum" decoding="auto" loading="lazy">
  </picture>
</figure> 
dlemm commented 2 years ago

For the TBD

Caption: Where do we like to use a caption? c-responsive-media vs. m-media

In my opinion it should be placed inside the c-responsive-media since the caption barely changes. So if you use the component somewhere else, would there be another caption?

And another suggestion is that we might need a desktop and a mobile caption since it is possible to maintain two different things now.

peterschewe commented 2 years ago

For the TBD

Caption: Where do we like to use a caption? c-responsive-media vs. m-media

In my opinion it should be placed inside the c-responsive-media since the caption barely changes. So if you use the component somewhere else, would there be another caption?

Yes, that is a good point. I can only see a disadvantage if the caption is not directly aligned with the media. For example, the media could be fullscreen and the caption could remain in the content grid. This is also possible in the component. But maybe it's more difficult if it's already in a grid (of the module). The case can probably be ignored...

And another suggestion is that we might need a desktop and a mobile caption since it is possible to maintain two different things now.

I would consider the responsive media as a unit. It is meant to be displayed differently, but the purpose of the content is the same. We also use only one alt text for both media.

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
10.8% 10.8% Duplication

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
10.8% 10.8% Duplication