From fbb6ca6d824e1d4d90ad3e1e0c382387ba3b00ad Mon Sep 17 00:00:00 2001 From: Jeri Peier Date: Tue, 13 Aug 2024 17:06:25 +0200 Subject: [PATCH] fix(sbb-flip-card): support disabled animation (#2998) --- .../flip-card-summary.visual.spec.ts | 87 ++++++++++++------- .../flip-card/flip-card/flip-card.scss | 19 ++-- .../flip-card/flip-card.visual.spec.ts | 39 +++++---- .../teaser-hero/teaser-hero.visual.spec.ts | 2 +- 4 files changed, 93 insertions(+), 54 deletions(-) diff --git a/src/elements/flip-card/flip-card-summary/flip-card-summary.visual.spec.ts b/src/elements/flip-card/flip-card-summary/flip-card-summary.visual.spec.ts index 67bbfff0c1..e4cad132a7 100644 --- a/src/elements/flip-card/flip-card-summary/flip-card-summary.visual.spec.ts +++ b/src/elements/flip-card/flip-card-summary/flip-card-summary.visual.spec.ts @@ -1,7 +1,11 @@ import { html } from 'lit'; import { styleMap } from 'lit/directives/style-map.js'; -import { describeViewports, visualDiffDefault } from '../../core/testing/private.js'; +import { + describeViewports, + loadAssetAsBase64, + visualDiffDefault, +} from '../../core/testing/private.js'; import { waitForImageReady } from '../../core/testing/wait-for-image-ready.js'; import './flip-card-summary.js'; @@ -10,38 +14,61 @@ import '../../title.js'; import '../../image.js'; const imageUrl = import.meta.resolve('../../core/testing/assets/placeholder-image.png'); +const imageBase64 = await loadAssetAsBase64( + import.meta.resolve('../../core/testing/assets/lucerne.png'), +); + +const images = [ + { + selector: 'sbb-image', + image: html``, + }, + { + selector: 'img', + image: html``, + }, +]; describe(`sbb-flip-card-summary`, () => { describeViewports({ viewports: ['zero', 'medium'] }, () => { - for (const imageAlignment of ['after', 'below']) { - it( - `image-alignment=${imageAlignment}`, - visualDiffDefault.with(async (setup) => { - await setup.withFixture(html` -
- - Summary - - -
- `); - await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!); - }), - ); + for (const image of images) { + describe(`image=${image.selector}`, () => { + for (const imageAlignment of ['after', 'below']) { + it( + `image-alignment=${imageAlignment}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` +
+ + ${image.image} + Summary + +
+ `); + + await waitForImageReady(setup.snapshotElement.querySelector(image.selector)!); + }), + ); + } + }); } }); }); diff --git a/src/elements/flip-card/flip-card/flip-card.scss b/src/elements/flip-card/flip-card/flip-card.scss index 7e99f47c96..a6b5ca59ea 100644 --- a/src/elements/flip-card/flip-card/flip-card.scss +++ b/src/elements/flip-card/flip-card/flip-card.scss @@ -9,10 +9,16 @@ --sbb-flip-card-border-radius: var(--sbb-border-radius-4x); --sbb-flip-card-min-height: #{sbb.px-to-rem-build(280)}; --sbb-flip-card-details-min-height: var(--sbb-flip-card-min-height); - --sbb-flip-card-summary-transition-duration: var(--sbb-animation-duration-5x); + --sbb-flip-card-summary-transition-duration: var( + --sbb-disable-animation-zero-time, + var(--sbb-animation-duration-5x) + ); --sbb-flip-card-summary-transition-delay: var(--sbb-animation-duration-2x); - --sbb-flip-card-details-transition-duration: var(--sbb-animation-duration-4x); - --sbb-flip-card-details-transition-delay: var(--sbb-disable-animation-zero-time); + --sbb-flip-card-details-transition-duration: var( + --sbb-disable-animation-zero-time, + var(--sbb-animation-duration-4x) + ); + --sbb-flip-card-details-transition-delay: 0s; position: relative; display: block; @@ -28,9 +34,12 @@ :host([data-flipped]) { --sbb-flip-card-background-color: var(--sbb-color-midnight); - --sbb-flip-card-details-transition-duration: var(--sbb-animation-duration-2x); + --sbb-flip-card-details-transition-duration: var( + --sbb-disable-animation-zero-time, + var(--sbb-animation-duration-2x) + ); --sbb-flip-card-details-transition-delay: var(--sbb-animation-duration-5x); - --sbb-flip-card-summary-transition-delay: var(--sbb-disable-animation-zero-time); + --sbb-flip-card-summary-transition-delay: 0s; --sbb-flip-card-details-min-height: fit-content; ::slotted(sbb-flip-card-summary) { diff --git a/src/elements/flip-card/flip-card/flip-card.visual.spec.ts b/src/elements/flip-card/flip-card/flip-card.visual.spec.ts index 689d4a9916..37d1c82050 100644 --- a/src/elements/flip-card/flip-card/flip-card.visual.spec.ts +++ b/src/elements/flip-card/flip-card/flip-card.visual.spec.ts @@ -21,7 +21,7 @@ const content = ( imageAlignment: SbbFlipCardImageAlignment = 'after', longContent: boolean = false, ): TemplateResult => - html` + html` ${title} - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam luctus ornare condimentum. + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam luctus ornare condimentum. Vivamus turpis elit, dapibus eget fringilla pellentesque, lobortis in nibh. ${longContent ? `Duis dapibus vitae @@ -42,25 +42,28 @@ const content = ( luctus ornare condimentum. Vivamus turpis elit, dapibus eget fringilla pellentesque, lobortis in nibh. Duis dapibus vitae tortor ullamcorper maximus. In convallis consectetur felis.` : nothing} - Link`; + Link + `; describe(`sbb-flip-card`, () => { describeViewports({ viewports: ['zero', 'medium'] }, () => { for (const imageAlignment of ['after', 'below']) { - for (const state of [visualDiffDefault, visualDiffFocus]) { - it( - `image-alignment=${imageAlignment} ${state.name}`, - state.with(async (setup) => { - await setup.withFixture(html` - - ${content('Summary', imageAlignment as SbbFlipCardImageAlignment)} - - `); - await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!); - }), - ); - } + describe(`image-alignment=${imageAlignment}`, () => { + for (const state of [visualDiffDefault, visualDiffFocus]) { + it( + state.name, + state.with(async (setup) => { + await setup.withFixture(html` + + ${content('Summary', imageAlignment as SbbFlipCardImageAlignment)} + + `); + + await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!); + }), + ); + } + }); } it( diff --git a/src/elements/teaser-hero/teaser-hero.visual.spec.ts b/src/elements/teaser-hero/teaser-hero.visual.spec.ts index df4204bbcc..492233405e 100644 --- a/src/elements/teaser-hero/teaser-hero.visual.spec.ts +++ b/src/elements/teaser-hero/teaser-hero.visual.spec.ts @@ -11,7 +11,7 @@ import './teaser-hero.js'; import '../image.js'; import '../chip.js'; -const imageUrl = import.meta.resolve('../../elements/core/testing/assets/placeholder-image.png'); +const imageUrl = import.meta.resolve('../core/testing/assets/placeholder-image.png'); describe(`sbb-teaser-hero`, () => { describeViewports({ viewports: ['zero', 'micro', 'small', 'medium', 'wide'] }, () => {