Skip to content

Commit b0afe98

Browse files
committed
chore(docs): add click blocker on stories
1 parent 49bf275 commit b0afe98

File tree

24 files changed

+72
-59
lines changed

24 files changed

+72
-59
lines changed

.changeset/seven-cars-melt.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@swisspost/design-system-documentation': patch
3+
---
4+
5+
Added a click blocker decorator on all of the components that had links to prevent users being redirected to another page.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { StoryContext, StoryFn } from '@storybook/web-components';
2+
import { html } from 'lit';
3+
4+
// Click blocker decorator to prevent clicking on example links
5+
export function clickBlocker(story: StoryFn, context: StoryContext) {
6+
return html`
7+
<div @click=${(e: Event) => e.preventDefault()}>${story(context.args, context)}</div>
8+
`;
9+
}

packages/documentation/src/stories/components/app-store-badge/app-store-badge.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent = {
67
id: 'f1cda0ac-28d4-4afc-b56d-9182bd9bd671',
78
title: 'Components/App Store Badge',
89
tags: ['package:HTML'],
10+
decorators: [clickBlocker],
911
parameters: {
1012
badges: [],
1113
design: {

packages/documentation/src/stories/components/avatar/avatar.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Args, StoryContext, StoryObj } from '@storybook/web-components';
22
import { MetaComponent } from '@root/types';
33
import { html, nothing } from 'lit';
44
import { components } from '@swisspost/design-system-components/dist/docs.json';
5+
import { clickBlocker } from '@/shared/click-blocker';
56

67
const AVATAR_ARGTYPES = components.find(c => c.tag === 'post-avatar');
78
const USERID_ARGTYPE = AVATAR_ARGTYPES?.props.find(p => p.name === 'userid');
@@ -75,6 +76,7 @@ export const Default: Story = {
7576
};
7677

7778
export const AnchorWrapped: Story = {
79+
decorators: [clickBlocker],
7880
render: (args: Args, context: StoryContext) => {
7981
return html`<a href="#">${Default.render?.(args, context)}</a>`;
8082
},

packages/documentation/src/stories/components/breadcrumb/breadcrumbs.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { Args, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent = {
67
id: 'b7db7391-f893-4b1e-a125-b30c6f0b028b',
78
title: 'Components/Breadcrumbs',
89
tags: ['package:WebComponents'],
10+
decorators: [clickBlocker],
911
parameters: {
1012
badges: [],
1113
design: {

packages/documentation/src/stories/components/button-group/button-group.stories.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Args, StoryContext, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { useArgs } from '@storybook/preview-api';
44
import { MetaComponent } from '@root/types';
5+
import { clickBlocker } from '@/shared/click-blocker';
56

67
const meta: MetaComponent = {
78
id: '021d61aa-e039-4858-b4b9-b86a3e772811',
@@ -127,19 +128,7 @@ const meta: MetaComponent = {
127128
},
128129
},
129130
},
130-
decorators: [
131-
story =>
132-
html`
133-
<div
134-
@click="${(e: Event) => {
135-
const target = e.target as HTMLElement;
136-
if (target.tagName === 'A' || target.tagName === 'BUTTON') e.preventDefault();
137-
}}"
138-
>
139-
${story()}
140-
</div>
141-
`,
142-
],
131+
decorators: [clickBlocker],
143132
};
144133

145134
export default meta;

packages/documentation/src/stories/components/button/button.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { html, unsafeStatic } from 'lit/static-html.js';
33
import { spread } from '@open-wc/lit-helpers';
44
import { repeat } from 'lit/directives/repeat.js';
55
import { MetaComponent } from '@root/types';
6+
import { clickBlocker } from '@/shared/click-blocker';
67

78
const meta: MetaComponent = {
89
id: 'eb78afcb-ce92-4990-94b6-6536d5ec6af4',
910
title: 'Components/Button',
1011
tags: ['package:HTML'],
12+
decorators: [clickBlocker],
1113
parameters: {
1214
badges: [],
1315
design: {

packages/documentation/src/stories/components/card-product/card-product.stories.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-compo
22
import { html, unsafeStatic } from 'lit/static-html.js';
33
import { nothing } from 'lit';
44
import { MetaComponent } from '@root/types';
5+
import { clickBlocker } from '@/shared/click-blocker';
56

67
const meta: MetaComponent = {
78
id: 'b4800d9e-4837-4476-a327-bb4586eb7e97',
@@ -58,13 +59,6 @@ const meta: MetaComponent = {
5859

5960
export default meta;
6061

61-
// DECORATORS
62-
function clickBlocker(story: StoryFn, context: StoryContext) {
63-
return html`
64-
<div @click=${(e: Event) => e.preventDefault()}>${story(context.args, context)}</div>
65-
`;
66-
}
67-
6862
function paddedContainer(story: StoryFn, context: StoryContext) {
6963
return html` <div class="p-8">${story(context.args, context)}</div> `;
7064
}

packages/documentation/src/stories/components/card/card.stories.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { html, nothing } from 'lit';
33
import { choose } from 'lit/directives/choose.js';
44
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
55
import { MetaComponent } from '@root/types';
6+
import { clickBlocker } from '@/shared/click-blocker';
67

78
const meta: MetaComponent = {
89
id: '605c788d-3f75-4e6c-8498-be3d546843c2',
@@ -205,13 +206,6 @@ const meta: MetaComponent = {
205206

206207
export default meta;
207208

208-
// DECORATORS
209-
function clickBlocker(story: StoryFn, context: StoryContext) {
210-
return html`
211-
<div @click=${(e: Event) => e.preventDefault()}>${story(context.args, context)}</div>
212-
`;
213-
}
214-
215209
function gridContainer(story: StoryFn, context: StoryContext) {
216210
return html`
217211
<div class="row gy-16">

packages/documentation/src/stories/components/footer/footer.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Args, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const GRID_CELLS = [1, 2, 3, 4];
67
const LINKS_PER_CELL = [6, 8, 8, 5];
@@ -10,6 +11,7 @@ const meta: MetaComponent = {
1011
title: 'Components/Footer',
1112
component: 'post-footer',
1213
tags: ['package:WebComponents'],
14+
decorators: [clickBlocker],
1315
parameters: {
1416
layout: 'fullscreen',
1517
badges: [],

packages/documentation/src/stories/components/header/header.stories.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { StoryObj } from '@storybook/web-components';
22
import { MetaComponent } from '@root/types';
33
import { html } from 'lit';
44
import { fakeContent } from '@/utils';
5+
import { clickBlocker } from '@/shared/click-blocker';
56

67
const meta: MetaComponent = {
78
id: '27a2e64d-55ba-492d-ab79-5f7c5e818498',
@@ -57,7 +58,7 @@ const meta: MetaComponent = {
5758
story =>
5859
html` <div class="header-story-wrapper">
5960
<div class="virtual-body">${story()} ${fakeContent()}</div>
60-
</div>`,
61+
</div>`, clickBlocker
6162
],
6263
};
6364

packages/documentation/src/stories/components/linkarea/linkarea.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Args, StoryObj } from '@storybook/web-components';
22
import { html, nothing } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
export interface PostLinkarea {
67
dataLink?: boolean;
@@ -14,6 +15,7 @@ const meta: MetaComponent<PostLinkarea> = {
1415
tags: ['package:WebComponents'],
1516
render: renderLinkarea,
1617
component: 'post-linkarea',
18+
decorators: [clickBlocker],
1719
parameters: {
1820
design: {},
1921
},

packages/documentation/src/stories/components/list-group/list-group.stories.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent = {
67
id: '5a47ba70-7831-4e59-b83e-81b6e6c32372',
78
title: 'Components/List Group',
89
tags: ['package:HTML'],
910
render: renderListGroup,
10-
decorators: [gridDecorator],
11+
decorators: [gridDecorator, clickBlocker],
1112
parameters: {
1213
design: {
1314
type: 'figma',

packages/documentation/src/stories/components/skiplinks/skiplinks.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { StoryObj } from '@storybook/web-components';
22
import { html } from 'lit/static-html.js';
33
import { MetaExtended } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaExtended = {
67
id: '2fc3b456-19ba-4ede-b1bc-499518f829b1',
78
title: 'Components/Skiplinks',
89
tags: ['package:HTML'],
10+
decorators: [clickBlocker],
911
render: renderSkiplinks,
1012
};
1113

packages/documentation/src/stories/components/subnavigation/subnavigation.stories.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components';
1+
import { Args, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent = {
67
id: '87ceabbb-f552-46eb-8a47-4d84e7f8cef0',
@@ -54,13 +55,6 @@ const meta: MetaComponent = {
5455

5556
export default meta;
5657

57-
// DECORATOR
58-
function clickBlocker(story: StoryFn, context: StoryContext) {
59-
return html`
60-
<div @click=${(e: Event) => e.preventDefault()}>${story(context.args, context)}</div>
61-
`;
62-
}
63-
6458
function renderTest(args: Args) {
6559
return html`
6660
<div class="subnavigation ${args.palette}">

packages/documentation/src/stories/components/teaser/teaser.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Args, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent = {
67
id: '68699b2c-ec1f-467d-81ae-8b3f48d7c595',
78
title: 'Components/Card Teaser',
9+
decorators: [clickBlocker],
810
tags: ['package:HTML'],
911
parameters: {
1012
design: {

packages/documentation/src/stories/foundations/logo/logo.stories.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { StoryContext, StoryFn, StoryObj } from '@storybook/web-components';
22
import { html, nothing } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent<HTMLPostLogoElement> = {
67
id: '73066e1c-0720-4a9b-8f81-a29d4250872a',
@@ -56,7 +57,7 @@ export const Link: Story = {
5657
url: 'https://www.post.ch/en',
5758
},
5859
render: renderLogo('the homepage'),
59-
decorators: [containerWithHeight],
60+
decorators: [containerWithHeight, clickBlocker],
6061
};
6162

6263
export const Height: Story = {

packages/documentation/src/stories/raw-components/breadcrumbs/breadcrumbs.stories.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { spread } from '@open-wc/lit-helpers';
44
import { getAttributes } from '@/utils';
55
import customItems from './custom-items';
66
import { MetaComponent } from '@root/types';
7+
import { clickBlocker } from '@/shared/click-blocker';
78

89
const meta: MetaComponent<HTMLSwisspostInternetBreadcrumbsElement> = {
910
id: '4347e5bf-8bf2-4f44-9075-9faaa53591ed',
1011
title: 'Raw Components/Internet Header/Breadcrumbs',
1112
component: 'swisspost-internet-breadcrumbs',
1213
tags: ['package:InternetHeader'],
1314
render: renderInternetBreadcrumbs,
14-
decorators: [hiddenHeader],
15+
decorators: [hiddenHeader, clickBlocker],
1516
parameters: {
1617
badges: [],
1718
design: {

packages/documentation/src/stories/raw-components/footer/footer.stories.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { html } from 'lit';
33
import customFooterConfig from './custom-footer-config';
44
import { spread } from '@open-wc/lit-helpers';
55
import { MetaComponent } from '@root/types';
6+
import { clickBlocker } from '@/shared/click-blocker';
67

78
const meta: MetaComponent = {
89
id: '27fc009d-3eec-43a9-b3a2-55531e721817',
910
title: 'Raw Components/Internet Header/Footer',
1011
component: 'swisspost-internet-footer',
1112
tags: ['package:InternetHeader'],
1213
render: renderInternetFooter,
13-
decorators: [hiddenHeader],
14+
decorators: [hiddenHeader, clickBlocker],
1415
parameters: {
1516
layout: 'fullscreen',
1617
badges: [],

packages/documentation/src/stories/raw-components/internet-header/header.stories.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import customConfig from './config/custom-config';
55
import osFlyoutOverrides from './config/os-flyout-overrides';
66
import languageSwitchOverrides from './config/language-switch-overrides';
77
import { MetaComponent } from '@root/types';
8+
import { clickBlocker } from '@/shared/click-blocker';
89

910
const meta: MetaComponent = {
1011
id: 'ebb11274-091b-4cb7-9a3f-3e0451c9a865',
@@ -158,15 +159,15 @@ const meta: MetaComponent = {
158159
},
159160
},
160161
decorators: [
161-
story =>
162-
html`
163-
<div
164-
class="header-story-wrapper"
165-
style="--header-z-index: 1;overflow: auto;max-height: 100svh;"
166-
>
167-
${story()} ${fakeContent()}
168-
</div>
169-
`,
162+
story => html`
163+
<div
164+
class="header-story-wrapper"
165+
style="--header-z-index: 1;overflow: auto;max-height: 100svh;"
166+
>
167+
${story()} ${fakeContent()}
168+
</div>
169+
`,
170+
clickBlocker,
170171
],
171172
};
172173

packages/documentation/src/stories/raw-components/megadropdown/megadropdown.stories.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33
import { MetaComponent } from '@root/types';
44
import { StoryContext, StoryFn } from '@storybook/web-components';
5+
import { clickBlocker } from '@/shared/click-blocker';
56

67
const meta: MetaComponent<HTMLPostMegadropdownElement> = {
78
id: '212efc4e-875b-4497-912d-d28c6baf32f5',
@@ -81,7 +82,13 @@ export function megadropdownDecorator(story: StoryFn, context: StoryContext) {
8182
</button>
8283
<post-list title-hidden="">
8384
<h2>Main Navigation</h2>
85+
<<<<<<< Updated upstream
8486
<post-list-item> ${story(context.args, context)} </post-list-item>
87+
=======
88+
<post-list-item>
89+
${story(context.args, context)}
90+
</post-list-item>
91+
>>>>>>> Stashed changes
8592
</post-list>
8693
</post-mainnavigation>
8794
</post-header>
@@ -124,7 +131,7 @@ function render() {
124131
type Story = StoryObj<HTMLPostLanguageOptionElement>;
125132

126133
export const Default: Story = {
127-
decorators: [megadropdownDecorator],
134+
decorators: [megadropdownDecorator, clickBlocker],
128135
};
129136

130137
// No decorators on the test page

packages/documentation/src/stories/raw-components/menu-button/menu-button.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Args, StoryObj } from '@storybook/web-components';
22
import { html, nothing } from 'lit';
33
import { MetaComponent } from '@root/types';
4+
import { clickBlocker } from '@/shared/click-blocker';
45

56
const meta: MetaComponent = {
67
id: '8ca2bd70-56e6-4da9-b1fd-4e55388dca88',
78
title: 'Raw Components/Menu Button',
89
tags: ['package:WebComponents'],
910
component: 'post-menu',
11+
decorators: [clickBlocker],
1012
parameters: {
1113
design: {},
1214
},

0 commit comments

Comments
 (0)