-
Notifications
You must be signed in to change notification settings - Fork 34
Dynamic data attribute for self hosted video, remove wrapper #16322
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -319,6 +319,7 @@ type Props = { | |
| isExternalLink: boolean; | ||
| }; | ||
| isInLoopClickTestVariant?: boolean; | ||
| isInArticle?: boolean; | ||
| }; | ||
|
|
||
| export const SelfHostedVideo = ({ | ||
|
|
@@ -351,6 +352,7 @@ export const SelfHostedVideo = ({ | |
| restrictHeightOnDesktop = false, | ||
| cardLink, | ||
| isInLoopClickTestVariant, | ||
| isInArticle = false, | ||
| }: Props) => { | ||
| const adapted = useShouldAdapt(); | ||
| const { renderingTarget } = useConfig(); | ||
|
|
@@ -1071,13 +1073,22 @@ export const SelfHostedVideo = ({ | |
| } | ||
| } | ||
|
|
||
| const videoStyleFormat = videoStyle.toLocaleLowerCase(); | ||
|
|
||
| return ( | ||
| <figure | ||
| css={ | ||
| isInArticle | ||
| ? css` | ||
| margin-bottom: ${space[3]}px; | ||
|
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. I'm not a huge fan of adding margins to the child component, instead of the parent controlling the spacing. I think the code can end up a bit messy with this approach. I see from following the code upwards that it is not easy to add this margin to a parent container and creating a new |
||
| ` | ||
| : undefined | ||
|
Comment on lines
+1081
to
+1085
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. nit: could this style be lifted out into a const? This would be more consistet with the rest of the file and would allow for slightly more readable jsx eg |
||
| } | ||
| ref={videoContainerRef} | ||
| className={`video-container ${videoStyle.toLocaleLowerCase()} ${ | ||
| className={`video-container ${videoStyleFormat} ${ | ||
| role === 'immersive' ? 'element-video-immersive' : '' | ||
| }`} | ||
| data-component="gu-video-loop" | ||
| data-component={`gu-video-${videoStyleFormat}`} | ||
|
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. Nice spot. I would run this change by the Fronts & Curation team. I think their analytics might be relying on this name
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. I think it would be OK to update this name provided the change is run past Ophan before its merged |
||
| > | ||
| <div | ||
| ref={setNode} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| import { css } from '@emotion/react'; | ||
| import { space } from '@guardian/source/foundations'; | ||
| import type { FEAspectRatio } from '../frontend/feFront'; | ||
| import { isInteractive } from '../layouts/lib/interactiveLegacyStyling'; | ||
| import type { ArticleFormat } from '../lib/articleFormat'; | ||
|
|
@@ -13,10 +11,6 @@ import type { VideoPlayerFormat } from '../types/mainMedia'; | |
| import { Island } from './Island'; | ||
| import { SelfHostedVideo } from './SelfHostedVideo.island'; | ||
|
|
||
| const containerStyles = css` | ||
| margin-bottom: ${space[3]}px; | ||
| `; | ||
|
|
||
| type SelfHostedVideoInArticleProps = { | ||
| element: MediaAtomBlockElement; | ||
| format: ArticleFormat; | ||
|
|
@@ -49,39 +43,35 @@ export const SelfHostedVideoInArticle = ({ | |
| } | ||
|
|
||
| return ( | ||
| <div css={containerStyles} data-spacefinder-role="inline"> | ||
|
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. Are we OK to drop the |
||
| <Island priority="critical" defer={{ until: 'visible' }}> | ||
| <SelfHostedVideo | ||
| atomId={element.id} | ||
| fallbackImage={posterImageUrl} | ||
| fallbackImageAlt={caption} | ||
| fallbackImageAspectRatio={ | ||
| (firstVideoSource?.aspectRatio ?? | ||
| '5:4') as FEAspectRatio | ||
| } | ||
| fallbackImageLoading="lazy" | ||
| fallbackImageSize="small" | ||
| aspectRatio={aspectRatio} | ||
| linkTo="Article-embed-MediaAtomBlockElement" | ||
| posterImage={posterImageUrl} | ||
| posterImageAspectRatio={ | ||
| firstVideoSource?.aspectRatio ?? '5:4' | ||
| } | ||
| sources={sources} | ||
| subtitleSize="medium" | ||
| subtitleSource={getSubtitleAsset(element.assets)} | ||
| videoStyle={videoStyle} | ||
| uniqueId={element.id} | ||
| caption={caption} | ||
| format={format} | ||
| isMainMedia={isMainMedia} | ||
| role={role} | ||
| preventAutoplay={videoStyle === 'Default'} | ||
| restrictHeightOnDesktop={ | ||
| isVerticalVideo && !isInteractive(format.design) | ||
| } | ||
| /> | ||
| </Island> | ||
| </div> | ||
| <Island priority="critical" defer={{ until: 'visible' }}> | ||
| <SelfHostedVideo | ||
| atomId={element.id} | ||
| fallbackImage={posterImageUrl} | ||
| fallbackImageAlt={caption} | ||
| fallbackImageAspectRatio={ | ||
| (firstVideoSource?.aspectRatio ?? '5:4') as FEAspectRatio | ||
| } | ||
| fallbackImageLoading="lazy" | ||
| fallbackImageSize="small" | ||
| aspectRatio={aspectRatio} | ||
| linkTo="Article-embed-MediaAtomBlockElement" | ||
| posterImage={posterImageUrl} | ||
| posterImageAspectRatio={firstVideoSource?.aspectRatio ?? '5:4'} | ||
| sources={sources} | ||
| subtitleSize="medium" | ||
| subtitleSource={getSubtitleAsset(element.assets)} | ||
| videoStyle={videoStyle} | ||
| uniqueId={element.id} | ||
| caption={caption} | ||
| format={format} | ||
| isMainMedia={isMainMedia} | ||
| role={role} | ||
| preventAutoplay={videoStyle === 'Default'} | ||
| restrictHeightOnDesktop={ | ||
| isVerticalVideo && !isInteractive(format.design) | ||
| } | ||
| isInArticle={true} | ||
| /> | ||
| </Island> | ||
| ); | ||
| }; | ||
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.
Could this be renamed to something that describes the behaviour of this component instead of the features of the parent? It can be easier to understand how to use props and predict what they do that follow this pattern
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 agree with @domlander, perhaps
hasBottomMarginor similar?