Skip to content

Commit

Permalink
Merge pull request #5254 from guardian/oliver/card-meta-placement
Browse files Browse the repository at this point in the history
Card meta placement
  • Loading branch information
oliverlloyd authored Jul 4, 2022
2 parents 65bb521 + dad1eaf commit d91f6d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 54 deletions.
59 changes: 26 additions & 33 deletions dotcom-rendering/src/web/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@emotion/react';
import { ArticleDesign } from '@guardian/libs';
import { brandAltBackground } from '@guardian/source-foundations';
import { brandAltBackground, space } from '@guardian/source-foundations';
import { Link } from '@guardian/source-react-components';
import { StraightLines } from '@guardian/source-react-components-development-kitchen';
import { decidePalette } from '../../lib/decidePalette';
Expand Down Expand Up @@ -60,26 +60,21 @@ export type Props = {
discussionId?: string;
};

const starWrapper = css`
background-color: ${brandAltBackground.primary};
position: absolute;
bottom: 0;
margin-top: 2px;
`;

const StarRatingComponent: React.FC<{ rating: number }> = ({ rating }) => (
<>
const StarRatingComponent = ({ rating }: { rating: number }) => (
<div
css={css`
background-color: ${brandAltBackground.primary};
margin-top: ${space[1]}px;
display: inline-block;
`}
>
<Hide when="above" breakpoint="desktop">
<div css={starWrapper}>
<StarRating rating={rating} size="small" />
</div>
<StarRating rating={rating} size="small" />
</Hide>
<Hide when="below" breakpoint="desktop">
<div css={starWrapper}>
<StarRating rating={rating} size="medium" />
</div>
<StarRating rating={rating} size="medium" />
</Hide>
</>
</div>
);

/**
Expand Down Expand Up @@ -221,19 +216,6 @@ export const Card = ({
/>
) : undefined
}
mediaMeta={
(format.design === ArticleDesign.Gallery ||
format.design === ArticleDesign.Audio ||
format.design === ArticleDesign.Video) &&
mediaType ? (
<MediaMeta
containerPalette={containerPalette}
format={format}
mediaType={mediaType}
mediaDuration={mediaDuration}
/>
) : undefined
}
commentCount={
discussionId ? (
<Link
Expand Down Expand Up @@ -299,9 +281,6 @@ export const Card = ({
imagePositionOnMobile={imagePositionOnMobile}
>
<img src={imageUrl} alt="" role="presentation" />
{starRating !== undefined ? (
<StarRatingComponent rating={starRating} />
) : null}
</ImageWrapper>
)}
<ContentWrapper
Expand Down Expand Up @@ -332,6 +311,20 @@ export const Card = ({
byline={byline}
showByline={showByline}
/>
{starRating !== undefined ? (
<StarRatingComponent rating={starRating} />
) : null}
{(format.design === ArticleDesign.Gallery ||
format.design === ArticleDesign.Audio ||
format.design === ArticleDesign.Video) &&
mediaType ? (
<MediaMeta
containerPalette={containerPalette}
format={format}
mediaType={mediaType}
mediaDuration={mediaDuration}
/>
) : undefined}
</HeadlineWrapper>
{avatar && (
<Hide when="above" breakpoint="tablet">
Expand Down
19 changes: 0 additions & 19 deletions dotcom-rendering/src/web/components/Card/components/CardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type Props = {
containerPalette?: DCRContainerPalette;
displayLines?: boolean;
age?: JSX.Element;
mediaMeta?: JSX.Element;
commentCount?: JSX.Element;
cardBranding?: JSX.Element;
supportingContent?: JSX.Element;
Expand All @@ -35,7 +34,6 @@ export const CardFooter = ({
containerPalette,
displayLines,
age,
mediaMeta,
commentCount,
cardBranding,
supportingContent,
Expand Down Expand Up @@ -73,23 +71,6 @@ export const CardFooter = ({
);
}

if (
format.design === ArticleDesign.Gallery ||
format.design === ArticleDesign.Audio ||
format.design === ArticleDesign.Video
) {
return (
<footer css={margins}>
{supportingContent}
<div css={spaceBetween}>
{mediaMeta}
{/* Show age if we have it otherwise try for commentCount */}
{age || commentCount}
</div>
</footer>
);
}

if (age) {
return (
<footer css={margins}>
Expand Down
3 changes: 1 addition & 2 deletions dotcom-rendering/src/web/components/MediaMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ const durationStyles = (palette: Palette) => css`
const wrapperStyles = css`
display: flex;
align-items: center;
padding: 0 5px 5px 5px;
margin-top: 4px;
`;

export function secondsToDuration(secs?: number): string {
Expand Down

0 comments on commit d91f6d0

Please sign in to comment.