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

Rework trail text visibility logic & show on all breakpoints in flexible/general #12584

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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,23 +790,14 @@ export const Card = ({
)}

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

{!showCommentFooter && (
<CardFooter
format={format}
Expand Down
63 changes: 63 additions & 0 deletions dotcom-rendering/src/components/Card/components/TrailText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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';
};

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

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,
}: Props) => {
const trailText = (
<div
css={[
trailTextStyles,
css`
color: ${trailTextColour};
`,
fontStyles(trailTextSize),
]}
dangerouslySetInnerHTML={{
__html: text,
}}
/>
);
return hideUntil ? (
<Hide until={hideUntil}>{trailText}</Hide>
) : (
<>{trailText}</>
);
};

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
Loading