Skip to content

Commit e5cb5da

Browse files
Add ProductCardImage.tsx
1 parent d1822ac commit e5cb5da

File tree

4 files changed

+91
-88
lines changed

4 files changed

+91
-88
lines changed

dotcom-rendering/src/components/InlineProductCard.tsx

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {
1212
import type { ArticleFormat } from '../lib/articleFormat';
1313
import { palette } from '../palette';
1414
import type { ProductImage } from '../types/content';
15-
import { Caption } from './Caption';
16-
import { Picture } from './Picture';
15+
import { ProductCardImage } from './ProductCardImage';
1716
import type { ProductCardCta } from './ProductElement';
1817
import { ProductLinkButton } from './ProductLinkButton';
1918

@@ -161,45 +160,11 @@ export const InlineProductCard = ({
161160
}: InlineProductCardProps) => {
162161
return (
163162
<div css={[isCardOnly && productCard, !isCardOnly && showcaseCard]}>
164-
{!!image && (
165-
<div>
166-
{productCtas[0]?.url ? (
167-
<a
168-
href={productCtas[0].url}
169-
target="_blank"
170-
rel="noopener noreferrer"
171-
>
172-
<Picture
173-
role={'productCard'}
174-
format={format}
175-
master={image.url}
176-
alt={image.alt}
177-
height={165}
178-
width={165}
179-
loading={'eager'}
180-
/>
181-
</a>
182-
) : (
183-
<Picture
184-
role={'productCard'}
185-
format={format}
186-
master={image.url}
187-
alt={image.alt}
188-
height={165}
189-
width={165}
190-
loading={'eager'}
191-
/>
192-
)}
193-
<Caption
194-
shouldLimitWidth={true}
195-
format={format}
196-
isLeftCol={true}
197-
displayCredit={image.displayCredit}
198-
credit={image.credit}
199-
isOverlaid={false}
200-
/>
201-
</div>
202-
)}
163+
<ProductCardImage
164+
format={format}
165+
image={image}
166+
url={productCtas[0]?.url}
167+
/>
203168
<div css={productInfoContainer}>
204169
<div css={primaryHeading}>{brandName}</div>
205170
<div css={productNameStyle}>{productName}</div>

dotcom-rendering/src/components/LeftColProductCard.tsx

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import {
99
import type { ArticleFormat } from '../lib/articleFormat';
1010
import { palette } from '../palette';
1111
import type { ProductImage } from '../types/content';
12-
import { Caption } from './Caption';
1312
import { ProductCardButtons } from './InlineProductCard';
14-
import { Picture } from './Picture';
13+
import { ProductCardImage } from './ProductCardImage';
1514
import type { ProductCardCta } from './ProductElement';
1615

1716
export type CustomAttributes = {
@@ -70,6 +69,11 @@ const buttonContainer = css`
7069
min-width: 100%;
7170
`;
7271

72+
const productImageCaption = css`
73+
figcaption {
74+
position: static;
75+
}
76+
`;
7377
const customAttributesContainer = css`
7478
border-top: 1px solid ${palette('--section-border')};
7579
padding-top: ${space[3]}px;
@@ -102,51 +106,12 @@ export const LeftColProductCard = ({
102106
}: LeftColProductCardProps) => {
103107
return (
104108
<div css={card}>
105-
{!!image && (
106-
<div
107-
css={css`
108-
figcaption {
109-
position: static;
110-
}
111-
`}
112-
>
113-
{productCtas[0]?.url ? (
114-
<a
115-
href={productCtas[0].url}
116-
target="_blank"
117-
rel="noopener noreferrer"
118-
>
119-
<Picture
120-
role={'productCard'}
121-
format={format}
122-
master={image.url}
123-
alt={image.alt}
124-
height={220}
125-
width={220}
126-
loading={'eager'}
127-
/>
128-
</a>
129-
) : (
130-
<Picture
131-
role={'productCard'}
132-
format={format}
133-
master={image.url}
134-
alt={image.alt}
135-
height={220}
136-
width={220}
137-
loading={'eager'}
138-
/>
139-
)}
140-
<Caption
141-
shouldLimitWidth={true}
142-
format={format}
143-
isLeftCol={true}
144-
displayCredit={image.displayCredit}
145-
credit={image.credit}
146-
isOverlaid={false}
147-
/>
148-
</div>
149-
)}
109+
<ProductCardImage
110+
format={format}
111+
image={image}
112+
url={productCtas[0]?.url}
113+
css={productImageCaption}
114+
/>
150115
<div css={productInfoContainer}>
151116
<div css={brandNameFont}>{brandName}</div>
152117
<div css={productNameFont}>{productName}</div>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { css } from '@emotion/react';
2+
import type { HTMLAttributes } from 'react';
3+
import type { ArticleFormat } from '../lib/articleFormat';
4+
import type { ProductImage } from '../types/content';
5+
import { Caption } from './Caption';
6+
import { Picture } from './Picture';
7+
8+
interface ProductCardImageProps extends HTMLAttributes<HTMLDivElement> {
9+
format: ArticleFormat;
10+
image?: ProductImage;
11+
url?: string;
12+
}
13+
14+
export const ProductCardImage = ({
15+
format,
16+
image,
17+
url,
18+
...props
19+
}: ProductCardImageProps) => {
20+
if (!image) {
21+
return null;
22+
}
23+
24+
return (
25+
<div {...props}>
26+
{url ? (
27+
<a
28+
href={url}
29+
target="_blank"
30+
rel="noopener noreferrer"
31+
aria-disabled={true}
32+
tabIndex={-1}
33+
data-src-focus-disabled={true}
34+
css={css`
35+
&:focus {
36+
box-shadow: none !important;
37+
}
38+
`}
39+
>
40+
<Picture
41+
data-src-focus-disabled={true}
42+
role={'productCard'}
43+
format={format}
44+
master={image.url}
45+
alt={image.alt}
46+
height={image.height}
47+
width={image.width}
48+
loading={'eager'}
49+
/>
50+
</a>
51+
) : (
52+
<Picture
53+
role={'productCard'}
54+
format={format}
55+
master={image.url}
56+
alt={image.alt}
57+
height={image.height}
58+
width={image.width}
59+
loading={'eager'}
60+
/>
61+
)}
62+
<Caption
63+
shouldLimitWidth={true}
64+
format={format}
65+
isLeftCol={true}
66+
displayCredit={image.displayCredit}
67+
credit={image.credit}
68+
isOverlaid={false}
69+
/>
70+
</div>
71+
);
72+
};

dotcom-rendering/src/components/ProductElement.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ const meta = {
282282
theme: Pillar.Lifestyle,
283283
},
284284
ArticleElementComponent,
285+
shouldShowLeftColCard: true,
285286
},
286287
decorators: [
287288
(Story) => (

0 commit comments

Comments
 (0)