Skip to content

Commit 645ddef

Browse files
Sync svelte docs (#988)
sync svelte docs Co-authored-by: Rich-Harris <[email protected]>
1 parent fc61a81 commit 645ddef

File tree

2 files changed

+241
-21
lines changed

2 files changed

+241
-21
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
---
2+
NOTE: do not edit this file, it is generated in apps/svelte.dev/scripts/sync-docs/index.ts
3+
title: svelte/reactivity/window
4+
---
5+
6+
This module exports reactive versions of various `window` values, each of which has a reactive `current` property that you can reference in reactive contexts (templates, [deriveds]($derived) and [effects]($effect)) without using [`<svelte:window>`](svelte-window) bindings or manually creating your own event listeners.
7+
8+
```svelte
9+
<script>
10+
import { innerWidth, innerHeight } from 'svelte/reactivity/window';
11+
</script>
12+
13+
<p>{innerWidth.current}x{innerHeight.current}</p>
14+
```
15+
16+
17+
18+
```js
19+
// @noErrors
20+
import {
21+
devicePixelRatio,
22+
innerHeight,
23+
innerWidth,
24+
online,
25+
outerHeight,
26+
outerWidth,
27+
screenLeft,
28+
screenTop,
29+
scrollX,
30+
scrollY
31+
} from 'svelte/reactivity/window';
32+
```
33+
34+
## devicePixelRatio
35+
36+
<blockquote class="since note">
37+
38+
Available since 5.11.0
39+
40+
</blockquote>
41+
42+
`devicePixelRatio.current` is a reactive view of `window.devicePixelRatio`. On the server it is `undefined`.
43+
Note that behaviour differs between browsers — on Chrome it will respond to the current zoom level,
44+
on Firefox and Safari it won't.
45+
46+
<div class="ts-block">
47+
48+
```dts
49+
const devicePixelRatio: {
50+
get current(): number;
51+
};
52+
```
53+
54+
</div>
55+
56+
57+
58+
## innerHeight
59+
60+
<blockquote class="since note">
61+
62+
Available since 5.11.0
63+
64+
</blockquote>
65+
66+
`innerHeight.current` is a reactive view of `window.innerHeight`. On the server it is `undefined`.
67+
68+
<div class="ts-block">
69+
70+
```dts
71+
const innerHeight: ReactiveValue<number | undefined>;
72+
```
73+
74+
</div>
75+
76+
77+
78+
## innerWidth
79+
80+
<blockquote class="since note">
81+
82+
Available since 5.11.0
83+
84+
</blockquote>
85+
86+
`innerWidth.current` is a reactive view of `window.innerWidth`. On the server it is `undefined`.
87+
88+
<div class="ts-block">
89+
90+
```dts
91+
const innerWidth: ReactiveValue<number | undefined>;
92+
```
93+
94+
</div>
95+
96+
97+
98+
## online
99+
100+
<blockquote class="since note">
101+
102+
Available since 5.11.0
103+
104+
</blockquote>
105+
106+
`online.current` is a reactive view of `navigator.onLine`. On the server it is `undefined`.
107+
108+
<div class="ts-block">
109+
110+
```dts
111+
const online: ReactiveValue<boolean | undefined>;
112+
```
113+
114+
</div>
115+
116+
117+
118+
## outerHeight
119+
120+
<blockquote class="since note">
121+
122+
Available since 5.11.0
123+
124+
</blockquote>
125+
126+
`outerHeight.current` is a reactive view of `window.outerHeight`. On the server it is `undefined`.
127+
128+
<div class="ts-block">
129+
130+
```dts
131+
const outerHeight: ReactiveValue<number | undefined>;
132+
```
133+
134+
</div>
135+
136+
137+
138+
## outerWidth
139+
140+
<blockquote class="since note">
141+
142+
Available since 5.11.0
143+
144+
</blockquote>
145+
146+
`outerWidth.current` is a reactive view of `window.outerWidth`. On the server it is `undefined`.
147+
148+
<div class="ts-block">
149+
150+
```dts
151+
const outerWidth: ReactiveValue<number | undefined>;
152+
```
153+
154+
</div>
155+
156+
157+
158+
## screenLeft
159+
160+
<blockquote class="since note">
161+
162+
Available since 5.11.0
163+
164+
</blockquote>
165+
166+
`screenLeft.current` is a reactive view of `window.screenLeft`. It is updated inside a `requestAnimationFrame` callback. On the server it is `undefined`.
167+
168+
<div class="ts-block">
169+
170+
```dts
171+
const screenLeft: ReactiveValue<number | undefined>;
172+
```
173+
174+
</div>
175+
176+
177+
178+
## screenTop
179+
180+
<blockquote class="since note">
181+
182+
Available since 5.11.0
183+
184+
</blockquote>
185+
186+
`screenTop.current` is a reactive view of `window.screenTop`. It is updated inside a `requestAnimationFrame` callback. On the server it is `undefined`.
187+
188+
<div class="ts-block">
189+
190+
```dts
191+
const screenTop: ReactiveValue<number | undefined>;
192+
```
193+
194+
</div>
195+
196+
197+
198+
## scrollX
199+
200+
<blockquote class="since note">
201+
202+
Available since 5.11.0
203+
204+
</blockquote>
205+
206+
`scrollX.current` is a reactive view of `window.scrollX`. On the server it is `undefined`.
207+
208+
<div class="ts-block">
209+
210+
```dts
211+
const scrollX: ReactiveValue<number | undefined>;
212+
```
213+
214+
</div>
215+
216+
217+
218+
## scrollY
219+
220+
<blockquote class="since note">
221+
222+
Available since 5.11.0
223+
224+
</blockquote>
225+
226+
`scrollY.current` is a reactive view of `window.scrollY`. On the server it is `undefined`.
227+
228+
<div class="ts-block">
229+
230+
```dts
231+
const scrollY: ReactiveValue<number | undefined>;
232+
```
233+
234+
</div>
235+
236+
237+
238+

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-reactivity.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,25 @@ If you can use the media query in CSS to achieve the same effect, do that.
6464
<div class="ts-block">
6565

6666
```dts
67-
class MediaQuery {/*…*/}
67+
class MediaQuery extends ReactiveValue<boolean> {/*…*/}
6868
```
6969

7070
<div class="ts-block-property">
7171

7272
```dts
73-
constructor(query: string, matches?: boolean | undefined);
73+
constructor(query: string, fallback?: boolean | undefined);
7474
```
7575

7676
<div class="ts-block-property-details">
7777

7878
<div class="ts-block-property-bullets">
7979

8080
- `query` A media query string
81-
- `matches` Fallback value for the server
81+
- `fallback` Fallback value for the server
8282

8383
</div>
8484

8585
</div>
86-
</div>
87-
88-
<div class="ts-block-property">
89-
90-
```dts
91-
get current(): boolean;
92-
```
93-
94-
<div class="ts-block-property-details"></div>
95-
</div>
96-
97-
<div class="ts-block-property">
98-
99-
```dts
100-
#private;
101-
```
102-
103-
<div class="ts-block-property-details"></div>
10486
</div></div>
10587

10688

0 commit comments

Comments
 (0)