-
Notifications
You must be signed in to change notification settings - Fork 30
Support full-width looping videos in articles #15056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,20 +55,23 @@ const videoContainerStyles = ( | |
| } | ||
| `; | ||
|
|
||
| const figureStyles = (aspectRatio: number) => css` | ||
| const figureStyles = (aspectRatio: number, letterboxed: boolean) => css` | ||
| position: relative; | ||
| aspect-ratio: ${aspectRatio}; | ||
| height: 100%; | ||
| max-height: 100vh; | ||
| max-height: 100svh; | ||
| max-width: 100%; | ||
| ${from.tablet} { | ||
| /** | ||
| * The value "80" is derived from the aspect ratio of the 5:4 slot. | ||
| * When other slots are used for self-hosted videos, this will need to be adjusted. | ||
| */ | ||
| max-width: ${aspectRatio * 80}%; | ||
| } | ||
| ${letterboxed && | ||
| css` | ||
| max-height: 100vh; | ||
| max-height: 100svh; | ||
| max-width: 100%; | ||
|
Comment on lines
+64
to
+66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these three lines of CSS not useful for video on articles?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requirement was that looping videos should take up the full width of an article, regardless of their aspect ratio. If you introduce a
Source: https://viewer.code.dev-gutools.co.uk/preview/music/2025/dec/17/simon-looping-video-test In reality this is an edge case and will probably never happen but that's what motivated me to make this change.
|
||
| ${from.tablet} { | ||
| /** | ||
| * The value "80" is derived from the aspect ratio of the 5:4 slot. | ||
| * When other slots are used for self-hosted videos, this will need to be adjusted. | ||
| */ | ||
| max-width: ${aspectRatio * 80}%; | ||
| } | ||
| `} | ||
| `; | ||
|
|
||
| /** | ||
|
|
@@ -150,6 +153,7 @@ type Props = { | |
| subtitleSource?: string; | ||
| subtitleSize: SubtitleSize; | ||
| enableHls: boolean; | ||
| letterboxed?: boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. I appreciate it isn't a standard or obvious term though and I'm open to changing it if you have any ideas? I originally went with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My fault for choosing the term itself (and, in our case, more correct would be, even more obscure, pillarbox). But while I don’t care for the term much, I think the reasoning behind my earlier comment still stands? (whatever works, ofc, though!)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning is solid. The name is obscure but perhaps just a comment explaining it would clear things up? |
||
| }; | ||
|
|
||
| export const SelfHostedVideo = ({ | ||
|
|
@@ -170,6 +174,7 @@ export const SelfHostedVideo = ({ | |
| subtitleSource, | ||
| subtitleSize, | ||
| enableHls, | ||
| letterboxed = false, | ||
| }: Props) => { | ||
| const adapted = useShouldAdapt(); | ||
| const { renderingTarget } = useConfig(); | ||
|
|
@@ -703,7 +708,7 @@ export const SelfHostedVideo = ({ | |
| > | ||
| <figure | ||
| ref={setNode} | ||
| css={figureStyles(aspectRatio)} | ||
| css={figureStyles(aspectRatio, letterboxed)} | ||
| className={`video-container ${videoStyle.toLocaleLowerCase()}`} | ||
| data-component="gu-video-loop" | ||
| > | ||
|
|
@@ -737,6 +742,7 @@ export const SelfHostedVideo = ({ | |
| subtitleSize={subtitleSize} | ||
| activeCue={activeCue} | ||
| enableHls={enableHls} | ||
| letterboxed={letterboxed} | ||
| /> | ||
| </figure> | ||
| </div> | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why we're touching the Fronts card here? Is calculating the aspect ratio from the video itself not enough?
Another thought - what happened with the rumours that people were looking to add an aspect ratio attribute to media atoms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair question, I've bundled together 2 distinct changes in this PR which is causing confusion. It probably should have been 2 PRs.
The first change uses the aspect ratio of the video to calculate the size of the video container for the purposes of reducing CLS. It has no impact on whether or not the video displays letterboxes. It just follows on from this PR where it was missed: #15029
The second change introduces the concept of letterboxes which can be enabled or disabled. Since the default state is to disable letterboxes (see Mat's comment), we need to change the Fronts card to enable them again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand you correctly, such a field exists now. But it's a string (e.g. "5:4") and we need a numerical value so I opted to use the dimensions instead.