Skip to content

Commit 7900d9b

Browse files
committed
add example to prefersReducedMotion
1 parent c6d29d7 commit 7900d9b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/svelte/src/motion/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ export * from './tweened.js';
55

66
/**
77
* 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).
8+
*
9+
* ```svelte
10+
* <script>
11+
* import { prefersReducedMotion } from 'svelte/motion';
12+
* import { fly } from 'svelte/transition';
13+
*
14+
* let visible = $state(false);
15+
* </script>
16+
*
17+
* <button onclick={() => visible = !visible}>
18+
* toggle
19+
* </button>
20+
*
21+
* {#if visible}
22+
* <p transition:fly={{ y: prefersReducedMotion.current ? 0 : 200 }}>
23+
* flies in, unless the user prefers reduced motion
24+
* </p>
25+
* {/if}
26+
* ```
827
* @type {MediaQuery}
928
*/
1029
export const prefersReducedMotion = /*@__PURE__*/ new MediaQuery(

packages/svelte/types/index.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,23 @@ declare module 'svelte/motion' {
16861686
}
16871687
/**
16881688
* 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).
1689+
*
1690+
* ```svelte
1691+
* <script>
1692+
* import { prefersReducedMotion } from 'svelte/motion';
1693+
* import { fly } from 'svelte/transition';
1694+
*
1695+
* let visible = $state(false);
1696+
* </script>
1697+
*
1698+
* <button onclick={() => visible = !visible}>toggle</button>
1699+
*
1700+
* {#if visible}
1701+
* <p transition:fly={{ y: prefersReducedMotion.current ? 0 : 200 }}>
1702+
* flies in, unless the user prefers reduced motion
1703+
* </p>
1704+
* {/if}
1705+
* ```
16891706
* */
16901707
export const prefersReducedMotion: MediaQuery;
16911708
/**

0 commit comments

Comments
 (0)