Skip to content

Commit e1b3eba

Browse files
oliverabrahamscharleycampbellemma-imber
authored
Adding new Filter Button component (#13909)
* Adding new Filter Button component. Co-authored-by: Charley Campbell <[email protected]> Co-authored-by: Emma Imber <[email protected]>
1 parent 38b319b commit e1b3eba

File tree

6 files changed

+122
-0
lines changed

6 files changed

+122
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { ProductLinkButton } from './ProductLinkButton';
3+
4+
const meta = {
5+
component: ProductLinkButton,
6+
title: 'Components/ProductLinkButton',
7+
parameters: {
8+
layout: 'padded',
9+
},
10+
args: {
11+
label: '£6.50 for 350g at Ollie’s Kimchi',
12+
url: 'https://ollieskimchi.co.uk/shop/ols/products/ollies-kimchi',
13+
},
14+
} satisfies Meta<typeof ProductLinkButton>;
15+
16+
export default meta;
17+
18+
type Story = StoryObj<typeof meta>;
19+
20+
export const Default = {} satisfies Story;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
LinkButton,
3+
SvgArrowRightStraight,
4+
} from '@guardian/source/react-components';
5+
6+
type ProductLinkButtonProps = {
7+
label: string;
8+
url: string;
9+
};
10+
11+
export const ProductLinkButton = ({ label, url }: ProductLinkButtonProps) => {
12+
return (
13+
<LinkButton
14+
href={url}
15+
rel="sponsored"
16+
iconSide="right"
17+
aria-label={`Open ${label} in a new tab`}
18+
icon={<SvgArrowRightStraight />}
19+
data-ignore="global-link-styling"
20+
data-link-name="in body link"
21+
data-spacefinder-role="inline"
22+
>
23+
{label}
24+
</LinkButton>
25+
);
26+
};

dotcom-rendering/src/frontend/schemas/feArticle.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@
673673
{
674674
"$ref": "#/definitions/KeyTakeawaysBlockElement"
675675
},
676+
{
677+
"$ref": "#/definitions/LinkBlockElement"
678+
},
676679
{
677680
"$ref": "#/definitions/ListBlockElement"
678681
},
@@ -2497,6 +2500,31 @@
24972500
"title"
24982501
]
24992502
},
2503+
"LinkBlockElement": {
2504+
"type": "object",
2505+
"properties": {
2506+
"_type": {
2507+
"type": "string",
2508+
"const": "model.dotcomrendering.pageElements.LinkBlockElement"
2509+
},
2510+
"url": {
2511+
"type": "string"
2512+
},
2513+
"label": {
2514+
"type": "string"
2515+
},
2516+
"linkType": {
2517+
"type": "string",
2518+
"const": "ProductButton"
2519+
}
2520+
},
2521+
"required": [
2522+
"_type",
2523+
"label",
2524+
"linkType",
2525+
"url"
2526+
]
2527+
},
25002528
"ListBlockElement": {
25012529
"type": "object",
25022530
"properties": {

dotcom-rendering/src/lib/renderElement.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { MultiBylines } from '../components/MultiBylines';
3636
import { MultiImageBlockComponent } from '../components/MultiImageBlockComponent';
3737
import { NumberedTitleBlockComponent } from '../components/NumberedTitleBlockComponent';
3838
import { PersonalityQuizAtom } from '../components/PersonalityQuizAtom.importable';
39+
import { ProductLinkButton } from '../components/ProductLinkButton';
3940
import { ProfileAtomWrapper } from '../components/ProfileAtomWrapper.importable';
4041
import { PullQuoteBlockComponent } from '../components/PullQuoteBlockComponent';
4142
import { QandaAtom } from '../components/QandaAtom.importable';
@@ -562,6 +563,17 @@ export const renderElement = ({
562563
/>
563564
</Island>
564565
);
566+
case 'model.dotcomrendering.pageElements.LinkBlockElement':
567+
return (
568+
<>
569+
{element.linkType === 'ProductButton' && (
570+
<ProductLinkButton
571+
label={element.label}
572+
url={element.url}
573+
/>
574+
)}
575+
</>
576+
);
565577
case 'model.dotcomrendering.pageElements.PullquoteBlockElement':
566578
return (
567579
<PullQuoteBlockComponent

dotcom-rendering/src/model/block-schema.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
{
163163
"$ref": "#/definitions/KeyTakeawaysBlockElement"
164164
},
165+
{
166+
"$ref": "#/definitions/LinkBlockElement"
167+
},
165168
{
166169
"$ref": "#/definitions/ListBlockElement"
167170
},
@@ -1986,6 +1989,31 @@
19861989
"title"
19871990
]
19881991
},
1992+
"LinkBlockElement": {
1993+
"type": "object",
1994+
"properties": {
1995+
"_type": {
1996+
"type": "string",
1997+
"const": "model.dotcomrendering.pageElements.LinkBlockElement"
1998+
},
1999+
"url": {
2000+
"type": "string"
2001+
},
2002+
"label": {
2003+
"type": "string"
2004+
},
2005+
"linkType": {
2006+
"type": "string",
2007+
"const": "ProductButton"
2008+
}
2009+
},
2010+
"required": [
2011+
"_type",
2012+
"label",
2013+
"linkType",
2014+
"url"
2015+
]
2016+
},
19892017
"ListBlockElement": {
19902018
"type": "object",
19912019
"properties": {

dotcom-rendering/src/types/content.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ export interface ListItem {
393393
bylineHtml?: string;
394394
}
395395

396+
export interface LinkBlockElement {
397+
_type: 'model.dotcomrendering.pageElements.LinkBlockElement';
398+
url: string;
399+
label: string;
400+
linkType: 'ProductButton';
401+
}
402+
396403
export interface ListBlockElement {
397404
_type: 'model.dotcomrendering.pageElements.ListBlockElement';
398405
listElementType:
@@ -792,6 +799,7 @@ export type FEElement =
792799
| InteractiveBlockElement
793800
| ItemLinkBlockElement
794801
| KeyTakeawaysBlockElement
802+
| LinkBlockElement
795803
| ListBlockElement
796804
| MapBlockElement
797805
| MediaAtomBlockElement

0 commit comments

Comments
 (0)