Skip to content

Commit

Permalink
Apply padding to immersive image captions (#13163)
Browse files Browse the repository at this point in the history
* Add immersive caption padding to compensate for negative margins

* Add immersive padding story
  • Loading branch information
jamesmockett authored Jan 22, 2025
1 parent ec58bd7 commit fb5de2d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dotcom-rendering/src/components/Caption.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,25 @@ export const ForVideos = {
},
},
} satisfies Story;

export const WhenImmersive = {
args: {
captionText:
'This is how a caption looks with immersive padding. Additional padding is added to the left and right of the caption to compensate for the negative margins applied to immersive images.',
format: Standard.args.format,
isImmersive: true,
},
parameters: {
chromatic: {
modes: {
'vertical mobileMedium': { disable: true },
'vertical mobile': allModes['vertical mobile'],
'vertical mobileLandscape':
allModes['vertical mobileLandscape'],
'vertical phablet': allModes['vertical tablet'],
'vertical desktop': allModes['vertical desktop'],
'vertical leftCol': allModes['vertical leftCol'],
},
},
},
} satisfies Story;
22 changes: 22 additions & 0 deletions dotcom-rendering/src/components/Caption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Props = {
isLeftCol?: boolean;
mediaType?: MediaType;
isMainMedia?: boolean;
isImmersive?: boolean;
};

type IconProps = {
Expand Down Expand Up @@ -123,6 +124,25 @@ const tabletCaptionPadding = css`
}
`;

const immersivePadding = css`
padding-left: 10px;
padding-right: 10px;
${from.mobileLandscape} {
padding-left: 20px;
padding-right: 20px;
}
${from.tablet} {
padding-right: 100px;
}
${from.desktop} {
padding-right: 340px;
}
${from.leftCol} {
padding-left: 0;
padding-right: 0;
}
`;

const bigLeftMargin = css`
width: inherit;
margin-left: ${space[9]}px;
Expand Down Expand Up @@ -228,6 +248,7 @@ export const Caption = ({
isLeftCol,
mediaType = 'Gallery',
isMainMedia = false,
isImmersive = false,
}: Props) => {
// Sometimes captions come thorough as a single blank space, so we trim here to ignore those
const noCaption = !captionText?.trim();
Expand All @@ -249,6 +270,7 @@ export const Caption = ({
(isBlog || mediaType === 'Video') &&
tabletCaptionPadding,
padCaption && captionPadding,
isImmersive && immersivePadding,
]}
data-spacefinder-role="inline"
>
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/components/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ export const ImageComponent = ({
shouldLimitWidth={shouldLimitWidth}
isMainMedia={isMainMedia}
padCaption={role === 'showcase' && isTimeline}
isImmersive={role === 'immersive'}
/>
)}
</>
Expand Down

0 comments on commit fb5de2d

Please sign in to comment.