Skip to content

Commit

Permalink
Rework trail text visibility logic & show on all breakpoints in flexi…
Browse files Browse the repository at this point in the history
…ble/general (#12584)

* rework trail text visibility logic

* reorder trail text logic to ensure it shows on splash for all breakpoints
  • Loading branch information
cemms1 authored Oct 22, 2024
1 parent 5b4f016 commit 0fea327
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 126 deletions.
38 changes: 20 additions & 18 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ import type {
ImageSizeType,
} from './components/ImageWrapper';
import { ImageWrapper } from './components/ImageWrapper';
import {
type TrailTextSize,
TrailTextWrapper,
} from './components/TrailTextWrapper';
import { TrailText, type TrailTextSize } from './components/TrailText';

export type Position = 'inner' | 'outer' | 'none';

Expand Down Expand Up @@ -443,6 +440,20 @@ export const Card = ({
showLivePlayable,
});

const hideTrailTextUntil = () => {
if (isFlexibleContainer) {
return undefined;
} else if (
imageSize === 'large' &&
imagePositionOnDesktop === 'right' &&
media?.type !== 'avatar'
) {
return 'desktop';
} else {
return 'tablet';
}
};

/** Determines the gap of between card components based on card properties */
const getGapSize = (): GapSize => {
if (isOnwardContent) return 'none';
Expand Down Expand Up @@ -779,24 +790,15 @@ export const Card = ({
)}

{!!trailText && (
<TrailTextWrapper
imagePositionOnDesktop={
imagePositionOnDesktop
}
imageSize={imageSize}
imageType={media?.type}
shouldHide={isFlexSplash ? false : true}
<TrailText
trailText={trailText}
trailTextColour={trailTextColour}
trailTextSize={trailTextSize}
padTop={headlinePosition === 'inner'}
>
<div
dangerouslySetInnerHTML={{
__html: trailText,
}}
/>
</TrailTextWrapper>
hideUntil={hideTrailTextUntil()}
/>
)}

{!showCommentFooter && (
<CardFooter
format={format}
Expand Down
71 changes: 71 additions & 0 deletions dotcom-rendering/src/components/Card/components/TrailText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { css } from '@emotion/react';
import {
from,
space,
textSans14,
textSans17,
} from '@guardian/source/foundations';
import { Hide } from '@guardian/source/react-components';
import { palette } from '../../../palette';

export type TrailTextSize = 'regular' | 'large';

type Props = {
trailText: string;
trailTextSize?: TrailTextSize;
/** Optionally overrides the trail text colour */
trailTextColour?: string;
/** Controls visibility of trail text on various breakpoints */
hideUntil?: 'tablet' | 'desktop';
/** Adds padding to the top of the trail text */
padTop: boolean;
};

const trailTextStyles = css`
display: flex;
flex-direction: column;
padding-bottom: ${space[2]}px;
`;

const topPadding = css`
padding-top: ${space[2]}px;
`;

const fontStyles = (trailTextSize: TrailTextSize) => css`
${textSans14}
${from.desktop} {
${trailTextSize === 'large' && textSans17}
}
strong {
font-weight: bold;
}
`;

export const TrailText = ({
trailText: text,
trailTextSize = 'regular',
trailTextColour = palette('--card-trail-text'),
hideUntil,
padTop,
}: Props) => {
const trailText = (
<div
css={[
trailTextStyles,
css`
color: ${trailTextColour};
`,
fontStyles(trailTextSize),
padTop && topPadding,
]}
dangerouslySetInnerHTML={{
__html: text,
}}
/>
);
return hideUntil ? (
<Hide until={hideUntil}>{trailText}</Hide>
) : (
<>{trailText}</>
);
};
106 changes: 0 additions & 106 deletions dotcom-rendering/src/components/Card/components/TrailTextWrapper.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/FlexibleGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
ImageSizeType,
} from './Card/components/ImageWrapper';
import { LI } from './Card/components/LI';
import type { TrailTextSize } from './Card/components/TrailTextWrapper';
import type { TrailTextSize } from './Card/components/TrailText';
import { UL } from './Card/components/UL';
import type { Loading } from './CardPicture';
import { FrontCard } from './FrontCard';
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/FlexibleSpecial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
ImageSizeType,
} from './Card/components/ImageWrapper';
import { LI } from './Card/components/LI';
import type { TrailTextSize } from './Card/components/TrailTextWrapper';
import type { TrailTextSize } from './Card/components/TrailText';
import { UL } from './Card/components/UL';
import type { Loading } from './CardPicture';
import { FrontCard } from './FrontCard';
Expand Down

0 comments on commit 0fea327

Please sign in to comment.