@@ -15,6 +15,7 @@ import { isMediaCard } from '../../lib/cardHelpers';
1515import { isWithinTwelveHours , secondsToDuration } from '../../lib/formatTime' ;
1616import { appendLinkNameMedia } from '../../lib/getDataLinkName' ;
1717import { getZIndex } from '../../lib/getZIndex' ;
18+ import { getOphanComponents } from '../../lib/labs' ;
1819import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount' ;
1920import { BETA_CONTAINERS } from '../../model/enhanceCollections' ;
2021import { palette } from '../../palette' ;
@@ -43,6 +44,7 @@ import { Pill } from '../Pill';
4344import { SlideshowCarousel } from '../SlideshowCarousel.importable' ;
4445import { Snap } from '../Snap' ;
4546import { SnapCssSandbox } from '../SnapCssSandbox' ;
47+ import { SponsoredContentLabel } from '../SponsoredContentLabel' ;
4648import { StarRating } from '../StarRating/StarRating' ;
4749import type { Alignment } from '../SupportingContent' ;
4850import { SupportingContent } from '../SupportingContent' ;
@@ -725,6 +727,47 @@ export const Card = ({
725727 return undefined ;
726728 } ;
727729
730+ /**
731+ * Decides which branding design to apply based on the labs redesign feature switch
732+ * Adds appropriate Ophan data attributes based on card context
733+ * Results in a clickable brand logo and sponsorship label
734+ */
735+ const getBranding = ( ) => {
736+ if ( ! branding ) return ;
737+ const getLocationPrefix = ( ) => {
738+ if ( ! onwardsSource ) {
739+ return 'front-card' ;
740+ }
741+ if ( onwardsSource === 'related-content' ) {
742+ return 'article-related-content' ;
743+ } else {
744+ return undefined ;
745+ }
746+ } ;
747+ const locationPrefix = getLocationPrefix ( ) ;
748+ const dataAttributes = locationPrefix
749+ ? getOphanComponents ( {
750+ branding,
751+ locationPrefix,
752+ } )
753+ : undefined ;
754+
755+ return showLabsRedesign ? (
756+ < SponsoredContentLabel
757+ branding = { branding }
758+ containerPalette = { containerPalette }
759+ ophanComponentLink = { dataAttributes ?. ophanComponentLink }
760+ ophanComponentName = { dataAttributes ?. ophanComponentName }
761+ />
762+ ) : (
763+ < CardBranding
764+ branding = { branding }
765+ containerPalette = { containerPalette }
766+ onwardsSource = { onwardsSource }
767+ />
768+ ) ;
769+ } ;
770+
728771 return (
729772 < CardWrapper
730773 format = { format }
@@ -1109,36 +1152,21 @@ export const Card = ({
11091152 { showPill ? (
11101153 < >
11111154 < MediaOrNewsletterPill />
1112- { format . theme === ArticleSpecial . Labs &&
1113- branding && (
1114- < CardBranding
1115- branding = { branding }
1116- onwardsSource = {
1117- onwardsSource
1118- }
1119- containerPalette = {
1120- containerPalette
1121- }
1122- />
1123- ) }
1155+ { ! showLabsRedesign &&
1156+ format . theme ===
1157+ ArticleSpecial . Labs &&
1158+ branding &&
1159+ getBranding ( ) }
11241160 </ >
11251161 ) : (
11261162 < CardFooter
11271163 format = { format }
11281164 age = { decideAge ( ) }
11291165 commentCount = { < CommentCount /> }
11301166 cardBranding = {
1131- branding ? (
1132- < CardBranding
1133- branding = { branding }
1134- onwardsSource = {
1135- onwardsSource
1136- }
1137- containerPalette = {
1138- containerPalette
1139- }
1140- />
1141- ) : undefined
1167+ ! showLabsRedesign && branding
1168+ ? getBranding ( )
1169+ : undefined
11421170 }
11431171 showLivePlayable = { showLivePlayable }
11441172 />
@@ -1187,6 +1215,7 @@ export const Card = ({
11871215 </ ContentWrapper >
11881216 </ CardLayout >
11891217
1218+ { /** This div contains content that sits "outside" of the standard card layout */ }
11901219 < div
11911220 css = {
11921221 /** We allow this area to take up more space so that cards without
@@ -1231,12 +1260,9 @@ export const Card = ({
12311260 age = { decideAge ( ) }
12321261 commentCount = { < CommentCount /> }
12331262 cardBranding = {
1234- branding ? (
1235- < CardBranding
1236- branding = { branding }
1237- onwardsSource = { onwardsSource }
1238- />
1239- ) : undefined
1263+ ! showLabsRedesign && branding
1264+ ? getBranding ( )
1265+ : undefined
12401266 }
12411267 showLivePlayable = { showLivePlayable }
12421268 shouldReserveSpace = { {
@@ -1246,6 +1272,11 @@ export const Card = ({
12461272 />
12471273 ) }
12481274 </ div >
1275+
1276+ { showLabsRedesign &&
1277+ format . theme === ArticleSpecial . Labs &&
1278+ branding &&
1279+ getBranding ( ) }
12491280 </ CardWrapper >
12501281 ) ;
12511282} ;
0 commit comments