|
| 1 | +<script lang="ts"> |
| 2 | + import { MediaQuery } from 'svelte/reactivity'; |
| 3 | +
|
| 4 | + import { Icon } from 'svelte-ux'; |
| 5 | + import { MediaQueryPresets } from '@layerstack/svelte-state'; |
| 6 | + import { mdiCheckCircle, mdiCloseCircle } from '@mdi/js'; |
| 7 | +
|
| 8 | + import Code from '$docs/Code.svelte'; |
| 9 | + import Preview from '$docs/Preview.svelte'; |
| 10 | +
|
| 11 | + const { |
| 12 | + smScreen, |
| 13 | + mdScreen, |
| 14 | + lgScreen, |
| 15 | + xlScreen, |
| 16 | + xxlScreen, |
| 17 | + screen, |
| 18 | + print, |
| 19 | + dark, |
| 20 | + motion, |
| 21 | + motionReduce, |
| 22 | + } = new MediaQueryPresets(); |
| 23 | +
|
| 24 | + let innerWidth = 0; |
| 25 | +</script> |
| 26 | + |
| 27 | +<h1>Usage</h1> |
| 28 | + |
| 29 | +<Code |
| 30 | + source={`<script> |
| 31 | + import { MediaQueryPresets } from '@layerstack/svelte-state'; |
| 32 | + const { mdScreen, print} = new MediaQueryPresets(); |
| 33 | +</script> |
| 34 | +
|
| 35 | +{#if mdScreen.current} |
| 36 | + <div>Only visible on 768px+ screens</div> |
| 37 | +{/if} |
| 38 | +
|
| 39 | +{#if print.current} |
| 40 | + <div>Only visable when printing</div> |
| 41 | +{/if}`} |
| 42 | + `} |
| 43 | + language="svelte" |
| 44 | +/> |
| 45 | + |
| 46 | +<h1>Examples</h1> |
| 47 | + |
| 48 | +<Preview> |
| 49 | + <div class="grid grid-cols-[auto_1fr] items-center gap-2"> |
| 50 | + {#if smScreen.current} |
| 51 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 52 | + {:else} |
| 53 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 54 | + {/if} |
| 55 | + smScreen (640px) |
| 56 | + |
| 57 | + {#if mdScreen.current} |
| 58 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 59 | + {:else} |
| 60 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 61 | + {/if} |
| 62 | + mdScreen (768px) |
| 63 | + |
| 64 | + {#if lgScreen.current} |
| 65 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 66 | + {:else} |
| 67 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 68 | + {/if} |
| 69 | + lgScreen (1024px) |
| 70 | + |
| 71 | + {#if xlScreen.current} |
| 72 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 73 | + {:else} |
| 74 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 75 | + {/if} |
| 76 | + xlScreen (1280px) |
| 77 | + |
| 78 | + {#if xxlScreen.current} |
| 79 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 80 | + {:else} |
| 81 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 82 | + {/if} |
| 83 | + xxlScreen (1536px) |
| 84 | + |
| 85 | + {#if screen.current} |
| 86 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 87 | + {:else} |
| 88 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 89 | + {/if} |
| 90 | + screen |
| 91 | + |
| 92 | + {#if print.current} |
| 93 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 94 | + {:else} |
| 95 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 96 | + {/if} |
| 97 | + print |
| 98 | + |
| 99 | + {#if dark.current} |
| 100 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 101 | + {:else} |
| 102 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 103 | + {/if} |
| 104 | + dark |
| 105 | + |
| 106 | + {#if motion.current} |
| 107 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 108 | + {:else} |
| 109 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 110 | + {/if} |
| 111 | + motion |
| 112 | + |
| 113 | + {#if motionReduce.current} |
| 114 | + <Icon data={mdiCheckCircle} size="1rem" class="text-success" /> |
| 115 | + {:else} |
| 116 | + <Icon data={mdiCloseCircle} size="1rem" class="text-danger" /> |
| 117 | + {/if} |
| 118 | + motionReduce |
| 119 | + </div> |
| 120 | + |
| 121 | + <div class="ml-6 mt-3 text-surface-content/50 text-xs"> |
| 122 | + current width: {innerWidth}px |
| 123 | + </div> |
| 124 | +</Preview> |
| 125 | + |
| 126 | +<svelte:window bind:innerWidth /> |
0 commit comments