@@ -12,40 +12,23 @@ yarn add @sveltejs/svelte-virtual-list
12
12
## Usage
13
13
14
14
``` html
15
- <VirtualList items ={things} component ={RowComponent} />
16
-
17
15
<script >
18
16
import VirtualList from ' @sveltejs/svelte-virtual-list' ;
19
- import RowComponent from ' ./RowComponent.html' ;
20
-
21
- export default {
22
- components: { VirtualList },
23
-
24
- data () {
25
- return {
26
- things: [
27
- // these can be any values you like
28
- { name: ' one' , number: 1 },
29
- { name: ' two' , number: 2 },
30
- { name: ' three' , number: 3 },
31
- // ...
32
- { name: ' six thousand and ninety-two' , number: 6092 }
33
- ],
34
- RowComponent
35
- };
36
- }
37
- };
38
- </script >
39
- ```
40
17
41
- The component constructor you supply to ` <VirtualList> ` will be instantiated for each visible member of ` items ` :
18
+ const things = [
19
+ // these can be any values you like
20
+ { name: ' one' , number: 1 },
21
+ { name: ' two' , number: 2 },
22
+ { name: ' three' , number: 3 },
23
+ // ...
24
+ { name: ' six thousand and ninety-two' , number: 6092 }
25
+ ];
26
+ </script >
42
27
43
- ``` html
44
- <!-- RowComponent.html -->
45
- <div >
46
- <strong >{number}</strong >
47
- <span >{name}</span >
48
- </div >
28
+ <VirtualList items ={things} let:item >
29
+ <!-- this will be rendered for each currently visible item -->
30
+ <p >{item.number}: {item.name}</p >
31
+ </VirtualList >
49
32
```
50
33
51
34
@@ -54,37 +37,35 @@ The component constructor you supply to `<VirtualList>` will be instantiated for
54
37
You can track which rows are visible at any given by binding to the ` start ` and ` end ` values:
55
38
56
39
``` html
57
- <VirtualList items ={things} component ={RowComponent} bind:start bind:end />
40
+ <VirtualList items ={things} bind:start bind:end >
41
+ <p >{item.number}: {item.name}</p >
42
+ </VirtualList >
58
43
59
44
<p >showing {start}-{end} of {things.length} rows</p >
60
45
```
61
46
62
- You can rename them with e.g. ` bind:start=a bind:end=b ` .
47
+ You can rename them with e.g. ` bind:start={a} bind:end={b} ` .
63
48
64
49
65
- ## ` itemHeight `
50
+ ## ` height `
66
51
67
- You can optimize initial display and scrolling when the height of items is known in advance.
52
+ By default, the ` <VirtualList> ` component will fill the vertical space of its container. You can specify a different height by passing any CSS length:
68
53
69
54
``` html
70
- <VirtualList items ={things} component ={RowComponent} itemHeight ={48} />
55
+ <VirtualList height =" 500px" items ={things} let:item >
56
+ <p >{item.number}: {item.name}</p >
57
+ </VirtualList >
71
58
```
72
59
73
60
74
- ## Additional properties
75
-
76
- You can add arbitrary properties to ` <VirtualList> ` and they will be forwarded to the rows:
61
+ ## ` itemHeight `
77
62
78
- ``` html
79
- <VirtualList class =" funky" answer ={42} items ={things} component ={RowComponent} />
80
- ```
63
+ You can optimize initial display and scrolling when the height of items is known in advance. This should be a number representing a pixel value.
81
64
82
65
``` html
83
- <!-- RowComponent.html -->
84
- <div class =" {number === answer ? 'the-answer' : ''}" >
85
- <strong >{number}</strong >
86
- <span >{name}</span >
87
- </div >
66
+ <VirtualList itemHeight ={48} items ={things} let:item >
67
+ <p >{item.number}: {item.name}</p >
68
+ </VirtualList >
88
69
```
89
70
90
71
0 commit comments