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..fe923378b0 --- /dev/null +++ b/packages/documentation/src/shared/click-blocker.ts @@ -0,0 +1,21 @@ +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) { + // Generate a custom ID in case there are multiple click blockers on the page + const id = crypto.randomUUID(); + setTimeout(() => { + const div = document.getElementById(id); + div?.addEventListener( + 'click', + e => { + e.stopPropagation(); + e.preventDefault(); + }, + { capture: true }, + ); + }, 0); + + return html`
${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..f1b801bc47 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`
@@ -223,9 +217,7 @@ function gridContainer(story: StoryFn, context: StoryContext) { // RENDERER function getCardLinks() { return html` - ${['Link Text', 'More Link'].map( - label => html` ${label} `, - )} + ${['Link Text', 'More Link'].map(label => html` ${label} `)} `; } @@ -243,7 +235,9 @@ function getCardBody({ customBody, content, action, showTitle, showSubtitle }: A return html`
${showTitle ? html`
Card Title
` : nothing} - ${showSubtitle ? html`
Card Subtitle
` : nothing} + ${showSubtitle + ? html`
Card Subtitle
` + : nothing}

${content}

${choose( action, @@ -314,7 +308,7 @@ const renderSimpleInteractiveCard = html` type Story = StoryObj; const singleCardStory: Story = { - decorators: [gridContainer], + decorators: [gridContainer, clickBlocker], render: (args: Args) => html`${args.action === 'button' ? renderCardWithInteractiveContainer(args) : renderCard(args)}`, }; @@ -324,7 +318,7 @@ export const Default: Story = { }; export const Foundation: Story = { - decorators: [story => html`
${story()}
`], + decorators: [story => html`
${story()}
`, clickBlocker], render: () => html`

Non-interactive card

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 1b453d7180..21866771fd 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 { Args, 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', @@ -247,6 +248,7 @@ export const Default: Story = { html`
${story()} ${fakeContent()}
`, + clickBlocker, ], }; @@ -255,5 +257,5 @@ export const WithTargetGroup: Story = { targetGroup: true, }, ...Template, - decorators: [story => html`
${story()}
`], + decorators: [story => html`
${story()}
`, 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/popover/popover.stories.ts b/packages/documentation/src/stories/components/popover/popover.stories.ts index 423cd3f824..24db6a17c4 100644 --- a/packages/documentation/src/stories/components/popover/popover.stories.ts +++ b/packages/documentation/src/stories/components/popover/popover.stories.ts @@ -2,6 +2,7 @@ import { Args, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; import { MetaComponent } from '@root/types'; +import { clickBlocker } from '@/shared/click-blocker'; const meta: MetaComponent = { id: '9a636763-de2d-4f72-bc81-98daf10871f7', @@ -53,7 +54,7 @@ const meta: MetaComponent = { 'Value can either be in `vw`, `px` or `%`. If no max-width is defined, the popover will extend to the width of its content.', table: { category: 'General', - defaultValue: { summary: '280px' } + defaultValue: { summary: '280px' }, }, }, palette: { @@ -91,6 +92,7 @@ const meta: MetaComponent = { name: 'Placement', }, }, + decorators: [clickBlocker], }; function render(args: Args) { 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`