Skip to content
Likable Aurora @likable-hair/svelte 5

MediaQuery

Renders defaultSnippet with the breakpoints of the window as flags (xs, s, m, l, xl, sAndDown, mAndDown, lAndUp, ...), to show different markup on phones, tablets and desktops. The widths are those of v4 and of the components, which switch to their mobile variant on mAndDown (up to 1024px). The same flags are reactive in scripts as breakpoints. On the server the window counts as wide (xl).

import { MediaQuery } from '@likable-hair/svelte';

src/lib/components/simple/common/MediaQuery.svelte · Markdown for LLMs

Different markup by width

defaultSnippet receives the flags of the breakpoints; resize the window to see them change. In scripts the same flags are breakpoints.mAndDown and so on.

Desktop layout: wider than 1024px

Code
<script lang="ts">
	import { Button, MediaQuery } from '@likable-hair/svelte';
	import { mdiPlus } from '@mdi/js';
</script>

<MediaQuery>
	{#snippet defaultSnippet({ mAndDown, sAndDown })}
		<div class="stack">
			<Button icon={mdiPlus} aria-label={sAndDown ? 'New booking' : undefined}>
				{#if !sAndDown}New booking{/if}
			</Button>
			<p>{mAndDown ? 'Mobile layout: up to 1024px' : 'Desktop layout: wider than 1024px'}</p>
		</div>
	{/snippet}
</MediaQuery>

<style>
	.stack {
		display: flex;
		align-items: center;
		gap: 16px;
	}

	p {
		margin: 0;
		color: var(--global-color-text-2);
		font-size: 13px;
	}
</style>

Props

No props of its own.

Snippets

NameParametersDescription
defaultSnippetBreakpointsContent, which receives the flags of the breakpoints (see Breakpoints).

Types

Exported by the package: import type { Breakpoints } from '@likable-hair/svelte';

Breakpoints

Which breakpoint the window is in, as reactive flags. xs up to 425px (phones), s up to 768px (tablets), m up to 1024px (small laptops), l up to 1440px, xl wider. The components switch to their mobile variant on mAndDown. On the server every flag says the window is wide (xl).

interface Breakpoints

NameTypeDescription
xs requiredbooleanUp to 425px.
s requiredbooleanFrom 426px to 768px.
m requiredbooleanFrom 769px to 1024px.
l requiredbooleanFrom 1025px to 1440px.
xl requiredbooleanWider than 1440px.
xsAndDown requiredbooleanUp to 425px.
sAndDown requiredbooleanUp to 768px.
mAndDown requiredbooleanUp to 1024px: where the components use their mobile variant.
lAndDown requiredbooleanUp to 1440px.
xlAndDown requiredbooleanAlways true.
xsAndUp requiredbooleanAlways true.
sAndUp requiredbooleanFrom 426px.
mAndUp requiredbooleanFrom 769px.
lAndUp requiredbooleanFrom 1025px.
xlAndUp requiredbooleanFrom 1441px.