11import { css } from '@emotion/react' ;
22import { isUndefined } from '@guardian/libs' ;
33import {
4+ between ,
45 from ,
56 palette as sourcePalette ,
67 space ,
8+ until ,
79} from '@guardian/source/foundations' ;
810import { Hide , Link , SvgCamera } from '@guardian/source/react-components' ;
911import {
@@ -15,6 +17,7 @@ import { isMediaCard } from '../../lib/cardHelpers';
1517import { isWithinTwelveHours , secondsToDuration } from '../../lib/formatTime' ;
1618import { appendLinkNameMedia } from '../../lib/getDataLinkName' ;
1719import { getZIndex } from '../../lib/getZIndex' ;
20+ import { getOphanComponents } from '../../lib/labs' ;
1821import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount' ;
1922import { BETA_CONTAINERS } from '../../model/enhanceCollections' ;
2023import { palette } from '../../palette' ;
@@ -43,6 +46,7 @@ import { Pill } from '../Pill';
4346import { SlideshowCarousel } from '../SlideshowCarousel.importable' ;
4447import { Snap } from '../Snap' ;
4548import { SnapCssSandbox } from '../SnapCssSandbox' ;
49+ import { SponsoredContentLabel } from '../SponsoredContentLabel' ;
4650import { StarRating } from '../StarRating/StarRating' ;
4751import type { Alignment } from '../SupportingContent' ;
4852import { SupportingContent } from '../SupportingContent' ;
@@ -725,6 +729,80 @@ export const Card = ({
725729 return undefined ;
726730 } ;
727731
732+ /**
733+ * Decides which branding design to apply based on the labs redesign feature switch
734+ * Adds appropriate Ophan data attributes based on card context
735+ * Results in a clickable brand logo and sponsorship label
736+ */
737+ const LabsBranding = ( ) => {
738+ if ( ! branding ) return ;
739+ const getLocationPrefix = ( ) => {
740+ if ( ! onwardsSource ) {
741+ return 'front-card' ;
742+ }
743+ if ( onwardsSource === 'related-content' ) {
744+ return 'article-related-content' ;
745+ } else {
746+ return undefined ;
747+ }
748+ } ;
749+ const locationPrefix = getLocationPrefix ( ) ;
750+ const dataAttributes = locationPrefix
751+ ? getOphanComponents ( {
752+ branding,
753+ locationPrefix,
754+ } )
755+ : undefined ;
756+
757+ return showLabsRedesign ? (
758+ < >
759+ { /** All screen sizes apart from tablet have horizontal orientation */ }
760+ < div
761+ css = { css `
762+ ${ between . tablet . and . desktop } {
763+ display : none;
764+ }
765+ ` }
766+ >
767+ < SponsoredContentLabel
768+ branding = { branding }
769+ containerPalette = { containerPalette }
770+ orientation = "horizontal"
771+ alignment = "end"
772+ ophanComponentLink = { dataAttributes ?. ophanComponentLink }
773+ ophanComponentName = { dataAttributes ?. ophanComponentName }
774+ />
775+ </ div >
776+ { /** Tablet sized screens have vertical orientation */ }
777+ < div
778+ css = { css `
779+ ${ until . tablet } {
780+ display : none;
781+ }
782+ ${ from . desktop } {
783+ display : none;
784+ }
785+ ` }
786+ >
787+ < SponsoredContentLabel
788+ branding = { branding }
789+ containerPalette = { containerPalette }
790+ orientation = "vertical"
791+ alignment = "end"
792+ ophanComponentLink = { dataAttributes ?. ophanComponentLink }
793+ ophanComponentName = { dataAttributes ?. ophanComponentName }
794+ />
795+ </ div >
796+ </ >
797+ ) : (
798+ < CardBranding
799+ branding = { branding }
800+ containerPalette = { containerPalette }
801+ onwardsSource = { onwardsSource }
802+ />
803+ ) ;
804+ } ;
805+
728806 return (
729807 < CardWrapper
730808 format = { format }
@@ -1109,17 +1187,10 @@ export const Card = ({
11091187 { showPill ? (
11101188 < >
11111189 < MediaOrNewsletterPill />
1112- { format . theme === ArticleSpecial . Labs &&
1113- branding && (
1114- < CardBranding
1115- branding = { branding }
1116- onwardsSource = {
1117- onwardsSource
1118- }
1119- containerPalette = {
1120- containerPalette
1121- }
1122- />
1190+ { ! showLabsRedesign &&
1191+ format . theme ===
1192+ ArticleSpecial . Labs && (
1193+ < LabsBranding />
11231194 ) }
11241195 </ >
11251196 ) : (
@@ -1128,16 +1199,9 @@ export const Card = ({
11281199 age = { decideAge ( ) }
11291200 commentCount = { < CommentCount /> }
11301201 cardBranding = {
1131- branding ? (
1132- < CardBranding
1133- branding = { branding }
1134- onwardsSource = {
1135- onwardsSource
1136- }
1137- containerPalette = {
1138- containerPalette
1139- }
1140- />
1202+ isOnwardContent ||
1203+ ! showLabsRedesign ? (
1204+ < LabsBranding />
11411205 ) : undefined
11421206 }
11431207 showLivePlayable = { showLivePlayable }
@@ -1187,6 +1251,7 @@ export const Card = ({
11871251 </ ContentWrapper >
11881252 </ CardLayout >
11891253
1254+ { /** This div contains content that sits "outside" of the standard card layout */ }
11901255 < div
11911256 css = {
11921257 /** We allow this area to take up more space so that cards without
@@ -1231,12 +1296,7 @@ export const Card = ({
12311296 age = { decideAge ( ) }
12321297 commentCount = { < CommentCount /> }
12331298 cardBranding = {
1234- branding ? (
1235- < CardBranding
1236- branding = { branding }
1237- onwardsSource = { onwardsSource }
1238- />
1239- ) : undefined
1299+ ! showLabsRedesign ? < LabsBranding /> : undefined
12401300 }
12411301 showLivePlayable = { showLivePlayable }
12421302 shouldReserveSpace = { {
@@ -1246,6 +1306,10 @@ export const Card = ({
12461306 />
12471307 ) }
12481308 </ div >
1309+
1310+ { showLabsRedesign &&
1311+ ! isOnwardContent &&
1312+ format . theme === ArticleSpecial . Labs && < LabsBranding /> }
12491313 </ CardWrapper >
12501314 ) ;
12511315} ;
0 commit comments