Skip to content
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

Podcast series image on highlights cards #13194

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 69 additions & 21 deletions dotcom-rendering/src/components/Masthead/HighlightsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import type { StarRating as Rating } from '../../types/content';
import type { DCRFrontImage } from '../../types/front';
import type { MainMedia } from '../../types/mainMedia';
import { PodcastSeriesImage } from '../../types/tag';

Check failure on line 17 in dotcom-rendering/src/components/Masthead/HighlightsCard.tsx

View workflow job for this annotation

GitHub Actions / lint / check

All imports in the declaration are only used as types. Use `import type`
import { Avatar } from '../Avatar';
import { CardLink } from '../Card/components/CardLink';
import { CardHeadline } from '../CardHeadline';
Expand Down Expand Up @@ -41,6 +42,8 @@
starRating?: Rating;
galleryCount?: number;
audioDuration?: string;
/** The square podcast series image, if it exists for a card */
podcastImage?: PodcastSeriesImage;
};

const gridContainer = css`
Expand Down Expand Up @@ -149,9 +152,11 @@
right: 0;
height: 100%;
width: 100%;
border-radius: 100%;
background-color: ${palette('--card-background-hover')};
}
:hover .circular {
border-radius: 100%;
}

/* Only underline the headline element we want to target (not kickers/sublink headlines) */
:hover .card-headline .show-underline {
Expand All @@ -171,6 +176,60 @@
}
`;

const decideImage = (
imageLoading: Loading,
format: ArticleFormat,
image?: DCRFrontImage,
podcastImage?: PodcastSeriesImage,
avatarUrl?: string,
byline?: string,
) => {
if (!image && !avatarUrl) {
return null;
}
if (avatarUrl) {
return (
<Avatar
src={avatarUrl}
alt={byline ?? ''}
shape="cutout"
imageSize="large"
/>
);
}
if (format.design === ArticleDesign.Audio && podcastImage?.src) {
return (
<>
<CardPicture
imageSize="medium"
mainImage={podcastImage.src}
alt={podcastImage.altText}
loading={imageLoading}
isCircular={false}
aspectRatio={'1:1'}
/>
<div className="image-overlay"> </div>
</>
);
}
if (!image) {
return null;
}
return (
<>
<CardPicture
imageSize="medium"
mainImage={image.src}
alt={image.altText}
loading={imageLoading}
isCircular={true}
/>
{/* This image overlay is styled when the CardLink is hovered */}
<div className="image-overlay circular"> </div>
</>
);
};

export const HighlightsCard = ({
linkTo,
format,
Expand All @@ -187,6 +246,7 @@
starRating,
galleryCount,
audioDuration,
podcastImage,
}: HighlightsCardProps) => {
const isMediaCard = isMedia(format);
const MediaPill = () => (
Expand Down Expand Up @@ -257,26 +317,14 @@
{!!mainMedia && isMediaCard && MediaPill()}

<div css={imageArea}>
{(avatarUrl && (
<Avatar
src={avatarUrl}
alt={byline ?? ''}
shape="cutout"
/>
)) ??
(image && (
<>
<CardPicture
imageSize="medium"
mainImage={image.src}
alt={image.altText}
loading={imageLoading}
isCircular={true}
/>
{/* This image overlay is styled when the CardLink is hovered */}
<div className="image-overlay"> </div>
</>
))}
{decideImage(
imageLoading,
format,
image,
podcastImage,
avatarUrl,
byline,
)}
</div>
</div>
</FormatBoundary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export const ScrollableHighlights = ({ trails }: Props) => {
starRating={trail.starRating}
galleryCount={trail.galleryCount}
audioDuration={trail.audioDuration}
podcastImage={trail.podcastImage}
/>
</li>
);
Expand Down
Loading