Skip to content

Commit 7c947ba

Browse files
committed
update README
1 parent 1cad879 commit 7c947ba

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

README.md

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,23 @@ yarn add @sveltejs/svelte-virtual-list
1212
## Usage
1313

1414
```html
15-
<VirtualList items={things} component={RowComponent} />
16-
1715
<script>
1816
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-
```
4017
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>
4227

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>
4932
```
5033

5134

@@ -54,37 +37,35 @@ The component constructor you supply to `<VirtualList>` will be instantiated for
5437
You can track which rows are visible at any given by binding to the `start` and `end` values:
5538

5639
```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>
5843

5944
<p>showing {start}-{end} of {things.length} rows</p>
6045
```
6146

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}`.
6348

6449

65-
## `itemHeight`
50+
## `height`
6651

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:
6853

6954
```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>
7158
```
7259

7360

74-
## Additional properties
75-
76-
You can add arbitrary properties to `<VirtualList>` and they will be forwarded to the rows:
61+
## `itemHeight`
7762

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

8265
```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>
8869
```
8970

9071

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@sveltejs/svelte-virtual-list",
33
"version": "2.2.1",
44
"description": "A <VirtualList> component for Svelte apps",
5+
"main": "VirtualList.html",
56
"svelte": "VirtualList.html",
67
"scripts": {
78
"build": "rollup -c",

0 commit comments

Comments
 (0)