Giter Club home page Giter Club logo

svelte-virtual's Introduction

svelte-virtual

About

Svelte components for efficiently rendering large lists. Instead of rendering all your data, svelte-virtual renders only what's visible

Installation

With npm:

npm i -D svelte-virtual@next

With yarn:

yarn add -D svelte-virtual@next

With pnpm:

pnpm add -D svelte-virtual@next

Usage

Vertical List [default] (demo)

<script>
	import { List } from "svelte-virtual@next";

	let items = [...Array(100000).keys()];
</script>

<List itemCount={items.length} itemSize={20} height={500}>
	<div slot="item" let:index let:style {style}>
		{items[index]}
	</div>
</List>

Horizontal List (demo)

<script>
	import { List } from "svelte-virtual@next";

	let items = [...Array(100000).keys()];
</script>

<List itemCount={items.length} itemSize={60} height={40} layout="horizontal">
	<div slot="item" let:index let:style {style}>
		{items[index]}
	</div>
</List>

Grid (demo)

<script>
	import { Grid } from "svelte-virtual@next";

	let items = [...Array(100000).keys()];
</script>

<Grid itemCount={items.length} itemHeight={50} itemWidth={60} height={500}>
	<div slot="item" let:index let:style {style}>
		{items[index]}
	</div>
</Grid>

Grid [using rows and columns] (demo)

<script>
	import { Grid } from "svelte-virtual@next";

	let itemCount = 100000;
	let columnCount = 5;

	let items = Array.from({ length: itemCount }, (_, l) =>
		Array.from({ length: columnCount }, (_, c) => `${l}-${c}`),
	);
</script>

<Grid itemCount={itemCount * columnCount} itemHeight={50} itemWidth={65} height={500} {columnCount}>
	<div slot="item" let:rowIndex let:columnIndex let:style {style}>
		{items[rowIndex][columnIndex]}
	</div>
</Grid>

Props

List

Property Type Default Required?
itemCount number
itemSize number
height number | string "100%"
width string "100%"
stickyIndices number[] []
overScan number 1
marginLeft number 0
marginTop number 0
layout "vertical" | "horizontal" "vertical"
scrollPosition number 0
scrollBehavior "auto" | "smooth" "auto"
getKey (index: number) => unknown (index: number) => index

Grid

Property Type Default Required?
itemCount number
itemHeight number
itemWidth number
height number
width string "100%"
overScan number 1
marginLeft number 0
marginTop number 0
scrollPosition number 0
scrollBehavior "auto" | "smooth" "auto"
getKey (index: number) => unknown (index: number) => index
columnCount number undefined

Methods (demo)

Method Argument Type Default Required?
scrollToIndex
index number
behavior "auto" | "smooth" scrollBehavior
scrollToPosition
position number
behavior "auto" | "smooth" scrollBehavior

Slots

  • item - Slot for each item
    • Props:
      • Shared:
        • index: number - Item index
        • style: string - Item style, must be applied to the slot (look above for example)
      • Only for <Grid/> (demo):
        • rowIndex: number - Item row index
        • columnIndex: number - Item column index
  • placeholder (optional) - Slot for each item (when scrolling fast, replaces item slot. if not present, item slot is used)
    • Props:
      • Shared:
        • index: number - Item index
        • style: string - Item style, must be applied to the slot (look above for example)
      • Only for <Grid/> (demo):
        • rowIndex: number - Item row index
        • columnIndex: number - Item column index
  • header (optional) - Slot for the elements that should appear at the top of the component
  • footer (optional) - Slot for the elements that should appear at the bottom of the component

License

MIT

svelte-virtual's People

Contributors

ghostebony avatar renovate[bot] avatar wattsjs avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.