Skip to content

Commit

Permalink
[Fairground 🎡] Card Headline sizing refactor (#12571)
Browse files Browse the repository at this point in the history
* Refactor fontsizes to use one map

* Transform existing sizes into modern size group

* Use modern headline sizing
  • Loading branch information
abeddow91 authored Oct 24, 2024
1 parent 2162803 commit f1bb92c
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 356 deletions.
1 change: 0 additions & 1 deletion dotcom-rendering/src/components/Byline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const bylineStyles = (size: SmallHeadlineSize, isLabs: boolean) => {
if (isLabs) {
return css`
${textSansItalic24};
font-size: 24px;
line-height: 24px;
${until.desktop} {
${textSansItalic24};
Expand Down
19 changes: 10 additions & 9 deletions dotcom-rendering/src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const basicCardProps: CardProps = {
headlineText: 'Headline text',
trailText:
'The 29-year-old source behind the biggest intelligence leak in the NSA’s history explains his motives',
headlineSize: 'medium',
headlineSizes: { desktop: 'xsmall' },
kickerText: '',
webPublicationDate: new Date(Date.now() - 60 * 60 * 1000).toString(),
image: {
Expand Down Expand Up @@ -209,34 +209,35 @@ export default {
],
};

/** TODO : Update stories once initial chromatic check has passed on new font size scale */
export const WithDifferentHeadlineSizes = () => {
return (
<CardGroup>
<CardWrapper>
<Card
{...basicCardProps}
headlineSize="tiny"
headlineSizes={{ desktop: 'tiny' }}
headlineText="tiny"
/>
</CardWrapper>
<CardWrapper>
<Card
{...basicCardProps}
headlineSize="small"
headlineSizes={{ desktop: 'xxsmall' }}
headlineText="small"
/>
</CardWrapper>
<CardWrapper>
<Card
{...basicCardProps}
headlineSize="medium"
headlineSizes={{ desktop: 'xsmall' }}
headlineText="medium"
/>
</CardWrapper>
<CardWrapper>
<Card
{...basicCardProps}
headlineSize="large"
headlineSizes={{ desktop: 'small' }}
headlineText="large"
/>
</CardWrapper>
Expand Down Expand Up @@ -266,7 +267,7 @@ export const WithExternalLink = () => {
{...basicCardProps}
imagePositionOnDesktop="right"
kickerText="Instagram"
headlineSize="huge"
headlineSizes={{ desktop: 'medium', tablet: 'small' }}
headlineText="Follow The Guardian now"
isExternalLink={true}
/>
Expand Down Expand Up @@ -1103,7 +1104,7 @@ export const WithLetterDesign = () => {
<CardWrapper>
<Card
{...basicCardProps}
headlineSize="small"
headlineSizes={{ desktop: 'xxsmall' }}
headlineText="Culture"
format={{
display: ArticleDisplay.Standard,
Expand All @@ -1122,7 +1123,7 @@ export const WithLetterDesignAndShowQuotedHeadline = () => {
<CardWrapper>
<Card
{...basicCardProps}
headlineSize="small"
headlineSizes={{ desktop: 'xxsmall' }}
headlineText="Culture"
showQuotedHeadline={true}
format={{
Expand Down Expand Up @@ -1372,7 +1373,7 @@ export const DynamoWithSpecialPaletteVariations = () => {
containerType="dynamic/package"
isDynamo={true}
kickerText="Main kicker"
headlineSize="huge"
headlineSizes={{ desktop: 'medium', tablet: 'small' }}
imagePositionOnDesktop="bottom"
imagePositionOnMobile="bottom"
imageSize="large"
Expand Down
37 changes: 16 additions & 21 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { MainMedia } from '../../types/mainMedia';
import type { OnwardsSource } from '../../types/onwards';
import { Avatar } from '../Avatar';
import { CardCommentCount } from '../CardCommentCount.importable';
import { CardHeadline } from '../CardHeadline';
import { CardHeadline, type ResponsiveFontSize } from '../CardHeadline';
import type { AspectRatio, Loading } from '../CardPicture';
import { CardPicture } from '../CardPicture';
import { Island } from '../Island';
Expand Down Expand Up @@ -62,9 +62,7 @@ export type Props = {
format: ArticleFormat;
absoluteServerTimes: boolean;
headlineText: string;
headlineSize?: SmallHeadlineSize;
headlineSizeOnMobile?: SmallHeadlineSize;
headlineSizeOnTablet?: SmallHeadlineSize;
headlineSizes?: ResponsiveFontSize;
showQuotedHeadline?: boolean;
byline?: string;
showByline?: boolean;
Expand Down Expand Up @@ -118,8 +116,6 @@ export type Props = {
isTagPage?: boolean;
/** Alows the consumer to set an aspect ratio on the image of 5:3 or 5:4 */
aspectRatio?: AspectRatio;
/** Alows the consumer to use a larger font size group for boost styling*/
boostedFontSizes?: boolean;
index?: number;
/** The Splash card in a flexible container gets a different visual treatment to other cards*/
isFlexSplash?: boolean;
Expand Down Expand Up @@ -267,9 +263,7 @@ export const Card = ({
linkTo,
format,
headlineText,
headlineSize,
headlineSizeOnMobile,
headlineSizeOnTablet,
headlineSizes,
showQuotedHeadline,
byline,
showByline,
Expand Down Expand Up @@ -313,7 +307,6 @@ export const Card = ({
absoluteServerTimes,
isTagPage = false,
aspectRatio,
boostedFontSizes,
index = 0,
isFlexSplash,
showTopBarDesktop = true,
Expand Down Expand Up @@ -544,9 +537,7 @@ export const Card = ({
<CardHeadline
headlineText={headlineText}
format={format}
size={headlineSize}
sizeOnMobile={headlineSizeOnMobile}
sizeOnTablet={headlineSizeOnTablet}
fontSizes={headlineSizes}
showQuotes={showQuotes}
kickerText={
format.design === ArticleDesign.LiveBlog &&
Expand All @@ -561,7 +552,6 @@ export const Card = ({
byline={byline}
showByline={showByline}
isExternalLink={isExternalLink}
boostedFontSizes={boostedFontSizes}
/>
{!isUndefined(starRating) ? (
<StarRatingComponent
Expand Down Expand Up @@ -665,11 +655,19 @@ export const Card = ({
imagePositionOnMobile={
imagePositionOnMobile
}
//** TODO: IMPROVE THIS MAPPING */
// image size defaults to small if not provided. However, if the headline size is large or greater, we want to assume the image is also large so that the play icon is correctly sized.
imageSize={
headlineSize === 'huge' ||
headlineSize === 'large' ||
headlineSize === 'ginormous'
[
'small',
'medium',
'large',
'xlarge',
'xxlarge',
].includes(
headlineSizes?.desktop ??
'',
)
? 'large'
: imageSize
}
Expand Down Expand Up @@ -753,9 +751,7 @@ export const Card = ({
<CardHeadline
headlineText={headlineText}
format={format}
size={headlineSize}
sizeOnMobile={headlineSizeOnMobile}
sizeOnTablet={headlineSizeOnTablet}
fontSizes={headlineSizes}
showQuotes={showQuotes}
kickerText={
format.design ===
Expand All @@ -772,7 +768,6 @@ export const Card = ({
byline={byline}
showByline={showByline}
isExternalLink={isExternalLink}
boostedFontSizes={boostedFontSizes}
/>
{!isUndefined(starRating) ? (
<StarRatingComponent
Expand Down
34 changes: 20 additions & 14 deletions dotcom-rendering/src/components/CardHeadline.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Pillar,
} from '../lib/articleFormat';
import type { DCRContainerPalette } from '../types/front';
import { CardHeadline } from './CardHeadline';
import { CardHeadline, type HeadlineSize } from './CardHeadline';
import { ContainerOverrides } from './ContainerOverrides';
import { Section } from './Section';

Expand All @@ -18,12 +18,16 @@ export default {
title: 'Components/CardHeadline',
};

const smallHeadlineSizes: SmallHeadlineSize[] = [
'ginormous',
'huge',
const headlineSize: HeadlineSize[] = [
'xxxlarge',
'xxlarge',
'xlarge',
'large',
'medium',
'small',
'xsmall',
'xxsmall',
'xxxsmall',
'tiny',
];

Expand All @@ -48,7 +52,7 @@ Article.decorators = [

export const Analysis: StoryObj = ({ format }: StoryProps) => (
<>
{smallHeadlineSizes.map((size) => (
{headlineSize.map((size) => (
<Section
key={size}
fullWidth={true}
Expand All @@ -63,7 +67,7 @@ export const Analysis: StoryObj = ({ format }: StoryProps) => (
'Unknown'
} card headline looks`}
format={format}
size={size}
fontSizes={{ desktop: size }}
/>
</Section>
))}
Expand Down Expand Up @@ -126,7 +130,7 @@ Feature.decorators = [

export const Size: StoryObj = ({ format }: StoryProps) => (
<>
{smallHeadlineSizes.map((size) => (
{headlineSize.map((size) => (
<Section
key={size}
fullWidth={true}
Expand All @@ -137,7 +141,7 @@ export const Size: StoryObj = ({ format }: StoryProps) => (
<CardHeadline
headlineText={`This is how a ${size} card headline looks`}
format={format}
size={size}
fontSizes={{ desktop: size }}
/>
</Section>
))}
Expand All @@ -156,7 +160,7 @@ Size.decorators = [

export const MobileSize: StoryObj = ({ format }: StoryProps) => (
<>
{smallHeadlineSizes.map((size) => (
{headlineSize.map((size) => (
<Section
key={size}
fullWidth={true}
Expand All @@ -167,8 +171,10 @@ export const MobileSize: StoryObj = ({ format }: StoryProps) => (
<CardHeadline
headlineText={`This is how a mobile ${size} card headline looks`}
format={format}
size="medium"
sizeOnMobile={size}
fontSizes={{
desktop: 'xsmall',
tablet: size,
}}
/>
</Section>
))}
Expand Down Expand Up @@ -280,7 +286,7 @@ export const Opinion: StoryObj = ({ format }: StoryProps) => (
headlineText="This is how small card headline for opinion articles look"
format={format}
showQuotes={true}
size="small"
fontSizes={{ desktop: 'xxsmall' }}
/>
</Section>
);
Expand All @@ -297,7 +303,7 @@ Opinion.decorators = [

export const OpinionKicker: StoryObj = ({ format }: StoryProps) => (
<>
{smallHeadlineSizes.map((size) => (
{headlineSize.map((size) => (
<Section
key={size}
fullWidth={true}
Expand All @@ -310,7 +316,7 @@ export const OpinionKicker: StoryObj = ({ format }: StoryProps) => (
format={format}
showQuotes={true}
kickerText="George Monbiot"
size={size}
fontSizes={{ desktop: size }}
/>
</Section>
))}
Expand Down
Loading

0 comments on commit f1bb92c

Please sign in to comment.