2.0.1 • Published 7 months ago

@mathewmathew1/virtualized-list v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

virtualized-list

A lightweight, flexible, and type-safe virtualized list and table component for rendering large datasets efficiently using React. Designed to be minimal yet extensible with customizable wrappers, item rendering, and scroll handling.


Features

  • Supports vertical and horizontal virtualization
  • Easily customizable ItemComponent rendering
  • Scroll-to-index & ref access
  • Handles dynamic item sizes
  • Simple API with rich TypeScript support

Installation

npm i @mathewmathew1/virtualized-list

The VirtualizedList handles large lists efficiently by only rendering items visible in the viewport (plus a small customizable over-scan). It supports both horizontal and vertical scrolling.

import { VirtualizedList } from from "@mathewmathew1/virtualized-list";

const MyItem = ({ data, index, style }) => (
  <div style={style}>{data[index]}</div>
);

<VirtualizedList
  data={myItems}
  itemSize={40}
  direction="vertical"
  height={300}
  ItemComponent={MyItem}
/>

Props: VirtualizedListProps<T, Item>

PropTypeDescription
dataT[]Array of items to render
itemSizenumber | number[] \| ((index: number) => number)Fixed or variable size per item
ItemComponentReact.ComponentTypeComponent to render each item
direction"vertical" | "horizontal"Scroll direction
height / widthnumberViewport size (depending on direction)
overScanCountnumber (optional) 5 by defaultExtra items rendered outside viewport
onScroll(offset: number) => void (optional)Callback fired when scrolling
WrapperComponentReact.ComponentType<{ children: React.ReactNode }> (optional)Custom wrapper around list content
additionalDataany (optional)Additional props passed to ItemComponent

Props: VirtualizedTableProps<T, Item>

PropTypeRequiredDescription
rowCountnumberTotal number of rows.
columnCountnumberTotal number of columns.
rowHeightsnumber \| number[] \| ((index: number) => number)Height of each row (fixed or variable per index).
columnWidthsnumber \| number[] \| ((index: number) => number)Width of each column (fixed or variable per index).
heightnumberHeight of the visible table viewport.
widthnumberWidth of the visible table viewport.
CellComponentReact.ComponentType<{ rowIndex, columnIndex, style }>Component used to render individual cells.
overScanCountnumberAdditional rows/columns rendered beyond viewport for smoother scrolling. Default: 3.
onScroll(xOffset: number, yOffset: number) => voidCallback triggered on scroll.
WrapperComponentReact.ComponentType<{ children: React.ReactNode }>Optional wrapper around the entire table content.
headersPartial<Record<"top" \| "bottom" \| "left" \| "right", VirtualizedTableHeader>>Defines sticky headers for each table side.
AbsoluteElementComponentReact.ComponentType<{ currentLeftOffset: number; currentTopOffset: number }>Component rendered absolutely in scroll container (e.g. indicators, overlays).
additionalDataanyAdditional data passed to CellComponent.

Header type

  {
  type: "custom";
  size: number;
  component: React.ComponentType<{
    position: { left: number; top: number };
    visibleRows: { firstVisible: number; lastVisible: number };
    visibleColumns: { firstVisible: number; lastVisible: number };
  }>;
}
{
  type: "cell";
  size: number;
  component: React.ComponentType<{
    columnIndex: number;
    style: VirtualizedHeaderStyle;
  }>;
}

License MIT © MathewMathew1

2.0.1

7 months ago

2.0.0

7 months ago

1.2.0

7 months ago

1.1.0

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago