1.7.12 • Published 1 year ago

svelte-virtual-infinite-list v1.7.12

Weekly downloads
-
License
LIL+MIT
Repository
github
Last release
1 year ago

svelte-virtual-infinite-list(DEMO)

test

A virtual list component for Svelte apps. Instead of rendering all your data, <VirtuaInfinitelList> just renders the bits that are visible, keeping your page nice and light.

This library is forked and extends from @sveltejs/svelte-virtual-list, and all the basic feature of @sveltejs/svelte-virtual-list are available except default slot.

Installation

npm i svelte-virtual-infinite-list

Usage

<script lang="ts">
  import VirtualInfiniteList from 'svelte-virtual-infinite-list'
  import type { InfiniteEvent } from 'svelte-virtual-infinite-list'
  import { find } from './find'

  let things = [
    // these can be any values you like
    { name: 'one', number: 1 },
    { name: 'two', number: 2 },
    { name: 'three', number: 3 },
    // ...
    { name: 'six thousand and ninety-two', number: 6092 }
  ]

  let loading = true
  let virtualInfiniteList: VirtualInfiniteList

  async function onInitialize() {
    await virtualInfiniteList.scrollToBottom()
  }

  async function onInfinite({ detail }: InfiniteEvent) {
    if (detail.on === 'bottom') return
    loading = true

    const data = await find(30)
    things = [...data, ...things]

    loading = false
  }

  onMount(async () => {
    const data = await find(30)
    things = [...data]
    loading = false
  })

  async function scrollToIndex(item) {
    const index = things.findIndex((it) => it === item.number)
    index && await virtualInfiniteList.scrollToIndex(index)
  }
</script>

<VirtualInfiniteList
  items={things}
  {loading}
  direction="top"
  persists={30}
  uniqueKey={'number'}
  on:initialize={onInitialize}
  on:infinite={onInfinite}
  bind:this={virtualInfiniteList}
  let:item
>
  <!-- this will be rendered for each currently visible item -->
  <div slot="item">
    <p>{item.number}: {item.name}</p>
  </div>

  <!-- option -->
  <div slot="loader">
    Loading...
  </div>

  <!-- option -->
  <div slot="empty">
    Empty
  </div>
</VirtualInfiniteList>

Additional Props

NoProperty NameTypeNote
1loadingboolean-
2direction'top' or 'bottom' or 'vertical'Loading direction.
3maxItemCountPerLoadnumberDeprecated. This valiable removed @2.0.0. Use persists, please.
4persistsnumberFor direction-top infinite scroll user Maximum number of items loaded per load. The offset after loaded may be significantly shift if the number of items that exceeds this value is loaded. Default value is 30.
5uniqueKeystringYou need to set specify one unique property like id in the item object if you want to use the scrollToIndex method. Default value is undefined.

Additional Events

NoProperty NameTypeNote
1on:initialize() => anyEmit on change items count from 0 to more over.
2on:infinite(event: InfiniteEvent) => anyEmit on scrollbar reached top or bottom.

Additional Slots

NoSlot NameNote
1itemDisplayed item
2loaderDisplayed element if loading is true
3emptyDisplayed element if items is [] and loading is false

Additional Methods

NoMethod NameTypeNote
1scrollTo(offset: number) => Promise<void>This allows you to scroll to a specific offset.
2scrollToIndex(index: number, options?: { align: 'top' \| 'bottom' \| 'center' }) => Promise<boolean>This allows you to scroll to a specific item using the index. Returns true if this is done.
3scrollToTop() => Promise<void>This allows you to scroll to top.
4scrollToBottom() => Promise<void>This allows you to scroll to bottom.
5reset() => Promise<void>This allows you to reset VirtualInfiniteList.
6forceRefresh() => Promise<void>This allows you to tick and render VirtualInfiniteList.

LICENSE

LIL (original)

LIL+MIT

1.7.11

1 year ago

1.7.12

1 year ago

1.7.10

2 years ago

1.7.9

2 years ago

1.7.8

2 years ago

1.7.7

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.2.0

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.3.3

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.3.2

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago