Skip to content

Commit 288e33a

Browse files
moved where CTA label is decided.
1 parent 9195e1a commit 288e33a

File tree

8 files changed

+73
-56
lines changed

8 files changed

+73
-56
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ const sampleProductCard: InlineProductCardProps = {
8181
productCtas: [
8282
{
8383
url: 'https://www.theguardian.com',
84-
label: '£89.99 at Amazon',
84+
price: '£89.99',
85+
retailer: 'Amazon',
86+
text: '',
8587
},
8688
{
8789
url: 'https://www.theguardian.com',
88-
label: '£99.99 at John Lewis',
90+
price: '£95.99',
91+
retailer: 'John Lewis',
92+
text: '',
8993
},
9094
],
9195
brandName: 'AirCraft',
@@ -97,16 +101,17 @@ const sampleProductCard: InlineProductCardProps = {
97101
value: 'There’s nowhere to stow the remote control',
98102
},
99103
],
104+
lowestPrice: '£89.99',
100105
isCardOnly: false,
101106
};
102107

103108
export const Default = () => <InlineProductCard {...sampleProductCard} />;
104109

105-
export const productCardOnly = () => (
110+
export const ProductCardOnly = () => (
106111
<InlineProductCard {...sampleProductCard} isCardOnly={true} />
107112
);
108113

109-
export const productCardOnlyDisplayCredit = () => (
114+
export const ProductCardOnlyDisplayCredit = () => (
110115
<InlineProductCard
111116
{...sampleProductCard}
112117
image={{

dotcom-rendering/src/components/InlineProductCard.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ import {
1313
} from '@guardian/source/foundations';
1414
import type { ArticleFormat } from '../lib/articleFormat';
1515
import { palette } from '../palette';
16-
import type { ProductImage } from '../types/content';
16+
import type { ProductCta, ProductImage } from '../types/content';
1717
import { ProductCardButtons } from './ProductCardButtons';
1818
import { ProductCardImage } from './ProductCardImage';
1919

20-
export type ProductCardCta = {
21-
label: string;
22-
url: string;
23-
};
2420
export type CustomAttributes = {
2521
name: string;
2622
value: string;
@@ -31,7 +27,7 @@ export type InlineProductCardProps = {
3127
brandName: string;
3228
productName: string;
3329
image?: ProductImage;
34-
productCtas: ProductCardCta[];
30+
productCtas: ProductCta[];
3531
customAttributes: CustomAttributes[];
3632
isCardOnly: boolean;
3733
shouldShowLeftColCard?: boolean;
@@ -107,7 +103,8 @@ const productNameStyle = css`
107103

108104
const mobileButtonWrapper = css`
109105
grid-column: 1 / span 2;
110-
grid-gap: ${space[1]}px;
106+
display: grid;
107+
row-gap: ${space[1]}px;
111108
${from.mobileLandscape} {
112109
display: none;
113110
}
@@ -116,7 +113,8 @@ const mobileButtonWrapper = css`
116113
const desktopButtonWrapper = css`
117114
display: none;
118115
${from.mobileLandscape} {
119-
display: inline;
116+
display: grid;
117+
row-gap: ${space[1]}px;
120118
}
121119
`;
122120

@@ -174,7 +172,6 @@ export const InlineProductCard = ({
174172
format={format}
175173
image={image}
176174
url={productCtas[0]?.url}
177-
label={productCtas[0]?.label}
178175
/>
179176
<div css={productInfoContainer}>
180177
<div css={primaryHeading}>{brandName}</div>

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ const meta = {
4141
productCtas: [
4242
{
4343
url: 'https://www.theguardian.com',
44-
label: '£89.99 at Amazon',
44+
price: '£89.99',
45+
retailer: 'Amazon',
46+
text: '',
4547
},
4648
{
4749
url: 'https://www.theguardian.com',
48-
label: '£99.99 at John Lewis',
50+
price: '£95.99',
51+
retailer: 'John Lewis',
52+
text: '',
4953
},
5054
],
5155
customAttributes: [
@@ -76,7 +80,9 @@ export const SingleCta: Story = {
7680
productCtas: [
7781
{
7882
url: 'https://www.theguardian.com',
79-
label: '£89.99 at Amazon',
83+
price: '£89.99',
84+
retailer: 'at Amazon',
85+
text: '',
8086
},
8187
],
8288
lowestPrice: '£89.99',
@@ -88,7 +94,9 @@ export const ShortCta: Story = {
8894
productCtas: [
8995
{
9096
url: 'https://www.theguardian.com',
91-
label: '£8 at Z',
97+
price: '£8',
98+
retailer: 'Z',
99+
text: '',
92100
},
93101
],
94102
lowestPrice: '£89.99',
@@ -100,31 +108,27 @@ export const LotsOfCtas: Story = {
100108
productCtas: [
101109
{
102110
url: 'https://www.theguardian.com',
103-
label: '£89.99 at Cotswolds Outdoors',
111+
price: '£89.99',
112+
retailer: 'Cotswold Outdoor',
113+
text: '',
104114
},
105115
{
106116
url: 'https://www.theguardian.com',
107-
label: '£89 at Zara',
117+
price: '£95',
118+
retailer: 'REI',
119+
text: '',
108120
},
109121
{
110122
url: 'https://www.theguardian.com',
111-
label: '£9 at Kenwood',
123+
price: '£99.99',
124+
retailer: 'John Lewis',
125+
text: '',
112126
},
113127
{
114128
url: 'https://www.theguardian.com',
115-
label: '£70 at Amazon',
116-
},
117-
{
118-
url: 'https://www.theguardian.com',
119-
label: '£12 for 10 at John Lewis',
120-
},
121-
{
122-
url: 'https://www.theguardian.com',
123-
label: '£30 at eBay',
124-
},
125-
{
126-
url: 'https://www.theguardian.com',
127-
label: '£45 at Etsy',
129+
price: '£105',
130+
retailer: 'Amazon',
131+
text: '',
128132
},
129133
],
130134
lowestPrice: '£89.99',

dotcom-rendering/src/components/LeftColProductCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
} from '@guardian/source/foundations';
1010
import type { ArticleFormat } from '../lib/articleFormat';
1111
import { palette } from '../palette';
12-
import type { ProductImage } from '../types/content';
13-
import type { ProductCardCta } from './InlineProductCard';
12+
import type { ProductCta, ProductImage } from '../types/content';
1413
import { ProductCardButtons } from './ProductCardButtons';
1514
import { ProductCardImage } from './ProductCardImage';
1615

@@ -25,7 +24,7 @@ export type LeftColProductCardProps = {
2524
image?: ProductImage;
2625
customAttributes: CustomAttributes[];
2726
format: ArticleFormat;
28-
productCtas: ProductCardCta[];
27+
productCtas: ProductCta[];
2928
lowestPrice?: string;
3029
};
3130

@@ -67,6 +66,8 @@ const productNameFont = css`
6766
const buttonContainer = css`
6867
padding-bottom: ${space[6]}px;
6968
min-width: 100%;
69+
display: grid;
70+
row-gap: ${space[1]}px;
7071
`;
7172
const customAttributesContainer = css`
7273
border-top: 1px solid ${palette('--section-border')};
@@ -102,7 +103,6 @@ export const LeftColProductCard = ({
102103
format={format}
103104
image={image}
104105
url={productCtas[0]?.url}
105-
label={productCtas[0]?.label}
106106
/>
107107
<div css={productInfoContainer}>
108108
<div css={brandNameFont}>{brandName}</div>
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
import type { ProductCardCta } from './InlineProductCard';
1+
import type { ProductCta } from '../types/content';
22
import { ProductLinkButton } from './ProductLinkButton';
33

44
export const ProductCardButtons = ({
55
productCtas,
66
dataComponent,
77
}: {
8-
productCtas: ProductCardCta[];
8+
productCtas: ProductCta[];
99
dataComponent?: string;
1010
}) => {
11+
const getLabel = (cta: ProductCta): string => {
12+
const overrideLabel = cta.text.trim().length > 0;
13+
return overrideLabel ? cta.text : `${cta.price} at ${cta.retailer}`;
14+
};
1115
return (
1216
<>
13-
{productCtas.map((productCta, index) => (
14-
<ProductLinkButton
15-
key={productCta.label}
16-
label={productCta.label}
17-
url={productCta.url}
18-
priority={index === 0 ? 'primary' : 'tertiary'}
19-
fullwidth={true}
20-
data-component={`${
21-
dataComponent ?? 'product-card-button'
22-
}-${index}`}
23-
/>
24-
))}
17+
{productCtas.map((productCta, index) => {
18+
const label = getLabel(productCta);
19+
return (
20+
<ProductLinkButton
21+
key={label}
22+
label={label}
23+
url={productCta.url}
24+
priority={index === 0 ? 'primary' : 'tertiary'}
25+
fullwidth={true}
26+
data-component={`${
27+
dataComponent ?? 'product-card-button'
28+
}-${index}`}
29+
/>
30+
);
31+
})}
2532
</>
2633
);
2734
};

dotcom-rendering/src/components/ProductCardImage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const ProductCardImage = ({
1616
format,
1717
image,
1818
url,
19-
label,
2019
...props
2120
}: ProductCardImageProps) => {
2221
if (!image) {
@@ -25,12 +24,11 @@ export const ProductCardImage = ({
2524

2625
return (
2726
<div {...props}>
28-
{url && label ? (
27+
{url ? (
2928
<a
3029
href={url}
3130
target="_blank"
3231
rel="noopener noreferrer"
33-
aria-label={label}
3432
// this is needed to override global style
3533
// html:not(.src-focus-disabled) *:focus
3634
// it has specificity(0, 2, 1) so we need (0, 3, 0)

dotcom-rendering/src/components/ProductLinkButton.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ export const ProductLinkButton = ({
6868
<span
6969
css={css`
7070
white-space: normal;
71-
width: 100%;
72-
padding: 10px 0 10px;
71+
padding: 4px 0 4px;
7372
`}
7473
>
7574
{label}

dotcom-rendering/src/types/content.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,13 @@ export interface ImageSource {
865865
srcSet: SrcSetItem[];
866866
}
867867

868+
export type ProductCta = {
869+
url: string;
870+
text: string;
871+
retailer: string;
872+
price: string;
873+
};
874+
868875
export interface SrcSetItem {
869876
src: string;
870877
width: number;

0 commit comments

Comments
 (0)