Skip to content

Commit

Permalink
allow adaptation of card text colours for feature cards
Browse files Browse the repository at this point in the history
  • Loading branch information
cemms1 committed Nov 1, 2024
1 parent ca80876 commit 4184e3f
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 46 deletions.
19 changes: 15 additions & 4 deletions dotcom-rendering/src/components/Byline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ type Props = {
text: string;
isLabs: boolean;
size: SmallHeadlineSize;
/** Optional override of the standard text colour */
colour?: string;
};

const baseStyles = css`
const baseStyles = (colour: string) => css`
display: block;
color: ${palette('--byline')};
color: ${colour};
`;

const bylineStyles = (size: SmallHeadlineSize, isLabs: boolean) => {
Expand Down Expand Up @@ -97,6 +99,15 @@ const bylineStyles = (size: SmallHeadlineSize, isLabs: boolean) => {
}
};

export const Byline = ({ text, isLabs, size }: Props) => {
return <span css={[baseStyles, bylineStyles(size, isLabs)]}>{text}</span>;
export const Byline = ({
text,
isLabs,
size,
colour = palette('--byline'),
}: Props) => {
return (
<span css={[baseStyles(colour), bylineStyles(size, isLabs)]}>
{text}
</span>
);
};
20 changes: 12 additions & 8 deletions dotcom-rendering/src/components/Card/components/CardAge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ type Props = {
showClock?: boolean;
isOnwardContent?: boolean;
isTagPage: boolean;
colour?: string;
};

const ageStyles = (isOnwardsContent?: boolean) => {
const ageStyles = (colour: string) => {
return css`
${textSansBold12};
color: ${isOnwardsContent
? palette('--card-footer-onwards-content')
: palette('--card-footer-text')};
color: ${colour};
margin-top: -4px;
svg {
fill: ${isOnwardsContent
? palette('--card-footer-onwards-content')
: palette('--card-footer-text')};
fill: ${colour};
margin-bottom: -1px;
height: 11px;
width: 11px;
Expand All @@ -44,13 +41,20 @@ export const CardAge = ({
isOnwardContent,
absoluteServerTimes,
isTagPage,
colour = palette('--card-footer-text'),
}: Props) => {
if (timeAgo(new Date(webPublication.date).getTime()) === false) {
return null;
}

return (
<span css={ageStyles(isOnwardContent)}>
<span
css={ageStyles(
isOnwardContent
? palette('--card-footer-onwards-content')
: colour,
)}
>
{showClock && <ClockIcon />}
{isTagPage ? (
<DateTime
Expand Down
39 changes: 20 additions & 19 deletions dotcom-rendering/src/components/CardCommentCount.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,11 @@ type Props = {
discussionId: string;
isDynamo?: true;
isOnwardContent?: boolean;
/** Optional override of default comment count colour */
colour?: string;
};

const getCommentCountColour = (
isDynamo?: boolean,
isOnwardContent?: boolean,
) => {
if (isDynamo) {
return themePalette('--card-trail-text');
} else if (isOnwardContent) {
return themePalette('--card-footer-onwards-content');
} else {
return themePalette('--card-footer-text');
}
};

const containerStyles = (isDynamo?: boolean, isOnwardContent?: boolean) => css`
const containerStyles = (colour: string) => css`
display: flex;
flex-direction: row;
${textSansBold12};
Expand All @@ -43,16 +32,16 @@ const containerStyles = (isDynamo?: boolean, isOnwardContent?: boolean) => css`
*/
line-height: 1.15;
margin-top: -4px;
color: ${getCommentCountColour(isDynamo, isOnwardContent)};
color: ${colour};
`;

const svgStyles = (isDynamo?: boolean, isOnwardContent?: boolean) => css`
const svgStyles = (colour: string) => css`
svg {
margin-bottom: -5px;
height: 14px;
width: 14px;
margin-right: 2px;
fill: ${getCommentCountColour(isDynamo, isOnwardContent)};
fill: ${colour};
}
`;

Expand All @@ -78,14 +67,26 @@ export const CardCommentCount = ({
discussionId,
isDynamo,
isOnwardContent,
colour = themePalette('--card-footer-text'),
}: Props) => {
const count = useCommentCount(discussionApiUrl, discussionId);

const { long, short } = formatCount(count);

const getCommentCountColour = (): string => {
if (isDynamo) {
return themePalette('--card-trail-text');
} else if (isOnwardContent) {
return themePalette('--card-footer-onwards-content');
} else {
return colour;
}
};

return (
<ContainerOverrides containerPalette={containerPalette}>
<div css={containerStyles(isDynamo, isOnwardContent)}>
<div css={svgStyles(isDynamo, isOnwardContent)}>
<div css={containerStyles(getCommentCountColour())}>
<div css={svgStyles(getCommentCountColour())}>
<CommentIcon />
</div>
<div css={longStyles}>{long}</div>
Expand Down
24 changes: 10 additions & 14 deletions dotcom-rendering/src/components/CardHeadline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ type Props = {
showByline?: boolean;
linkTo?: string; // If provided, the headline is wrapped in a link
isExternalLink?: boolean;
/** Is the headline inside a Highlights card? */
isHighlights?: boolean;
/** Optional override of the standard card headline colour */
headlineColour?: string;
/** Optional override of the standard card kicker colour */
kickerColour?: string;
};

const headlineSize = {
Expand Down Expand Up @@ -191,12 +193,9 @@ export const CardHeadline = ({
showByline,
linkTo,
isExternalLink,
isHighlights = false,
headlineColour = palette('--card-headline'),
kickerColour = palette('--card-kicker-text'),
}: Props) => {
const kickerColour = isHighlights
? palette('--highlights-card-kicker-text')
: palette('--card-kicker-text');

// The link is only applied directly to the headline if it is a sublink
const isSublink = !!linkTo;

Expand Down Expand Up @@ -231,13 +230,9 @@ export const CardHeadline = ({
)}
{showQuotes && <QuoteIcon colour={kickerColour} />}
<span
css={[
css`
color: ${isHighlights
? palette('--highlights-card-headline')
: palette('--card-headline')};
`,
]}
css={css`
color: ${headlineColour};
`}
className="show-underline"
>
{headlineText}
Expand All @@ -257,6 +252,7 @@ export const CardHeadline = ({
text={byline}
isLabs={format.theme === ArticleSpecial.Labs}
size={bylineSize}
colour={palette('--feature-card-kicker-text')}
/>
)}
</WithLink>
Expand Down
8 changes: 8 additions & 0 deletions dotcom-rendering/src/components/FeatureCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const CardAge = ({
isOnwardContent={false}
absoluteServerTimes={absoluteServerTimes}
isTagPage={false}
colour={palette('--feature-card-footer-text')}
/>
);
};
Expand Down Expand Up @@ -207,6 +208,7 @@ const CommentCount = ({
discussionApiUrl={discussionApiUrl}
discussionId={discussionId}
isOnwardContent={false}
colour={palette('--feature-card-footer-text')}
/>
</Island>
</Link>
Expand Down Expand Up @@ -364,6 +366,12 @@ export const FeatureCard = ({
byline={byline}
showByline={showByline}
isExternalLink={isExternalLink}
headlineColour={palette(
'--feature-card-headline',
)}
kickerColour={palette(
'--feature-card-kicker-text',
)}
/>

{starRating !== undefined ? (
Expand Down
3 changes: 2 additions & 1 deletion dotcom-rendering/src/components/Masthead/HighlightsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export const HighlightsCard = ({
kickerText={kickerText}
isExternalLink={isExternalLink}
showQuotes={showQuotedHeadline}
isHighlights={true}
headlineColour={palette('--highlights-card-headline')}
kickerColour={palette('--highlights-card-kicker-text')}
/>
</div>

Expand Down
27 changes: 27 additions & 0 deletions dotcom-rendering/src/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5759,6 +5759,21 @@ const editorialButtonText: PaletteFunction = (format: ArticleFormat) => {
}
};

const featureCardKickerTextLight: PaletteFunction = ({ theme }) => {
switch (theme) {
case ArticleSpecial.Labs:
case ArticleSpecial.SpecialReport:
case ArticleSpecial.SpecialReportAlt:
return sourcePalette.neutral[86];
case Pillar.News:
case Pillar.Opinion:
case Pillar.Sport:
case Pillar.Culture:
case Pillar.Lifestyle:
return pillarPalette(theme, 600);
}
};

// ----- Palette ----- //

/**
Expand Down Expand Up @@ -6424,6 +6439,18 @@ const paletteColours = {
light: explainerAtomBackgroundLight,
dark: explainerAtomBackgroundDark,
},
'--feature-card-footer-text': {
light: () => sourcePalette.neutral[86],
dark: () => sourcePalette.neutral[20],
},
'--feature-card-headline': {
light: () => sourcePalette.neutral[97],
dark: () => sourcePalette.neutral[20],
},
'--feature-card-kicker-text': {
light: featureCardKickerTextLight,
dark: () => sourcePalette.neutral[20],
},
'--feature-card-trail-text': {
light: () => sourcePalette.neutral[86],
dark: () => sourcePalette.neutral[20],
Expand Down

0 comments on commit 4184e3f

Please sign in to comment.