Skip to content

Commit 4e40316

Browse files
committed
Initial sources
1 parent 556b9f9 commit 4e40316

File tree

13 files changed

+431
-0
lines changed

13 files changed

+431
-0
lines changed

.eslintrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
root: true,
3+
parser: 'babel-eslint',
4+
parserOptions: {
5+
sourceType: 'module'
6+
},
7+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
8+
extends: 'standard',
9+
// required to lint *.vue files
10+
plugins: [
11+
'html'
12+
],
13+
env: {
14+
browser: true,
15+
},
16+
// add your custom rules here
17+
'rules': {
18+
// allow paren-less arrow functions
19+
'arrow-parens': 0,
20+
// allow async-await
21+
'generator-star-spacing': 0,
22+
// allow debugger during development
23+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
24+
// trailing comma
25+
'comma-dangle': ['error', 'always-multiline'],
26+
// beware of returning assignement
27+
'no-return-assign': 'warn',
28+
'no-extend-native': 'warn',
29+
}
30+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
11
# vue-virtual-scroller
22
Smooth scroll with any amount of data
3+
4+
```
5+
npm install --save vue-virtual-scroller
6+
```
7+
8+
Use the component in your app. For example, register it as a global component:
9+
10+
```javascript
11+
import { VirtualScroller } from 'vue-virtual-scroller'
12+
13+
Vue.component('virtual-scroller', VirtualScroller)
14+
```
15+
16+
```html
17+
<template>
18+
<div class="demo">
19+
<virtual-scroller
20+
:items="items"
21+
:renderers="renderers"
22+
item-height="22"
23+
type-field="type">
24+
</virtual-scroller>
25+
</div>
26+
</template>
27+
28+
<script>
29+
// Data with a type field
30+
const items = [
31+
{ type: 'letter', value: 'A' },
32+
{ type: 'person', value: { name: 'Alan' } },
33+
{ type: 'person', value: { name: 'Alice' } },
34+
]
35+
36+
import Letter from './Letter.vue'
37+
import Item from './Item.vue'
38+
39+
// Bind the components to the item type
40+
const renderers = Object.freeze({
41+
letter: Letter,
42+
person: Item,
43+
})
44+
45+
export default {
46+
data: () => ({
47+
items,
48+
renderers,
49+
}),
50+
}
51+
</script>
52+
```
53+
54+
Finally, set the size of the virtual-scroller element (for example, with CSS).

demo/Demo.vue

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<div class="demo">
3+
<virtual-scroller :items="items" :renderers="renderers" item-height="22"></virtual-scroller>
4+
</div>
5+
</template>
6+
7+
<script>
8+
import { getData } from './data.js'
9+
10+
const count = 100000
11+
console.log('Generating ' + count + ' items...')
12+
let time = new Date().getTime()
13+
let time2
14+
const items = Object.freeze(getData(count))
15+
console.log('Generated ' + items.length + ' in ' + ((time2 = new Date().getTime()) - time))
16+
17+
import Letter from './Letter.vue'
18+
import Item from './Item.vue'
19+
20+
const renderers = {
21+
letter: Letter,
22+
person: Item,
23+
}
24+
25+
export default {
26+
data: () => ({
27+
items,
28+
renderers,
29+
}),
30+
mounted () {
31+
console.log('app ready', new Date().getTime() - time2)
32+
},
33+
}
34+
</script>
35+
36+
<style>
37+
body {
38+
font-family: sans-serif;
39+
}
40+
41+
.virtual-scroller {
42+
overflow: auto;
43+
position: absolute;
44+
top: 0;
45+
bottom: 0;
46+
left: 0;
47+
right: 0;
48+
}
49+
50+
.item-container {
51+
box-sizing: border-box;
52+
}
53+
54+
.item {
55+
height: 22px;
56+
padding: 2px 12px;
57+
box-sizing: border-box;
58+
cursor: pointer;
59+
user-select: none;
60+
-moz-user-select: none;
61+
-webkit-user-select: none;
62+
}
63+
64+
.item:hover {
65+
background: #4fc08d;
66+
color: white;
67+
}
68+
69+
.letter {
70+
text-transform: uppercase;
71+
color: grey;
72+
}
73+
</style>

demo/Item.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div class="person" @click="edit">({{item.index}}) {{item.value.name}}</div>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: ['item'],
8+
methods: {
9+
edit () {
10+
this.item.value.name += '*'
11+
},
12+
},
13+
}
14+
</script>

demo/Letter.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<div class="letter">({{item.index}}) {{item.value}}</div>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: ['item'],
8+
}
9+
</script>

demo/data.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import faker from 'faker'
2+
3+
export function getData (count) {
4+
const raw = {}
5+
6+
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')
7+
8+
for (var l of alphabet) {
9+
raw[l] = []
10+
}
11+
12+
for (var i = 0; i < count; i++) {
13+
const item = {
14+
name: faker.name.findName(),
15+
}
16+
const letter = item.name.charAt(0).toLowerCase()
17+
raw[letter].push(item)
18+
}
19+
20+
const data = []
21+
let index = 0
22+
23+
for (const l of alphabet) {
24+
raw[l] = raw[l].sort((a, b) => a.name < b.name ? -1 : 1)
25+
data.push({
26+
index: index++,
27+
type: 'letter',
28+
value: l,
29+
})
30+
for (var item of raw[l]) {
31+
data.push({
32+
index: index++,
33+
type: 'person',
34+
value: item,
35+
})
36+
}
37+
}
38+
39+
return data
40+
}

demo/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Vue from 'vue'
2+
import VirtualScroller from '../src/VirtualScroller.vue'
3+
import * as Index from '../'
4+
5+
console.log(Index)
6+
console.log(VirtualScroller)
7+
8+
Vue.component('virtual-scroller', VirtualScroller)
9+
10+
import Demo from './Demo.vue'
11+
12+
const app = new Vue({
13+
render: h => h(Demo),
14+
})
15+
app.$mount('#app')

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Vue Virtual Scroller</title>
6+
</head>
7+
<body>
8+
<div id="app"></div>
9+
<script src="dist/build.js"></script>
10+
</body>
11+
</html>

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { VirtualScroller } from './src/VirtualScroller.vue'

0 commit comments

Comments
 (0)