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

Pad content based on card properties #13076

Merged
merged 3 commits into from
Jan 7, 2025
Merged
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
17 changes: 15 additions & 2 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,16 @@ export const Card = ({
);
};

const determinePadContent = (
mediaCard: boolean,
betaContainer: boolean,
onwardContent: boolean,
): 'large' | 'small' | undefined => {
if (mediaCard && betaContainer) return 'large';
if (mediaCard || onwardContent) return 'small';
return undefined;
};

return (
<CardWrapper
format={format}
Expand Down Expand Up @@ -817,8 +827,11 @@ export const Card = ({
imageType={media?.type}
imageSize={imageSize}
imagePositionOnDesktop={imagePositionOnDesktop}
hasBackgroundColour={isMediaCard}
isOnwardContent={isOnwardContent}
padContent={determinePadContent(
isMediaCard,
isBetaContainer,
isOnwardContent,
)}
isFlexibleContainer={isFlexibleContainer}
>
{/* This div is needed to keep the headline and trail text justified at the start */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const flexBasisStyles = ({
const paddingStyles = (
imagePosition: ImagePositionType,
isFlexibleContainer: boolean,
paddingWidth: 1 | 2,
) => {
/**
* If we're in a flexible container there is a 20px gap between the image
Expand All @@ -72,18 +73,20 @@ const paddingStyles = (
*/
if (isFlexibleContainer && imagePosition === 'left') {
return css`
padding: ${space[1]}px ${space[1]}px ${space[1]}px 0;
padding: ${space[paddingWidth]}px ${space[paddingWidth]}px
${space[paddingWidth]}px 0;
`;
}

if (isFlexibleContainer && imagePosition === 'right') {
return css`
padding: ${space[1]}px 0 ${space[1]}px ${space[1]}px;
padding: ${space[paddingWidth]}px 0 ${space[paddingWidth]}px
${space[paddingWidth]}px;
`;
}

return css`
padding: ${space[1]}px;
padding: ${space[paddingWidth]}px;
`;
};

Expand All @@ -92,8 +95,7 @@ type Props = {
imageType?: CardImageType;
imageSize: ImageSizeType;
imagePositionOnDesktop: ImagePositionType;
hasBackgroundColour?: boolean;
isOnwardContent?: boolean;
padContent?: 'small' | 'large';
isFlexibleContainer?: boolean;
};

Expand All @@ -102,8 +104,7 @@ export const ContentWrapper = ({
imageType,
imageSize,
imagePositionOnDesktop,
hasBackgroundColour,
isOnwardContent,
padContent,
isFlexibleContainer = false,
}: Props) => {
const isHorizontalOnDesktop =
Expand All @@ -115,8 +116,12 @@ export const ContentWrapper = ({
sizingStyles,
isHorizontalOnDesktop &&
flexBasisStyles({ imageSize, imageType }),
(!!hasBackgroundColour || !!isOnwardContent) &&
paddingStyles(imagePositionOnDesktop, isFlexibleContainer),
padContent &&
paddingStyles(
imagePositionOnDesktop,
isFlexibleContainer,
padContent === 'small' ? 1 : 2,
),
]}
>
{children}
Expand Down
Loading