From 3985ccbbbc1eb08350092b03a3c944c8c46c60f7 Mon Sep 17 00:00:00 2001 From: Tommmaso Menga Date: Tue, 20 Feb 2024 15:24:30 +0100 Subject: [PATCH 01/39] refactor(link): split variants --- .../block-link-button.spec.ts | 61 ++++++++++++ .../block-link-button/block-link-button.ts | 22 +++++ .../link/block-link-button/index.ts | 1 + .../link/block-link-button/readme.md | 73 +++++++++++++++ .../block-link-static.spec.ts | 51 ++++++++++ .../block-link-static/block-link-static.ts | 22 +++++ .../link/block-link-static/index.ts | 1 + .../link/block-link-static/readme.md | 62 +++++++++++++ .../link/block-link/block-link.spec.ts | 50 ++++++++++ src/components/link/block-link/block-link.ts | 22 +++++ src/components/link/block-link/index.ts | 1 + src/components/link/block-link/readme.md | 72 +++++++++++++++ .../link/common/block-link-common.ts | 45 +++++++++ src/components/link/common/block-link.scss | 47 ++++++++++ src/components/link/common/index.ts | 2 + .../link/common/inline-link-common.ts | 26 ++++++ src/components/link/common/inline-link.scss | 22 +++++ .../link/common/link-common-stories.ts | 11 --- src/components/link/common/link-common.ts | 28 +----- src/components/link/common/link.scss | 60 ++---------- src/components/link/index.ts | 3 + .../link/link-button/link-button.spec.ts | 92 +------------------ .../link/link-button/link-button.stories.ts | 21 ++++- .../link/link-button/link-button.ts | 4 +- .../link/link-static/link-static.spec.ts | 85 +---------------- .../link/link-static/link-static.stories.ts | 21 ++++- .../link/link-static/link-static.ts | 4 +- src/components/link/link/link.spec.ts | 51 +--------- src/components/link/link/link.stories.ts | 21 ++++- src/components/link/link/link.ts | 4 +- 30 files changed, 660 insertions(+), 325 deletions(-) create mode 100644 src/components/link/block-link-button/block-link-button.spec.ts create mode 100644 src/components/link/block-link-button/block-link-button.ts create mode 100644 src/components/link/block-link-button/index.ts create mode 100644 src/components/link/block-link-button/readme.md create mode 100644 src/components/link/block-link-static/block-link-static.spec.ts create mode 100644 src/components/link/block-link-static/block-link-static.ts create mode 100644 src/components/link/block-link-static/index.ts create mode 100644 src/components/link/block-link-static/readme.md create mode 100644 src/components/link/block-link/block-link.spec.ts create mode 100644 src/components/link/block-link/block-link.ts create mode 100644 src/components/link/block-link/index.ts create mode 100644 src/components/link/block-link/readme.md create mode 100644 src/components/link/common/block-link-common.ts create mode 100644 src/components/link/common/block-link.scss create mode 100644 src/components/link/common/inline-link-common.ts create mode 100644 src/components/link/common/inline-link.scss diff --git a/src/components/link/block-link-button/block-link-button.spec.ts b/src/components/link/block-link-button/block-link-button.spec.ts new file mode 100644 index 0000000000..09cde7102e --- /dev/null +++ b/src/components/link/block-link-button/block-link-button.spec.ts @@ -0,0 +1,61 @@ +import { expect, fixture } from '@open-wc/testing'; +import { html } from 'lit/static-html.js'; + +import { waitForLitRender } from '../../core/testing'; + +import './block-link-button'; + +describe('sbb-block-link-button', () => { + it('renders a negative link-button with provided icon', async () => { + const root = await fixture( + html` + + Travelcards & tickets. + `, + ); + + await waitForLitRender(root); + + expect(root).dom.to.be.equal(` + + + + Travelcards & tickets. + + `); + expect(root).shadowDom.to.be.equal(` + + + + + + + `); + }); +}); diff --git a/src/components/link/block-link-button/block-link-button.ts b/src/components/link/block-link-button/block-link-button.ts new file mode 100644 index 0000000000..eee5600c7f --- /dev/null +++ b/src/components/link/block-link-button/block-link-button.ts @@ -0,0 +1,22 @@ +import { customElement } from 'lit/decorators.js'; + +import { SbbButtonBaseElement, SbbDisabledTabIndexActionMixin } from '../../core/common-behaviors'; +import { SbbBlockLinkCommonElementMixin } from '../common'; + +/** + * It displays a link enhanced with the SBB Design, which will behave as a button. + * + * @slot - Use the unnamed slot to add content to the `sbb-link-button`. + * @slot icon - Slot used to display the icon, if one is set. + */ +@customElement('sbb-block-link-button') +export class SbbBlockLinkButtonElement extends SbbBlockLinkCommonElementMixin( + SbbDisabledTabIndexActionMixin(SbbButtonBaseElement), +) {} + +declare global { + interface HTMLElementTagNameMap { + // eslint-disable-next-line @typescript-eslint/naming-convention + 'sbb-block-link-button': SbbBlockLinkButtonElement; + } +} diff --git a/src/components/link/block-link-button/index.ts b/src/components/link/block-link-button/index.ts new file mode 100644 index 0000000000..47b0bfd8b1 --- /dev/null +++ b/src/components/link/block-link-button/index.ts @@ -0,0 +1 @@ +export * from './block-link-button'; diff --git a/src/components/link/block-link-button/readme.md b/src/components/link/block-link-button/readme.md new file mode 100644 index 0000000000..c85cd2846e --- /dev/null +++ b/src/components/link/block-link-button/readme.md @@ -0,0 +1,73 @@ +The `sbb-link-button` component provides the same functionality as a native ` `); @@ -33,12 +33,12 @@ describe('sbb-skiplink-list', () => { expect(listItemLinks[0]).to.have.style('height', '0px'); expect(listItemLinks[0]).to.have.style('overflow', 'hidden'); - const firstLink: SbbLinkElement = element.querySelector('sbb-link:nth-child(1)')!; + const firstLink: SbbBlockLinkElement = element.querySelector('sbb-block-link:nth-child(1)')!; firstLink.focus(); expect(listItemLinks[0]).not.to.have.style('height', '0px'); expect(listItemLinks[0]).to.have.style('overflow', 'visible'); - const secondLink: SbbLinkElement = element.querySelector('sbb-link:nth-child(2)')!; + const secondLink: SbbBlockLinkElement = element.querySelector('sbb-block-link:nth-child(2)')!; secondLink.focus(); expect(listItemLinks[0]).to.have.style('height', '0px'); expect(listItemLinks[0]).to.have.style('overflow', 'hidden'); @@ -50,11 +50,11 @@ describe('sbb-skiplink-list', () => { element = await fixture(html``); element.innerHTML = ` - Link 1 - Link 2`; + Link 1 + Link 2`; await waitForLitRender(element); - expect(element.querySelector('sbb-link')).to.have.attribute('slot'); + expect(element.querySelector('sbb-block-link')).to.have.attribute('slot'); }); }); diff --git a/src/components/skiplink-list/skiplink-list.scss b/src/components/skiplink-list/skiplink-list.scss index 4630470f80..13a88223d7 100644 --- a/src/components/skiplink-list/skiplink-list.scss +++ b/src/components/skiplink-list/skiplink-list.scss @@ -40,7 +40,7 @@ } } -::slotted(:is(sbb-link, sbb-link-button)) { +::slotted(:is(sbb-link, sbb-link-button, sbb-block-link, sbb-block-link-button)) { --sbb-focus-outline-color: transparent; --sbb-link-padding: var(--sbb-spacing-fixed-2x) var(--sbb-spacing-responsive-xxs); } diff --git a/src/components/skiplink-list/skiplink-list.spec.ts b/src/components/skiplink-list/skiplink-list.spec.ts index 28be72fe39..b9bd93151b 100644 --- a/src/components/skiplink-list/skiplink-list.spec.ts +++ b/src/components/skiplink-list/skiplink-list.spec.ts @@ -15,9 +15,9 @@ describe('sbb-skiplink-list', () => { beforeEach(async () => { element = await fixture(html` - Link 1 - Link 2 - Link 3 + Link 1 + Link 2 + Link 3 `); await waitForLitRender(element); @@ -38,9 +38,9 @@ describe('sbb-skiplink-list', () => { beforeEach(async () => { element = await fixture(html` - Link 1 - Link 2 - Link 3 + Link 1 + Link 2 + Link 3 `); await waitForLitRender(element); diff --git a/src/components/skiplink-list/skiplink-list.stories.ts b/src/components/skiplink-list/skiplink-list.stories.ts index b64c4d6ed3..659e2066ae 100644 --- a/src/components/skiplink-list/skiplink-list.stories.ts +++ b/src/components/skiplink-list/skiplink-list.stories.ts @@ -116,8 +116,8 @@ const Template = ({ ...args }: Args): TemplateResult => html` - ${labelFirstLink} - ${labelSecondLink} + ${labelFirstLink} + ${labelSecondLink} `; diff --git a/src/components/skiplink-list/skiplink-list.ts b/src/components/skiplink-list/skiplink-list.ts index d8affb581f..8d1baf9571 100644 --- a/src/components/skiplink-list/skiplink-list.ts +++ b/src/components/skiplink-list/skiplink-list.ts @@ -13,7 +13,12 @@ import { SbbNamedSlotListElementMixin, type WithListChildren, } from '../core/common-behaviors'; -import type { SbbLinkElement, SbbLinkButtonElement } from '../link'; +import type { + SbbLinkElement, + SbbLinkButtonElement, + SbbBlockLinkElement, + SbbBlockLinkButtonElement, +} from '../link'; import type { SbbTitleLevel } from '../title'; import style from './skiplink-list.scss?lit&inline'; @@ -27,11 +32,16 @@ import '../title'; */ @customElement('sbb-skiplink-list') export class SbbSkiplinkListElement extends SbbNamedSlotListElementMixin< - SbbLinkElement | SbbLinkButtonElement, + SbbLinkElement | SbbLinkButtonElement | SbbBlockLinkElement | SbbBlockLinkButtonElement, typeof LitElement >(LitElement) { public static override styles: CSSResultGroup = style; - protected override readonly listChildTagNames = ['SBB-LINK', 'SBB-LINK-BUTTON']; + protected override readonly listChildTagNames = [ + 'SBB-LINK', + 'SBB-LINK-BUTTON', + 'SBB-BLOCK-LINK', + 'SBB-BLOCK-LINK-BUTTON', + ]; /** The title text we want to place before the list. */ @property({ attribute: 'title-content', reflect: true }) public titleContent?: string; diff --git a/src/components/teaser-hero/__snapshots__/teaser-hero.spec.snap.js b/src/components/teaser-hero/__snapshots__/teaser-hero.spec.snap.js index d01932cb13..23ad003863 100644 --- a/src/components/teaser-hero/__snapshots__/teaser-hero.spec.snap.js +++ b/src/components/teaser-hero/__snapshots__/teaser-hero.spec.snap.js @@ -13,7 +13,7 @@ snapshots["sbb-teaser-hero should render with slots"] =

- - + @@ -65,7 +64,7 @@ snapshots["sbb-teaser-hero should render all properties ShadowDom"] =

- Find out more - +

${this.href - ? html` ${this.linkContent} - ` + ` : nothing} diff --git a/src/components/toast/toast.e2e.ts b/src/components/toast/toast.e2e.ts index 948991eb6e..d1c60e9d69 100644 --- a/src/components/toast/toast.e2e.ts +++ b/src/components/toast/toast.e2e.ts @@ -130,12 +130,11 @@ describe('sbb-toast', () => { it('forces state on link actions', async () => { element = await fixture(html` - + `); - const actionLink = element.querySelector('sbb-link'); + const actionLink = element.querySelector('sbb-link-button'); - expect(actionLink).to.have.attribute('variant', 'inline'); expect(actionLink).to.have.attribute('negative'); }); diff --git a/src/components/toast/toast.ts b/src/components/toast/toast.ts index 793761dad0..f8eca91a1e 100644 --- a/src/components/toast/toast.ts +++ b/src/components/toast/toast.ts @@ -193,7 +193,7 @@ export class SbbToastElement extends SbbIconNameMixin(LitElement) { btn.size = 'm'; }); - // Force the visual state on slotted links + // Force negative on inline slotted links const links = slotNodes.filter((el) => ['SBB-LINK', 'SBB-LINK-BUTTON', 'SBB-LINK-STATIC'].includes(el.nodeName), ) as (SbbLinkElement | SbbLinkButtonElement | SbbLinkStaticElement)[]; diff --git a/src/storybook/pages/home/home--logged-in.stories.ts b/src/storybook/pages/home/home--logged-in.stories.ts index 67d9a41e26..bc64a1ba3e 100644 --- a/src/storybook/pages/home/home--logged-in.stories.ts +++ b/src/storybook/pages/home/home--logged-in.stories.ts @@ -213,7 +213,7 @@ const Template = (args: Args): TemplateResult => html` orientation="vertical" horizontal-from="medium" > - html` sbb-dialog-close > Link - + Cancel Button diff --git a/src/storybook/pages/home/home.common.ts b/src/storybook/pages/home/home.common.ts index a08e2a1860..f99d7fa6c5 100644 --- a/src/storybook/pages/home/home.common.ts +++ b/src/storybook/pages/home/home.common.ts @@ -28,8 +28,8 @@ import '../../../components/title'; export const skiplinkList = (): TemplateResult => html` - Skip to content - Go to help page + Skip to content + Go to help page `; @@ -243,36 +243,36 @@ export const footer = (args: Args): TemplateResult => html` - Jobs & careers - - + Rail traffic information - - + SBB News - - + SBB Community - - + Company - +