@svelte-atoms/core 1.0.0-alpha.23 → 1.0.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/atom/html-atom.svelte +70 -70
- package/dist/components/input/input-root.svelte +79 -79
- package/dist/components/input/input.stories.svelte +38 -38
- package/dist/components/root/root.svelte +121 -103
- package/dist/components/root/root.svelte.d.ts +1 -0
- package/dist/runes/index.d.ts +3 -0
- package/dist/runes/index.js +3 -0
- package/dist/runes/reduced-motion.svelte.d.ts +23 -0
- package/dist/runes/reduced-motion.svelte.js +41 -0
- package/package.json +436 -436
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A rune that tracks the user's motion preferences via the `prefers-reduced-motion` media query.
|
|
3
|
+
*
|
|
4
|
+
* @returns An object with a `current` getter that returns `true` if the user prefers reduced motion, `false` otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```svelte
|
|
8
|
+
* <script>
|
|
9
|
+
* import { reducedMotion } from '@svelte-atoms/core';
|
|
10
|
+
*
|
|
11
|
+
* const motion = reducedMotion();
|
|
12
|
+
* </script>
|
|
13
|
+
*
|
|
14
|
+
* {#if motion.current}
|
|
15
|
+
* <div>Animations disabled</div>
|
|
16
|
+
* {:else}
|
|
17
|
+
* <div class="animated">Animations enabled</div>
|
|
18
|
+
* {/if}
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function reducedMotion() {
|
|
22
|
+
let prefersReduced = $state(false);
|
|
23
|
+
$effect(() => {
|
|
24
|
+
if (typeof window === 'undefined')
|
|
25
|
+
return;
|
|
26
|
+
const handleChange = (ev) => {
|
|
27
|
+
prefersReduced = ev.matches;
|
|
28
|
+
};
|
|
29
|
+
const media = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
30
|
+
media.addEventListener('change', handleChange);
|
|
31
|
+
prefersReduced = media.matches;
|
|
32
|
+
return () => {
|
|
33
|
+
media.removeEventListener('change', handleChange);
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
get current() {
|
|
38
|
+
return prefersReduced;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|