Skip to content

Commit

Permalink
fix: reinstate prefersReducedMotion (#14586)
Browse files Browse the repository at this point in the history
* reinstate prefersReducedMotion

* changeset
  • Loading branch information
Rich-Harris authored Dec 6, 2024
1 parent 7086709 commit 8433a71
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/large-humans-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: reinstate missing prefersReducedMotion export
2 changes: 1 addition & 1 deletion packages/svelte/src/motion/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ export interface Tweened<T> extends Readable<T> {
update(updater: Updater<T>, opts?: TweenedOptions<T>): Promise<void>;
}

export { spring, tweened, Tween } from './index.js';
export { prefersReducedMotion, spring, tweened, Tween } from './index.js';
25 changes: 25 additions & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ declare module 'svelte/legacy' {
}

declare module 'svelte/motion' {
import type { MediaQuery } from 'svelte/reactivity';
// TODO we do declaration merging here in order to not have a breaking change (renaming the Spring interface)
// this means both the Spring class and the Spring interface are merged into one with some things only
// existing on one side. In Svelte 6, remove the type definition and move the jsdoc onto the class in spring.js
Expand Down Expand Up @@ -1767,6 +1768,30 @@ declare module 'svelte/motion' {
easing?: (t: number) => number;
interpolate?: (a: T, b: T) => (t: number) => T;
}
/**
* A [media query](https://svelte.dev/docs/svelte/svelte-reactivity#MediaQuery) that matches if the user [prefers reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion).
*
* ```svelte
* <script>
* import { prefersReducedMotion } from 'svelte/motion';
* import { fly } from 'svelte/transition';
*
* let visible = $state(false);
* </script>
*
* <button onclick={() => visible = !visible}>
* toggle
* </button>
*
* {#if visible}
* <p transition:fly={{ y: prefersReducedMotion.current ? 0 : 200 }}>
* flies in, unless the user prefers reduced motion
* </p>
* {/if}
* ```
* @since 5.7.0
*/
export const prefersReducedMotion: MediaQuery;
/**
* The spring function in Svelte creates a store whose value is animated, with a motion that simulates the behavior of a spring. This means when the value changes, instead of transitioning at a steady rate, it "bounces" like a spring would, depending on the physics parameters provided. This adds a level of realism to the transitions and can enhance the user experience.
*
Expand Down

0 comments on commit 8433a71

Please sign in to comment.