0.0.6 • Published 1 year ago

@a993576769/virtual-list v0.0.6

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

Virtual List Component Documentation

Build Publish

Demo

https://993576769.github.io/virtual-list/

Installation

npm install @a993576769/virtual-list

Virtual List Component

Props

Prop NameTypeDefaultDescription
itemsArray<T>RequiredArray of items to be rendered
itemHeightNumber48Height of each item, if fixedHeight is true, this value will be ignored
bufferNumber0Number of items to render outside the visible area
keyFieldkeyof T'id'Unique key field for each item
topThresholdNumber50Threshold for triggering the topArrived event
bottomThresholdNumber50Threshold for triggering the bottomArrived event
initialPosition'top' \| 'bottom' \| T[keyof T]'bottom'Initial scroll position

Events

Event NameParametersDescription
topArrivedNoneTriggered when scrolling reaches the top threshold
bottomArrivedNoneTriggered when scrolling reaches the bottom threshold
scrollNoneTriggered on scroll

Exposed Methods and Refs

NameTypeDescription
visibleItemsRef<RenderedItem<T>[]>Array of currently visible items
renderItemsRef<RenderedItem<T>[]>Array of all rendered items, including buffer
scrollToItem({ key: T[keyof T]; alignment: `start` \| `center` \| `end`; smooth?: boolean }) => Promise<void>Scrolls to a specific item
scrollToTop(smooth?: boolean) => voidScrolls to the top of the list
scrollToBottom(smooth?: boolean) => Promise<void>Scrolls to the bottom of the list
getScroll() => { scrollHeight: number; scrollTop: number; clientHeight: number }Returns current scroll information

Virtual List Item Component

Props

Prop NameTypeRequiredDescription
itemTYesThe data object for the list item
indexNumberYesThe index of the item in the list
resizeFunctionYesCallback function to report item height changes

Usage

To use the Virtual List components together:

<script setup lang="ts">
import { VirtualList, VirtualListItem } from '@a993576769/virtual-list';
import { ref } from 'vue';

const myItems = ref([/* your items array */]);
</script>

<template>
  <VirtualList :items="myItems">
    <template #default="{ item, index, resize }">
      <VirtualListItem :item="item" :index="index" :resize="resize">
        <!-- Your item content here -->
      </VirtualListItem>
    </template>
  </VirtualList>
</template>

License

This project is licensed under the MIT license.

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago