Skip to content

Commit 09e3da2

Browse files
Update grid on inline card to allow no custom attributes (#14797)
1 parent 9a02920 commit 09e3da2

File tree

2 files changed

+81
-52
lines changed

2 files changed

+81
-52
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,20 @@ type Story = StoryObj<typeof meta>;
7070

7171
export const Default = {} satisfies Story;
7272

73+
export const ProductCardNoCustomAttributes = {
74+
args: {
75+
...meta.args,
76+
customAttributes: [],
77+
},
78+
} satisfies Story;
79+
7380
export const ProductCardOnly = {
7481
args: {
7582
...meta.args,
7683
isCardOnly: true,
7784
},
78-
};
85+
} satisfies Story;
86+
7987
export const ProductCardOnlyDisplayCredit = {
8088
args: {
8189
...meta.args,

dotcom-rendering/src/components/ProductCardInline.tsx

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,37 @@ export type InlineProductCardProps = {
3232
lowestPrice?: string;
3333
};
3434

35-
const baseCard = css`
36-
padding: ${space[2]}px ${space[3]}px ${space[3]}px;
37-
display: grid;
35+
const defaultGrid = css`
3836
grid-template:
3937
'image info'
4038
'buttons buttons'
4139
'custom-attributes custom-attributes' / 1fr 1fr;
42-
column-gap: 10px;
43-
row-gap: ${space[4]}px;
44-
max-width: 100%;
4540
${from.mobileLandscape} {
4641
grid-template:
4742
'image info' auto
4843
'image buttons' 1fr
4944
'custom-attributes custom-attributes' / 1fr 1fr;
45+
}
46+
`;
47+
48+
const noCustomAttributesGrid = css`
49+
grid-template:
50+
'image info'
51+
'buttons buttons' / 1fr 1fr;
52+
${from.mobileLandscape} {
53+
grid-template:
54+
'image info' auto
55+
'image buttons' 1fr / 1fr 1fr;
56+
}
57+
`;
58+
59+
const baseCard = css`
60+
padding: ${space[2]}px ${space[3]}px ${space[3]}px;
61+
display: grid;
62+
column-gap: 10px;
63+
row-gap: ${space[4]}px;
64+
max-width: 100%;
65+
${from.mobileLandscape} {
5066
column-gap: 20px;
5167
row-gap: ${space[2]}px;
5268
}
@@ -161,51 +177,56 @@ export const ProductCardInline = ({
161177
isCardOnly = false,
162178
shouldShowLeftColCard = false,
163179
lowestPrice,
164-
}: InlineProductCardProps) => (
165-
<div
166-
css={[
167-
isCardOnly ? productCard : showcaseCard,
168-
shouldShowLeftColCard && !isCardOnly && hideFromWide,
169-
]}
170-
>
171-
<div css={imageGridArea}>
172-
<ProductCardImage
173-
format={format}
174-
image={image}
175-
url={productCtas[0]?.url}
176-
/>
177-
</div>
178-
<div css={productInfoContainer}>
179-
<div css={primaryHeading}>{brandName}</div>
180-
<div css={productNameStyle}>{productName}</div>
181-
{!!lowestPrice && (
182-
<div css={productNameStyle}>
183-
{productCtas.length > 1 ? (
184-
<>
185-
from <strong>{lowestPrice}</strong>
186-
</>
187-
) : (
188-
<strong>{lowestPrice}</strong>
189-
)}
180+
}: InlineProductCardProps) => {
181+
const hasCustomAttributes = customAttributes.length > 0 && !isCardOnly;
182+
183+
return (
184+
<div
185+
css={[
186+
isCardOnly ? productCard : showcaseCard,
187+
shouldShowLeftColCard && !isCardOnly && hideFromWide,
188+
hasCustomAttributes ? defaultGrid : noCustomAttributesGrid,
189+
]}
190+
>
191+
<div css={imageGridArea}>
192+
<ProductCardImage
193+
format={format}
194+
image={image}
195+
url={productCtas[0]?.url}
196+
/>
197+
</div>
198+
<div css={productInfoContainer}>
199+
<div css={primaryHeading}>{brandName}</div>
200+
<div css={productNameStyle}>{productName}</div>
201+
{!!lowestPrice && (
202+
<div css={productNameStyle}>
203+
{productCtas.length > 1 ? (
204+
<>
205+
from <strong>{lowestPrice}</strong>
206+
</>
207+
) : (
208+
<strong>{lowestPrice}</strong>
209+
)}
210+
</div>
211+
)}
212+
</div>
213+
<div css={buttonWrapper}>
214+
<ProductCardButtons
215+
productCtas={productCtas}
216+
dataComponent={'inline-product-card-buttons'}
217+
/>
218+
</div>
219+
{hasCustomAttributes && (
220+
<div css={customAttributesContainer}>
221+
{customAttributes.map((customAttribute) => (
222+
<CustomAttribute
223+
key={customAttribute.name}
224+
name={customAttribute.name}
225+
value={customAttribute.value}
226+
/>
227+
))}
190228
</div>
191229
)}
192230
</div>
193-
<div css={buttonWrapper}>
194-
<ProductCardButtons
195-
productCtas={productCtas}
196-
dataComponent={'inline-product-card-buttons'}
197-
/>
198-
</div>
199-
{!isCardOnly && customAttributes.length > 0 && (
200-
<div css={customAttributesContainer}>
201-
{customAttributes.map((customAttribute) => (
202-
<CustomAttribute
203-
key={customAttribute.name}
204-
name={customAttribute.name}
205-
value={customAttribute.value}
206-
/>
207-
))}
208-
</div>
209-
)}
210-
</div>
211-
);
231+
);
232+
};

0 commit comments

Comments
 (0)