From b0afe98489653d5f82c1e7d4eff4879a621f40bf Mon Sep 17 00:00:00 2001 From: leagrdv Date: Wed, 14 May 2025 16:54:33 +0200 Subject: [PATCH 1/2] chore(docs): add click blocker on stories --- .changeset/seven-cars-melt.md | 5 +++++ .../documentation/src/shared/click-blocker.ts | 9 +++++++++ .../app-store-badge.stories.ts | 2 ++ .../components/avatar/avatar.stories.ts | 2 ++ .../breadcrumb/breadcrumbs.stories.ts | 2 ++ .../button-group/button-group.stories.ts | 15 ++------------- .../components/button/button.stories.ts | 2 ++ .../card-product/card-product.stories.ts | 8 +------- .../stories/components/card/card.stories.ts | 8 +------- .../components/footer/footer.stories.ts | 2 ++ .../components/header/header.stories.ts | 3 ++- .../components/linkarea/linkarea.stories.ts | 2 ++ .../list-group/list-group.stories.ts | 3 ++- .../components/skiplinks/skiplinks.stories.ts | 2 ++ .../subnavigation/subnavigation.stories.ts | 10 ++-------- .../components/teaser/teaser.stories.ts | 2 ++ .../stories/foundations/logo/logo.stories.ts | 3 ++- .../breadcrumbs/breadcrumbs.stories.ts | 3 ++- .../raw-components/footer/footer.stories.ts | 3 ++- .../internet-header/header.stories.ts | 19 ++++++++++--------- .../megadropdown/megadropdown.stories.ts | 9 ++++++++- .../menu-button/menu-button.stories.ts | 2 ++ .../error-page/error-page.stories.ts | 12 ++++-------- .../stories/utilities/text/text.stories.ts | 3 ++- 24 files changed, 72 insertions(+), 59 deletions(-) create mode 100644 .changeset/seven-cars-melt.md create mode 100644 packages/documentation/src/shared/click-blocker.ts diff --git a/.changeset/seven-cars-melt.md b/.changeset/seven-cars-melt.md new file mode 100644 index 0000000000..979827945f --- /dev/null +++ b/.changeset/seven-cars-melt.md @@ -0,0 +1,5 @@ +--- +'@swisspost/design-system-documentation': patch +--- + +Added a click blocker decorator on all of the components that had links to prevent users being redirected to another page. diff --git a/packages/documentation/src/shared/click-blocker.ts b/packages/documentation/src/shared/click-blocker.ts new file mode 100644 index 0000000000..c836c49cc5 --- /dev/null +++ b/packages/documentation/src/shared/click-blocker.ts @@ -0,0 +1,9 @@ +import { StoryContext, StoryFn } from '@storybook/web-components'; +import { html } from 'lit'; + +// Click blocker decorator to prevent clicking on example links +export function clickBlocker(story: StoryFn, context: StoryContext) { + return html` +
e.preventDefault()}>${story(context.args, context)}
+ `; +} diff --git a/packages/documentation/src/stories/components/app-store-badge/app-store-badge.stories.ts b/packages/documentation/src/stories/components/app-store-badge/app-store-badge.stories.ts index ffec33c92c..b203017db9 100644 --- a/packages/documentation/src/stories/components/app-store-badge/app-store-badge.stories.ts +++ b/packages/documentation/src/stories/components/app-store-badge/app-store-badge.stories.ts @@ -1,11 +1,13 @@ import { StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: 'f1cda0ac-28d4-4afc-b56d-9182bd9bd671', title: 'Components/App Store Badge', tags: ['package:HTML'], + decorators: [clickBlocker], parameters: { badges: [], design: { diff --git a/packages/documentation/src/stories/components/avatar/avatar.stories.ts b/packages/documentation/src/stories/components/avatar/avatar.stories.ts index d7854c2561..0fb3c78d84 100644 --- a/packages/documentation/src/stories/components/avatar/avatar.stories.ts +++ b/packages/documentation/src/stories/components/avatar/avatar.stories.ts @@ -2,6 +2,7 @@ import { Args, StoryContext, StoryObj } from '@storybook/web-components'; import { MetaComponent } from '@root/types'; import { html, nothing } from 'lit'; import { components } from '@swisspost/design-system-components/dist/docs.json'; +import { clickBlocker } from '@/shared/click-blocker'; const AVATAR_ARGTYPES = components.find(c => c.tag === 'post-avatar'); const USERID_ARGTYPE = AVATAR_ARGTYPES?.props.find(p => p.name === 'userid'); @@ -75,6 +76,7 @@ export const Default: Story = { }; export const AnchorWrapped: Story = { + decorators: [clickBlocker], render: (args: Args, context: StoryContext) => { return html`${Default.render?.(args, context)}`; }, diff --git a/packages/documentation/src/stories/components/breadcrumb/breadcrumbs.stories.ts b/packages/documentation/src/stories/components/breadcrumb/breadcrumbs.stories.ts index a60cb42f8d..ee4a767c41 100644 --- a/packages/documentation/src/stories/components/breadcrumb/breadcrumbs.stories.ts +++ b/packages/documentation/src/stories/components/breadcrumb/breadcrumbs.stories.ts @@ -1,11 +1,13 @@ import type { Args, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: 'b7db7391-f893-4b1e-a125-b30c6f0b028b', title: 'Components/Breadcrumbs', tags: ['package:WebComponents'], + decorators: [clickBlocker], parameters: { badges: [], design: { diff --git a/packages/documentation/src/stories/components/button-group/button-group.stories.ts b/packages/documentation/src/stories/components/button-group/button-group.stories.ts index 93b0bbbd8c..29d8be5328 100644 --- a/packages/documentation/src/stories/components/button-group/button-group.stories.ts +++ b/packages/documentation/src/stories/components/button-group/button-group.stories.ts @@ -2,6 +2,7 @@ import type { Args, StoryContext, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { useArgs } from '@storybook/preview-api'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: '021d61aa-e039-4858-b4b9-b86a3e772811', @@ -127,19 +128,7 @@ const meta: MetaComponent = { }, }, }, - decorators: [ - story => - html` -
- ${story()} -
- `, - ], + decorators: [clickBlocker], }; export default meta; diff --git a/packages/documentation/src/stories/components/button/button.stories.ts b/packages/documentation/src/stories/components/button/button.stories.ts index be006877d7..56fd65da2d 100644 --- a/packages/documentation/src/stories/components/button/button.stories.ts +++ b/packages/documentation/src/stories/components/button/button.stories.ts @@ -3,11 +3,13 @@ import { html, unsafeStatic } from 'lit/static-html.js'; import { spread } from '@open-wc/lit-helpers'; import { repeat } from 'lit/directives/repeat.js'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: 'eb78afcb-ce92-4990-94b6-6536d5ec6af4', title: 'Components/Button', tags: ['package:HTML'], + decorators: [clickBlocker], parameters: { badges: [], design: { diff --git a/packages/documentation/src/stories/components/card-product/card-product.stories.ts b/packages/documentation/src/stories/components/card-product/card-product.stories.ts index 350cd3e64e..49c10b15cb 100644 --- a/packages/documentation/src/stories/components/card-product/card-product.stories.ts +++ b/packages/documentation/src/stories/components/card-product/card-product.stories.ts @@ -2,6 +2,7 @@ import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-compo import { html, unsafeStatic } from 'lit/static-html.js'; import { nothing } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: 'b4800d9e-4837-4476-a327-bb4586eb7e97', @@ -58,13 +59,6 @@ const meta: MetaComponent = { export default meta; -// DECORATORS -function clickBlocker(story: StoryFn, context: StoryContext) { - return html` -
e.preventDefault()}>${story(context.args, context)}
- `; -} - function paddedContainer(story: StoryFn, context: StoryContext) { return html`
${story(context.args, context)}
`; } diff --git a/packages/documentation/src/stories/components/card/card.stories.ts b/packages/documentation/src/stories/components/card/card.stories.ts index 2cab6edbfd..146d009e9d 100644 --- a/packages/documentation/src/stories/components/card/card.stories.ts +++ b/packages/documentation/src/stories/components/card/card.stories.ts @@ -3,6 +3,7 @@ import { html, nothing } from 'lit'; import { choose } from 'lit/directives/choose.js'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: '605c788d-3f75-4e6c-8498-be3d546843c2', @@ -205,13 +206,6 @@ const meta: MetaComponent = { export default meta; -// DECORATORS -function clickBlocker(story: StoryFn, context: StoryContext) { - return html` -
e.preventDefault()}>${story(context.args, context)}
- `; -} - function gridContainer(story: StoryFn, context: StoryContext) { return html`
diff --git a/packages/documentation/src/stories/components/footer/footer.stories.ts b/packages/documentation/src/stories/components/footer/footer.stories.ts index 320cb2f2ec..195525498f 100644 --- a/packages/documentation/src/stories/components/footer/footer.stories.ts +++ b/packages/documentation/src/stories/components/footer/footer.stories.ts @@ -1,6 +1,7 @@ import { Args, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const GRID_CELLS = [1, 2, 3, 4]; const LINKS_PER_CELL = [6, 8, 8, 5]; @@ -10,6 +11,7 @@ const meta: MetaComponent = { title: 'Components/Footer', component: 'post-footer', tags: ['package:WebComponents'], + decorators: [clickBlocker], parameters: { layout: 'fullscreen', badges: [], diff --git a/packages/documentation/src/stories/components/header/header.stories.ts b/packages/documentation/src/stories/components/header/header.stories.ts index cd4f75723a..bff3cce0b0 100644 --- a/packages/documentation/src/stories/components/header/header.stories.ts +++ b/packages/documentation/src/stories/components/header/header.stories.ts @@ -2,6 +2,7 @@ import type { StoryObj } from '@storybook/web-components'; import { MetaComponent } from '@root/types'; import { html } from 'lit'; import { fakeContent } from '@/utils'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: '27a2e64d-55ba-492d-ab79-5f7c5e818498', @@ -57,7 +58,7 @@ const meta: MetaComponent = { story => html`
${story()} ${fakeContent()}
-
`, +
`, clickBlocker ], }; diff --git a/packages/documentation/src/stories/components/linkarea/linkarea.stories.ts b/packages/documentation/src/stories/components/linkarea/linkarea.stories.ts index a7552188c7..972d5843a9 100644 --- a/packages/documentation/src/stories/components/linkarea/linkarea.stories.ts +++ b/packages/documentation/src/stories/components/linkarea/linkarea.stories.ts @@ -1,6 +1,7 @@ import type { Args, StoryObj } from '@storybook/web-components'; import { html, nothing } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; export interface PostLinkarea { dataLink?: boolean; @@ -14,6 +15,7 @@ const meta: MetaComponent = { tags: ['package:WebComponents'], render: renderLinkarea, component: 'post-linkarea', + decorators: [clickBlocker], parameters: { design: {}, }, diff --git a/packages/documentation/src/stories/components/list-group/list-group.stories.ts b/packages/documentation/src/stories/components/list-group/list-group.stories.ts index 3e8bf5ab93..3cd10ccf7d 100644 --- a/packages/documentation/src/stories/components/list-group/list-group.stories.ts +++ b/packages/documentation/src/stories/components/list-group/list-group.stories.ts @@ -1,13 +1,14 @@ import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: '5a47ba70-7831-4e59-b83e-81b6e6c32372', title: 'Components/List Group', tags: ['package:HTML'], render: renderListGroup, - decorators: [gridDecorator], + decorators: [gridDecorator, clickBlocker], parameters: { design: { type: 'figma', diff --git a/packages/documentation/src/stories/components/skiplinks/skiplinks.stories.ts b/packages/documentation/src/stories/components/skiplinks/skiplinks.stories.ts index aa14b2b864..11843d08f6 100644 --- a/packages/documentation/src/stories/components/skiplinks/skiplinks.stories.ts +++ b/packages/documentation/src/stories/components/skiplinks/skiplinks.stories.ts @@ -1,11 +1,13 @@ import type { StoryObj } from '@storybook/web-components'; import { html } from 'lit/static-html.js'; import { MetaExtended } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaExtended = { id: '2fc3b456-19ba-4ede-b1bc-499518f829b1', title: 'Components/Skiplinks', tags: ['package:HTML'], + decorators: [clickBlocker], render: renderSkiplinks, }; diff --git a/packages/documentation/src/stories/components/subnavigation/subnavigation.stories.ts b/packages/documentation/src/stories/components/subnavigation/subnavigation.stories.ts index 8229f2ae73..d7d06f0d50 100644 --- a/packages/documentation/src/stories/components/subnavigation/subnavigation.stories.ts +++ b/packages/documentation/src/stories/components/subnavigation/subnavigation.stories.ts @@ -1,6 +1,7 @@ -import { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; +import { Args, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: '87ceabbb-f552-46eb-8a47-4d84e7f8cef0', @@ -54,13 +55,6 @@ const meta: MetaComponent = { export default meta; -// DECORATOR -function clickBlocker(story: StoryFn, context: StoryContext) { - return html` -
e.preventDefault()}>${story(context.args, context)}
- `; -} - function renderTest(args: Args) { return html`