virtualized-ui 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +192 -0
  2. package/package.json +9 -9
  3. package/LICENSE +0 -21
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # virtualized-ui
2
+
3
+ Headless virtualized table primitives for React. Built on [TanStack Table](https://tanstack.com/table) and [TanStack Virtual](https://tanstack.com/virtual).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install virtualized-ui
9
+ # or
10
+ pnpm add virtualized-ui
11
+ # or
12
+ yarn add virtualized-ui
13
+ ```
14
+
15
+ **Peer dependencies:** React 18+
16
+
17
+ ## Features
18
+
19
+ - **Virtualization** - Efficiently render thousands of rows
20
+ - **Sorting** - Single and multi-column sorting
21
+ - **Row Selection** - Checkbox or click-based selection
22
+ - **Row Expansion** - Expandable rows with variable heights
23
+ - **Column Resizing** - Drag to resize columns
24
+ - **Column Reordering** - Drag and drop columns
25
+ - **Keyboard Navigation** - Arrow keys, Home/End, Space/Enter
26
+ - **Infinite Scroll** - Load more data on scroll
27
+ - **Controlled & Uncontrolled** - Flexible state management
28
+
29
+ ## Quick Start
30
+
31
+ ```tsx
32
+ import { useVirtualTable } from 'virtualized-ui';
33
+ import { createColumnHelper } from '@tanstack/react-table';
34
+
35
+ interface Person {
36
+ id: number;
37
+ name: string;
38
+ age: number;
39
+ }
40
+
41
+ const columnHelper = createColumnHelper<Person>();
42
+
43
+ const columns = [
44
+ columnHelper.accessor('name', { header: 'Name' }),
45
+ columnHelper.accessor('age', { header: 'Age' }),
46
+ ];
47
+
48
+ function MyTable({ data }: { data: Person[] }) {
49
+ const {
50
+ table,
51
+ rows,
52
+ virtualItems,
53
+ totalSize,
54
+ containerRef,
55
+ } = useVirtualTable({
56
+ data,
57
+ columns,
58
+ });
59
+
60
+ return (
61
+ <div ref={containerRef} style={{ height: 400, overflow: 'auto' }}>
62
+ <div style={{ height: totalSize, position: 'relative' }}>
63
+ {virtualItems.map((virtualRow) => {
64
+ const row = rows[virtualRow.index];
65
+ return (
66
+ <div
67
+ key={row.id}
68
+ style={{
69
+ position: 'absolute',
70
+ top: virtualRow.start,
71
+ height: virtualRow.size,
72
+ }}
73
+ >
74
+ {row.getVisibleCells().map((cell) => (
75
+ <span key={cell.id}>
76
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
77
+ </span>
78
+ ))}
79
+ </div>
80
+ );
81
+ })}
82
+ </div>
83
+ </div>
84
+ );
85
+ }
86
+ ```
87
+
88
+ ## API
89
+
90
+ ### `useVirtualTable<TData>(options)`
91
+
92
+ The main hook that combines TanStack Table with TanStack Virtual.
93
+
94
+ #### Options
95
+
96
+ | Option | Type | Default | Description |
97
+ |--------|------|---------|-------------|
98
+ | `data` | `TData[]` | required | The data array |
99
+ | `columns` | `ColumnDef<TData>[]` | required | Column definitions |
100
+ | `rowHeight` | `number` | `40` | Height of each row in pixels |
101
+ | `overscan` | `number` | `5` | Number of rows to render outside viewport |
102
+ | `enableRowSelection` | `boolean` | `false` | Enable row selection |
103
+ | `rowSelection` | `RowSelectionState` | - | Controlled selection state |
104
+ | `onRowSelectionChange` | `(state) => void` | - | Selection change callback |
105
+ | `enableSorting` | `boolean` | `false` | Enable column sorting |
106
+ | `enableMultiSort` | `boolean` | `false` | Enable multi-column sorting |
107
+ | `sorting` | `SortingState` | - | Controlled sorting state |
108
+ | `onSortingChange` | `(state) => void` | - | Sorting change callback |
109
+ | `enableRowExpansion` | `boolean` | `false` | Enable expandable rows |
110
+ | `expandedRowHeight` | `number` | `200` | Additional height for expanded rows |
111
+ | `expanded` | `ExpandedState` | - | Controlled expansion state |
112
+ | `onExpandedChange` | `(state) => void` | - | Expansion change callback |
113
+ | `enableColumnResizing` | `boolean` | `false` | Enable column resizing |
114
+ | `columnResizeMode` | `'onChange' \| 'onEnd'` | `'onChange'` | When to update sizes |
115
+ | `enableColumnReordering` | `boolean` | `false` | Enable column reordering |
116
+ | `enableKeyboardNavigation` | `boolean` | `false` | Enable keyboard navigation |
117
+ | `onScrollToBottom` | `() => void` | - | Called when scrolled near bottom |
118
+ | `scrollBottomThreshold` | `number` | `100` | Pixels from bottom to trigger callback |
119
+ | `getRowId` | `(row) => string` | - | Custom row ID function |
120
+
121
+ #### Returns
122
+
123
+ | Property | Type | Description |
124
+ |----------|------|-------------|
125
+ | `table` | `Table<TData>` | TanStack Table instance |
126
+ | `rows` | `Row<TData>[]` | Processed rows from table |
127
+ | `virtualizer` | `Virtualizer` | TanStack Virtual instance |
128
+ | `virtualItems` | `VirtualItem[]` | Currently visible virtual items |
129
+ | `totalSize` | `number` | Total scrollable height |
130
+ | `containerRef` | `RefObject<HTMLDivElement>` | Ref for scroll container |
131
+ | `handleScroll` | `() => void` | Scroll handler for infinite scroll |
132
+ | `handleKeyDown` | `(e) => void` | Keyboard event handler |
133
+ | `reorderColumn` | `(from, to) => void` | Reorder columns helper |
134
+ | `setFocusedRow` | `(index) => void` | Set focused row index |
135
+ | `rowSelection` | `RowSelectionState` | Current selection state |
136
+ | `sorting` | `SortingState` | Current sorting state |
137
+ | `expanded` | `ExpandedState` | Current expansion state |
138
+ | `columnSizing` | `ColumnSizingState` | Current column sizes |
139
+ | `columnOrder` | `ColumnOrderState` | Current column order |
140
+ | `focusedRowIndex` | `number` | Currently focused row |
141
+
142
+ ## Examples
143
+
144
+ ### With Row Expansion
145
+
146
+ ```tsx
147
+ const { table, rows, virtualItems, totalSize, containerRef } = useVirtualTable({
148
+ data,
149
+ columns,
150
+ enableRowExpansion: true,
151
+ rowHeight: 52,
152
+ expandedRowHeight: 200,
153
+ });
154
+ ```
155
+
156
+ ### With Infinite Scroll
157
+
158
+ ```tsx
159
+ const { containerRef, handleScroll } = useVirtualTable({
160
+ data,
161
+ columns,
162
+ onScrollToBottom: () => fetchNextPage(),
163
+ scrollBottomThreshold: 500,
164
+ });
165
+
166
+ return (
167
+ <div ref={containerRef} onScroll={handleScroll} style={{ height: 400, overflow: 'auto' }}>
168
+ {/* ... */}
169
+ </div>
170
+ );
171
+ ```
172
+
173
+ ### With Sorting
174
+
175
+ ```tsx
176
+ const { table, sorting } = useVirtualTable({
177
+ data,
178
+ columns,
179
+ enableSorting: true,
180
+ enableMultiSort: true,
181
+ });
182
+
183
+ // In header:
184
+ <th onClick={header.column.getToggleSortingHandler()}>
185
+ {header.column.columnDef.header}
186
+ {header.column.getIsSorted() === 'asc' ? ' ↑' : header.column.getIsSorted() === 'desc' ? ' ↓' : ''}
187
+ </th>
188
+ ```
189
+
190
+ ## License
191
+
192
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtualized-ui",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Headless virtualized table and select components for React",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,6 +22,13 @@
22
22
  "dist"
23
23
  ],
24
24
  "sideEffects": false,
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "typecheck": "tsc --noEmit",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest"
31
+ },
25
32
  "keywords": [
26
33
  "react",
27
34
  "virtual",
@@ -63,12 +70,5 @@
63
70
  "tsup": "^8.3.0",
64
71
  "typescript": "^5.6.0",
65
72
  "vitest": "^4.0.18"
66
- },
67
- "scripts": {
68
- "build": "tsup",
69
- "dev": "tsup --watch",
70
- "typecheck": "tsc --noEmit",
71
- "test": "vitest run",
72
- "test:watch": "vitest"
73
73
  }
74
- }
74
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Greg Levine-Rozenvayn
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.