# 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`).

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

Category: simple. Source: `src/lib/components/simple/common/MediaQuery.svelte`.

## Examples

### 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.

```svelte
<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

| Name | Parameters | Description |
| --- | --- | --- |
| `defaultSnippet` | `Breakpoints` | Content, 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`

| Name | Type | Description |
| --- | --- | --- |
| `xs` (required) | `boolean` | Up to 425px. |
| `s` (required) | `boolean` | From 426px to 768px. |
| `m` (required) | `boolean` | From 769px to 1024px. |
| `l` (required) | `boolean` | From 1025px to 1440px. |
| `xl` (required) | `boolean` | Wider than 1440px. |
| `xsAndDown` (required) | `boolean` | Up to 425px. |
| `sAndDown` (required) | `boolean` | Up to 768px. |
| `mAndDown` (required) | `boolean` | Up to 1024px: where the components use their mobile variant. |
| `lAndDown` (required) | `boolean` | Up to 1440px. |
| `xlAndDown` (required) | `boolean` | Always true. |
| `xsAndUp` (required) | `boolean` | Always true. |
| `sAndUp` (required) | `boolean` | From 426px. |
| `mAndUp` (required) | `boolean` | From 769px. |
| `lAndUp` (required) | `boolean` | From 1025px. |
| `xlAndUp` (required) | `boolean` | From 1441px. |
