react-window 2.4.0 → 2.5.0
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.
- package/README.md +44 -0
- package/dist/react-window.cjs +1 -1
- package/dist/react-window.cjs.map +1 -1
- package/dist/react-window.d.ts +205 -2
- package/dist/react-window.js +1103 -750
- package/dist/react-window.js.map +1 -1
- package/package.json +4 -4
package/dist/react-window.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare function getScrollbarSize(recalculate?: boolean, ownerDocument?:
|
|
|
41
41
|
* ℹ️ Unlike `List` rows, `Grid` cell sizes must be known ahead of time.
|
|
42
42
|
* Either static sizes or something that can be derived (from the data in `CellProps`) without rendering.
|
|
43
43
|
*/
|
|
44
|
-
export declare function Grid<CellProps extends object, TagName extends TagNames = "div">({ cellComponent: CellComponentProp, cellProps: cellPropsUnstable, children, className, columnCount, columnKey, columnWidth, defaultHeight, defaultScrollLeft, defaultScrollTop, defaultWidth, dir, gridRef, onCellsRendered, onResize, overscanCount, rowCount, rowHeight, rowKey, style, tagName, ...rest }: GridProps<CellProps, TagName>): ReactElement;
|
|
44
|
+
export declare function Grid<CellProps extends object, TagName extends TagNames = "div">({ cellComponent: CellComponentProp, cellProps: cellPropsUnstable, children, className, columnCount, columnKey, columnWidth, defaultHeight, defaultScrollLeft, defaultScrollTop, defaultWidth, dir, gridRef, onCellsRendered, onResize, overscanCount, rowCount, rowHeight, rowKey, scrollElement, style, tagName, ...rest }: GridProps<CellProps, TagName>): ReactElement;
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Ref used to interact with this component's imperative API.
|
|
@@ -57,6 +57,8 @@ export declare interface GridImperativeAPI {
|
|
|
57
57
|
get element(): HTMLDivElement | null;
|
|
58
58
|
/**
|
|
59
59
|
* Scrolls the grid so that the specified row and column are visible.
|
|
60
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
61
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
60
62
|
*
|
|
61
63
|
* @param behavior Determines whether scrolling is instant or animates smoothly
|
|
62
64
|
* @param columnAlign Determines the horizontal alignment of the element within the grid
|
|
@@ -75,6 +77,8 @@ export declare interface GridImperativeAPI {
|
|
|
75
77
|
}) => void;
|
|
76
78
|
/**
|
|
77
79
|
* Scrolls the grid so that the specified column is visible.
|
|
80
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
81
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
78
82
|
*
|
|
79
83
|
* @param align Determines the horizontal alignment of the element within the grid
|
|
80
84
|
* @param behavior Determines whether scrolling is instant or animates smoothly
|
|
@@ -89,6 +93,8 @@ export declare interface GridImperativeAPI {
|
|
|
89
93
|
}) => void;
|
|
90
94
|
/**
|
|
91
95
|
* Scrolls the grid so that the specified row is visible.
|
|
96
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
97
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
92
98
|
*
|
|
93
99
|
* @param align Determines the vertical alignment of the element within the grid
|
|
94
100
|
* @param behavior Determines whether scrolling is instant or animates smoothly
|
|
@@ -225,6 +231,8 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
|
|
|
225
231
|
get element(): HTMLDivElement | null;
|
|
226
232
|
/**
|
|
227
233
|
* Scrolls the grid so that the specified row and column are visible.
|
|
234
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
235
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
228
236
|
*
|
|
229
237
|
* @param behavior Determines whether scrolling is instant or animates smoothly
|
|
230
238
|
* @param columnAlign Determines the horizontal alignment of the element within the grid
|
|
@@ -243,6 +251,8 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
|
|
|
243
251
|
}): void;
|
|
244
252
|
/**
|
|
245
253
|
* Scrolls the grid so that the specified column is visible.
|
|
254
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
255
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
246
256
|
*
|
|
247
257
|
* @param align Determines the horizontal alignment of the element within the grid
|
|
248
258
|
* @param behavior Determines whether scrolling is instant or animates smoothly
|
|
@@ -257,6 +267,8 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
|
|
|
257
267
|
}): void;
|
|
258
268
|
/**
|
|
259
269
|
* Scrolls the grid so that the specified row is visible.
|
|
270
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
271
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
260
272
|
*
|
|
261
273
|
* @param align Determines the vertical alignment of the element within the grid
|
|
262
274
|
* @param behavior Determines whether scrolling is instant or animates smoothly
|
|
@@ -328,6 +340,27 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
|
|
|
328
340
|
data: CellProps;
|
|
329
341
|
rowIndex: number;
|
|
330
342
|
}) => React.Key;
|
|
343
|
+
/**
|
|
344
|
+
* Element that scrolls the grid, for grids that scroll along with other content (e.g. the page):
|
|
345
|
+
* - "window" to scroll with the page
|
|
346
|
+
* - an ancestor element that scrolls (e.g. stored with a `useState` ref callback); `null` until it has mounted
|
|
347
|
+
*
|
|
348
|
+
* The grid renders at its full height and only renders the rows (and columns) visible within the scroll element's viewport.
|
|
349
|
+
* Its position within the scroll element is measured whenever it renders, scrolls, or resizes,
|
|
350
|
+
* and whenever content before it is resized, inserted, or removed (e.g. an image loading above the grid).
|
|
351
|
+
* - columns scroll with the scroll element too if the grid is as wide as its content (e.g. `style={{ width: "max-content" }}`);
|
|
352
|
+
* otherwise the grid fills the width of its parent and its columns scroll within it
|
|
353
|
+
* - `scrollToCell`, `scrollToColumn` and `scrollToRow` scroll whichever element scrolls each axis
|
|
354
|
+
* - `defaultHeight` and `defaultWidth` are used as the viewport size until the scroll element has been measured (e.g. during server rendering)
|
|
355
|
+
* - percentage row heights and column widths are relative to the scroll element's viewport
|
|
356
|
+
* - `defaultScrollLeft` and `defaultScrollTop` are ignored
|
|
357
|
+
*
|
|
358
|
+
* ℹ️ While the scroll element is `null`, the grid renders the first rows (as it does during server rendering).
|
|
359
|
+
*
|
|
360
|
+
* ⚠️ The grid's `onScroll` handler is only called when the grid scrolls its own columns;
|
|
361
|
+
* listen to the scroll element's "scroll" events instead (or use the `useIsScrolling` hook).
|
|
362
|
+
*/
|
|
363
|
+
scrollElement?: "window" | HTMLElement | null;
|
|
331
364
|
/**
|
|
332
365
|
* Optional CSS properties.
|
|
333
366
|
* The grid of cells will fill the height and width defined by this style.
|
|
@@ -345,7 +378,7 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
|
|
|
345
378
|
/**
|
|
346
379
|
* Renders data with many rows.
|
|
347
380
|
*/
|
|
348
|
-
export declare function List<RowProps extends object, TagName extends TagNames = "div">({ children, className, defaultHeight, defaultScrollOffset, listRef, onResize, onRowsRendered, overscanCount, rowComponent: RowComponentProp, rowCount, rowHeight: rowHeightProp, rowKey, rowProps: rowPropsUnstable, tagName, style, ...rest }: ListProps<RowProps, TagName>): ReactElement;
|
|
381
|
+
export declare function List<RowProps extends object, TagName extends TagNames = "div">({ children, className, defaultHeight, defaultScrollOffset, listRef, onResize, onRowsRendered, overscanCount, rowComponent: RowComponentProp, rowCount, rowHeight: rowHeightProp, rowKey, rowProps: rowPropsUnstable, scrollElement, tagName, style, ...rest }: ListProps<RowProps, TagName>): ReactElement;
|
|
349
382
|
|
|
350
383
|
/**
|
|
351
384
|
* Imperative List API.
|
|
@@ -359,6 +392,8 @@ export declare interface ListImperativeAPI {
|
|
|
359
392
|
get element(): HTMLDivElement | null;
|
|
360
393
|
/**
|
|
361
394
|
* Scrolls the list so that the specified row is visible.
|
|
395
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
396
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
362
397
|
*
|
|
363
398
|
* Dynamic row heights are measured after rendering;
|
|
364
399
|
* Content that resizes later may require another scrollToRow call.
|
|
@@ -422,6 +457,8 @@ export declare type ListProps<RowProps extends object, TagName extends TagNames
|
|
|
422
457
|
get element(): HTMLDivElement | null;
|
|
423
458
|
/**
|
|
424
459
|
* Scrolls the list so that the specified row is visible.
|
|
460
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
461
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
425
462
|
*
|
|
426
463
|
* Dynamic row heights are measured after rendering;
|
|
427
464
|
* Content that resizes later may require another scrollToRow call.
|
|
@@ -520,6 +557,25 @@ export declare type ListProps<RowProps extends object, TagName extends TagNames
|
|
|
520
557
|
* ⚠️ This object must not contain `ariaAttributes`, `index`, or `style` props.
|
|
521
558
|
*/
|
|
522
559
|
rowProps: ExcludeForbiddenKeys_2<RowProps>;
|
|
560
|
+
/**
|
|
561
|
+
* Element that scrolls the list, for lists that scroll along with other content (e.g. the page):
|
|
562
|
+
* - "window" to scroll with the page
|
|
563
|
+
* - an ancestor element that scrolls (e.g. stored with a `useState` ref callback); `null` until it has mounted
|
|
564
|
+
*
|
|
565
|
+
* The list renders at its full height and only renders the rows visible within the scroll element's viewport.
|
|
566
|
+
* Its position within the scroll element is measured whenever it renders, scrolls, or resizes,
|
|
567
|
+
* and whenever content before it is resized, inserted, or removed (e.g. an image loading above the list).
|
|
568
|
+
* - `scrollToRow` scrolls the scroll element
|
|
569
|
+
* - `defaultHeight` is used as the viewport height until the scroll element has been measured (e.g. during server rendering)
|
|
570
|
+
* - percentage row heights are relative to the scroll element's viewport height
|
|
571
|
+
* - `defaultScrollOffset` is ignored
|
|
572
|
+
*
|
|
573
|
+
* ℹ️ While the scroll element is `null`, the list renders the first rows (as it does during server rendering).
|
|
574
|
+
*
|
|
575
|
+
* ⚠️ The list itself doesn't scroll, so its `onScroll` handler isn't called;
|
|
576
|
+
* listen to the scroll element's "scroll" events instead (or use the `useIsScrolling` hook).
|
|
577
|
+
*/
|
|
578
|
+
scrollElement?: "window" | HTMLElement | null;
|
|
523
579
|
/**
|
|
524
580
|
* Optional CSS properties.
|
|
525
581
|
* The list of rows will fill the height defined by this style.
|
|
@@ -574,6 +630,29 @@ export declare const useGridCallbackRef: typeof useState<GridImperativeAPI | nul
|
|
|
574
630
|
*/
|
|
575
631
|
export declare const useGridRef: typeof useRef<GridImperativeAPI>;
|
|
576
632
|
|
|
633
|
+
/**
|
|
634
|
+
* Tracks whether an element (or the window) is currently scrolling,
|
|
635
|
+
* e.g. to render simplified content in place of rows that are expensive to render.
|
|
636
|
+
*
|
|
637
|
+
* Pass the element that scrolls:
|
|
638
|
+
* - a list or grid's own element (e.g. from `useListCallbackRef`)
|
|
639
|
+
* - "window" or the scroll element, for lists and grids that use the `scrollElement` prop
|
|
640
|
+
*
|
|
641
|
+
* Scrolling ends when the browser fires a "scrollend" event or,
|
|
642
|
+
* in browsers that don't support that event, after no scroll events have been received for `delay` milliseconds.
|
|
643
|
+
*
|
|
644
|
+
* ℹ️ Scrolling that starts and ends before React renders (e.g. an instant scroll) may not change this value.
|
|
645
|
+
*
|
|
646
|
+
* ⚠️ Changing this value re-renders any rows it is passed to (e.g. via `rowProps`) when scrolling starts and when it ends.
|
|
647
|
+
*/
|
|
648
|
+
export declare function useIsScrolling(target: "window" | HTMLElement | null | undefined, { delay }?: {
|
|
649
|
+
/**
|
|
650
|
+
* Milliseconds without scroll events after which scrolling is considered to have ended
|
|
651
|
+
* (only used by browsers that don't support the "scrollend" event); defaults to 150.
|
|
652
|
+
*/
|
|
653
|
+
delay?: number;
|
|
654
|
+
}): boolean;
|
|
655
|
+
|
|
577
656
|
/**
|
|
578
657
|
* Convenience hook to return a properly typed ref callback for the List component.
|
|
579
658
|
*
|
|
@@ -586,4 +665,128 @@ export declare const useListCallbackRef: typeof useState<ListImperativeAPI | nul
|
|
|
586
665
|
*/
|
|
587
666
|
export declare const useListRef: typeof useRef<ListImperativeAPI>;
|
|
588
667
|
|
|
668
|
+
/**
|
|
669
|
+
* Calculates which items to render, and where, for custom (headless) virtualized content
|
|
670
|
+
* (e.g. a `<table>` or a custom layout).
|
|
671
|
+
*
|
|
672
|
+
* The returned items are positioned relative to the start of the element's content;
|
|
673
|
+
* how they are rendered (e.g. absolute positioning or spacer elements) is up to the caller.
|
|
674
|
+
*/
|
|
675
|
+
export declare function useVirtualizer({ count, defaultScrollOffset, defaultSize, dir, direction, element, itemSize: itemSizeOption, onItemsRendered, overscanCount, scrollElement }: VirtualizerOptions): Virtualizer;
|
|
676
|
+
|
|
677
|
+
export declare type VirtualItem = {
|
|
678
|
+
/**
|
|
679
|
+
* Index of the item.
|
|
680
|
+
*/
|
|
681
|
+
index: number;
|
|
682
|
+
/**
|
|
683
|
+
* Offset (in pixels) of the item from the start of the element's content.
|
|
684
|
+
*/
|
|
685
|
+
offset: number;
|
|
686
|
+
/**
|
|
687
|
+
* Size (in pixels) of the item; an estimate for dynamic sizes that have not yet been measured.
|
|
688
|
+
*/
|
|
689
|
+
size: number;
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
export declare type Virtualizer = {
|
|
693
|
+
/**
|
|
694
|
+
* Items to render (including overscan).
|
|
695
|
+
*/
|
|
696
|
+
items: VirtualItem[];
|
|
697
|
+
/**
|
|
698
|
+
* Ref callback for rendered items, required for items with dynamic sizes (see `itemSize`).
|
|
699
|
+
*/
|
|
700
|
+
measureElement: (element: Element | null) => void;
|
|
701
|
+
/**
|
|
702
|
+
* Scrolls the element (or scroll element) so that the specified item is visible.
|
|
703
|
+
* Like the browser's `scrollIntoView`, items are aligned within the CSS `scroll-padding` of the element being scrolled
|
|
704
|
+
* (e.g. `scroll-padding-top` can leave room for a sticky header).
|
|
705
|
+
*
|
|
706
|
+
* @throws RangeError if an invalid index is provided
|
|
707
|
+
*/
|
|
708
|
+
scrollToIndex: (options: {
|
|
709
|
+
align?: Align;
|
|
710
|
+
behavior?: ScrollBehavior;
|
|
711
|
+
index: number;
|
|
712
|
+
}) => void;
|
|
713
|
+
/**
|
|
714
|
+
* Total size (in pixels) of all items; an estimate for dynamic sizes that have not yet been measured.
|
|
715
|
+
*/
|
|
716
|
+
totalSize: number;
|
|
717
|
+
/**
|
|
718
|
+
* Range of items within the visible area (excluding overscan).
|
|
719
|
+
*/
|
|
720
|
+
visibleRange: {
|
|
721
|
+
startIndex: number;
|
|
722
|
+
stopIndex: number;
|
|
723
|
+
};
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
export declare type VirtualizerOptions = {
|
|
727
|
+
/**
|
|
728
|
+
* Number of items.
|
|
729
|
+
*/
|
|
730
|
+
count: number;
|
|
731
|
+
/**
|
|
732
|
+
* Initial scroll offset (in pixels), applied once when the element first mounts with at least one item.
|
|
733
|
+
*
|
|
734
|
+
* ℹ️ Ignored when a `scrollElement` is specified.
|
|
735
|
+
*/
|
|
736
|
+
defaultScrollOffset?: number;
|
|
737
|
+
/**
|
|
738
|
+
* Size (in pixels) of the viewport before it has been measured (e.g. during server rendering);
|
|
739
|
+
* this determines how many items are initially rendered.
|
|
740
|
+
*/
|
|
741
|
+
defaultSize?: number;
|
|
742
|
+
/**
|
|
743
|
+
* Direction of horizontal content; detected from the element (or its ancestors) by default.
|
|
744
|
+
*/
|
|
745
|
+
dir?: "ltr" | "rtl";
|
|
746
|
+
/**
|
|
747
|
+
* Direction that items are laid out in; defaults to "vertical".
|
|
748
|
+
*/
|
|
749
|
+
direction?: "horizontal" | "vertical";
|
|
750
|
+
/**
|
|
751
|
+
* Element that scrolls the items or, if a `scrollElement` is specified, the element that contains the items.
|
|
752
|
+
*
|
|
753
|
+
* ℹ️ Item offsets are relative to the start of this element's content.
|
|
754
|
+
*/
|
|
755
|
+
element: HTMLElement | null;
|
|
756
|
+
/**
|
|
757
|
+
* Item size; the following formats are supported:
|
|
758
|
+
* - number of pixels (number)
|
|
759
|
+
* - percentage of the viewport's size (string)
|
|
760
|
+
* - function that returns the item size (in pixels) given an index
|
|
761
|
+
* - dynamic row height cache returned by the `useDynamicRowHeight` hook (vertical only);
|
|
762
|
+
* rendered items must be passed to `measureElement` and specify a `data-index` attribute
|
|
763
|
+
*
|
|
764
|
+
* ℹ️ Sizes are cached until the value of this option changes;
|
|
765
|
+
* memoize functions (e.g. with `useCallback`) and only change them when sizes change.
|
|
766
|
+
*/
|
|
767
|
+
itemSize: number | string | ((index: number) => number) | DynamicRowHeight;
|
|
768
|
+
/**
|
|
769
|
+
* Callback notified when the range of visible (or rendered) items changes.
|
|
770
|
+
*/
|
|
771
|
+
onItemsRendered?: (visibleItems: {
|
|
772
|
+
startIndex: number;
|
|
773
|
+
stopIndex: number;
|
|
774
|
+
}, allItems: {
|
|
775
|
+
startIndex: number;
|
|
776
|
+
stopIndex: number;
|
|
777
|
+
}) => void;
|
|
778
|
+
/**
|
|
779
|
+
* How many additional items to render outside of the visible area; defaults to 3.
|
|
780
|
+
*/
|
|
781
|
+
overscanCount?: number;
|
|
782
|
+
/**
|
|
783
|
+
* Element that scrolls the items, for items that scroll along with other content (e.g. the page):
|
|
784
|
+
* - "window" to scroll with the page
|
|
785
|
+
* - an ancestor element that scrolls; `null` until it has mounted
|
|
786
|
+
*
|
|
787
|
+
* See the `scrollElement` prop of `List` for more information.
|
|
788
|
+
*/
|
|
789
|
+
scrollElement?: "window" | HTMLElement | null;
|
|
790
|
+
};
|
|
791
|
+
|
|
589
792
|
export { }
|