Gathering detailed insights and metrics for svelte-media-queries
Gathering detailed insights and metrics for svelte-media-queries
Gathering detailed insights and metrics for svelte-media-queries
Gathering detailed insights and metrics for svelte-media-queries
A ✨light✨ and magical Svelte component for CSS media queries🐹
npm install svelte-media-queries
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
38 Stars
107 Commits
5 Forks
2 Watching
3 Branches
3 Contributors
Updated on 07 Nov 2024
Minified
Minified + Gzipped
TypeScript (46.64%)
Svelte (42.88%)
JavaScript (8.35%)
HTML (2.13%)
Cumulative downloads
Total Downloads
Last day
-73.2%
704
Compared to previous day
Last week
4.2%
9,234
Compared to previous week
Last month
228%
22,307
Compared to previous month
Last year
57.7%
89,248
Compared to previous year
With TypeScript support💙
1npm i svelte-media-queries
1query = { 2 "mobile": "(max-width: 480px)", 3 "tablet": "(min-width: 480px) and (max-width: 768px)", 4 "largeTablet": "(min-width: 768px) and (max-width: 1200px)", 5 "desktop": "(min-width: 1200px)", 6 "other": [ 7 "(min-width: 1200px)", 8 "(max-height: 900px)" 9 ], 10 "themes": { 11 "dark": "(prefers-color-scheme: dark)", 12 "light": "(prefers-color-scheme: light)" 13 } 14} //
1matches = { 2 "mobile": false, 3 "tablet": true, 4 "largeTablet": false, 5 "desktop": false, 6 "other": [ 7 false, 8 true 9 ], 10 "themes": { 11 "dark": false, 12 "light": true 13 } 14}
Yes, yes, and it's all recursive and reactive🐹
Try it in Svelte REPL
1query='(min-width: 768px) and (max-width: 1280px)'
bind:
directive)bind:matches
------------------
bind:matches={foo}
let:
directive)let:matches
------------------
let:matches={foo}
1<script> 2 import { onDestroy } from 'svelte' 3 import { createMediaStore } from 'svelte-media-queries' 4 5 const matches = createMediaStore(query) //The type of the store will completely repeat the query 6 7 onDestroy(() => matches.destroy()) //Stop events for calculation 8</script>
1<script> 2 import MediaQuery from 'svelte-media-queries' 3</script> 4 5<MediaQuery query='(max-width: 480px)' let:matches> 6 {#if matches} 7 mobile!! 8 {/if} 9</MediaQuery>
1<script> 2 import MediaQuery from 'svelte-media-queries' 3 4 let matches 5</script> 6 7<MediaQuery query='(max-width: 480px)' bind:matches/> 8 9{#if matches} 10 mobile!! 11{/if} 12 13{#if matches} 14 Oh my God, it's really mobile 15{/if}
query
1query={['(max-width: 1200px)', '(min-width: 800px)']}
What about matches?
Matches will take everything from query
in order
1matches=[boolean, boolean]
1<script> 2 import MediaQuery from 'svelte-media-queries' 3</script> 4 5<MediaQuery query={['(max-width: 768px)', '(min-width: 768px) and (max-width: 1280px)', '(min-width: 1280px)']} let:matches> 6 {@const [mobile, tablet, desktop] = matches} 7 <h5> 8 mobile: '(max-width: 768px)' = {mobile} 9 tablet: '(max-width: 1280px)' = {tablet} 10 desktop: '(min-width: 1280px)' = {desktop} 11 </h5> 12</MediaQuery>
{@const}
- Svelte Docs🐹
You can also use it through the array index tablet = matches[1]
With bind:
, everything is the same🐥
No vulnerabilities found.
No security vulnerabilities found.