Skip to content

Commit

Permalink
feat: transition slide wrapper and params (#580)
Browse files Browse the repository at this point in the history
# Motivation

Provide a wrapper for the "slide" transition, similarly as those which
were provided in #573.

Needed in OISY for Svelte v5 - i.e. looks like we will have to use those
wrappers in consuming dApps as well.

The PR also 

# Changes

- Add `testSafeSlide`.
  • Loading branch information
peterpeterparker authored Feb 10, 2025
1 parent 61f6c06 commit d8f1aae
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib/directives/transition.directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
fade as svelteFade,
fly as svelteFly,
scale as svelteScale,
slide as svelteSlide,
type FadeParams,
type FlyParams,
type ScaleParams,
type SlideParams,
type TransitionConfig,
} from "svelte/transition";

Expand Down Expand Up @@ -67,3 +69,23 @@ export const testSafeScale = (

return svelteScale(node, params);
};

/**
* A wrapper around Svelte's `slide` transition that disables itself in test mode.
*
* Prevents the test error "Cannot set properties of undefined (setting 'onfinish')".
*
* @param {HTMLElement} node - The HTML element to apply the transition to.
* @param {SlideParams} [params] - Optional parameters for the slide transition.
* @returns {TransitionConfig} The transition configuration, or an empty object in test mode.
*/
export const testSafeSlide = (
node: HTMLElement,
params?: SlideParams | undefined,
): TransitionConfig => {
if (process.env.NODE_ENV === "test") {
return {};
}

return svelteSlide(node, params);
};

0 comments on commit d8f1aae

Please sign in to comment.