@candidstartup/react-virtual-scroll 0.4.0 → 0.6.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/dist/index.d.ts CHANGED
@@ -1,108 +1,637 @@
1
- import React from 'react';
1
+ import React$1 from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
3
 
3
- interface VirtualBaseItemProps {
4
- data: any;
4
+ /**
5
+ * Props that an implementation of {@link VirtualContainerRender} must accept.
6
+ *
7
+ * Includes all the props that a {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLDivElement | HTMLDivElement} would accept.
8
+ */
9
+ type VirtualContainerRenderProps = React$1.ComponentPropsWithoutRef<'div'>;
10
+ /**
11
+ * Render prop for a {@link VirtualContainer}
12
+ *
13
+ * Can be passed to {@link VirtualContainer} to replace default implementation.
14
+ * Function must render a div and forward {@link VirtualContainerRenderProps}
15
+ * and any `ref` to it.
16
+ *
17
+ * @example Minimal compliant implementation
18
+ * ```
19
+ * const containerRender: VirtualContainerRender = ({...rest}, ref) => (
20
+ * <div ref={ref} {...rest} />
21
+ * )
22
+ * ```
23
+ */
24
+ type VirtualContainerRender = (props: VirtualContainerRenderProps, ref?: React$1.ForwardedRef<HTMLDivElement>) => JSX.Element;
25
+ /**
26
+ * Props that {@link VirtualContainer} accepts.
27
+ */
28
+ interface VirtualContainerComponentProps extends VirtualContainerRenderProps {
29
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualContainer}. */
30
+ render?: VirtualContainerRender;
31
+ }
32
+ /**
33
+ * Wrapper around a div used by other components in {@link @candidstartup/react-virtual-scroll!}. Most props are passed through to the div. Use the
34
+ * {@link VirtualContainerComponentProps.render} prop to override the default behavior.
35
+ *
36
+ * @group Components
37
+ */
38
+ declare const VirtualContainer: React$1.ForwardRefExoticComponent<VirtualContainerComponentProps & React$1.RefAttributes<HTMLDivElement>>;
39
+
40
+ /**
41
+ * Props that an implementation of {@link AutoSizerRender} must accept.
42
+ */
43
+ interface AutoSizerRenderProps {
44
+ /** Computed height */
45
+ height: number;
46
+ /** Computed width */
47
+ width: number;
48
+ }
49
+ /**
50
+ * Render prop for content in an {@link AutoSizer}
51
+ *
52
+ * Function renders content and forwards `width` and `height`
53
+ * to whatever needs it.
54
+ *
55
+ * @example Simple implementation
56
+ * ```
57
+ * const autoSizeRender: AutoSizeRender = ({width, height}) => (
58
+ * <VirtualList width={width} height={height} {...props} />
59
+ * )
60
+ * ```
61
+ */
62
+ type AutoSizerRender = (props: AutoSizerRenderProps) => JSX.Element;
63
+ /**
64
+ * Props accepted by {@link AutoSizer}
65
+ */
66
+ interface AutoSizerProps {
67
+ /** Function implementing {@link AutoSizerRender} that renders the content that needs explicit sizing */
68
+ children: AutoSizerRender;
69
+ /** The `className` applied to the container element */
70
+ className?: string;
71
+ /** Inline style to apply to the container element */
72
+ style?: React$1.CSSProperties;
73
+ }
74
+ /**
75
+ * HOC that calculates the size available to it and makes the computed size available to children.
76
+ * The size available depends on DOM layout and style applied wherever the AutoSizer finds itself.
77
+ * You will probably want to pass something appropriate via the `className` or `style` props.
78
+ *
79
+ * Accepts props defined by {@link AutoSizerProps}.
80
+ * You must pass a single instance of {@link AutoSizerRender} as a child.
81
+ * @group Components
82
+ */
83
+ declare function AutoSizer(props: AutoSizerProps): react_jsx_runtime.JSX.Element;
84
+
85
+ /**
86
+ * Common props for {@link DisplayListItem} and {@link DisplayGridItem}
87
+ */
88
+ interface DisplayBaseItemProps {
89
+ /** Value of {@link DisplayBaseProps.itemData} from owning component */
90
+ data: unknown;
91
+ /**
92
+ * Is the owning component being actively scrolled? Used to change how the item is rendered depending on scroll state.
93
+ *
94
+ * Value passed through from {@link DisplayBaseProps.isScrolling}.
95
+ * */
5
96
  isScrolling?: boolean;
6
- style: React.CSSProperties;
97
+ /** Style that should be applied to each item rendered. Positions the item within the inner container. */
98
+ style: React$1.CSSProperties;
7
99
  }
8
- interface VirtualBaseProps {
100
+ /**
101
+ * Common props for all components
102
+ */
103
+ interface ComponentProps {
104
+ /** The `className` applied to the outer container element. Use when styling the entire component. */
9
105
  className?: string;
106
+ /** The `className` applied to the inner container element. Use for special cases when styling only the inner container and items. */
10
107
  innerClassName?: string;
108
+ /** Component height */
11
109
  height: number;
110
+ /** Component width */
12
111
  width: number;
13
- itemData?: any;
112
+ }
113
+ /**
114
+ * Common props for {@link DisplayList} and {@link DisplayGrid}
115
+ */
116
+ interface DisplayBaseProps extends ComponentProps {
117
+ /** Passed as {@link DisplayBaseItemProps.data} to each child item */
118
+ itemData?: unknown;
119
+ /** Passed as {@link DisplayBaseItemProps.isScrolling} to each child item
120
+ *
121
+ * Provided as a convenience when combining display components with {@link VirtualScroll}
122
+ * Not interpreted by the display component itself
123
+ */
124
+ isScrolling?: boolean;
125
+ /**
126
+ * Renders the outer viewport div which provides a window onto the inner grid div
127
+ *
128
+ * Render prop implementing {@link VirtualContainerRender}. Used to customize display component outer container.
129
+ */
130
+ outerRender?: VirtualContainerRender;
131
+ /**
132
+ * Renders the inner grid div containing all the list items
133
+ *
134
+ * Render prop implementing {@link VirtualContainerRender}. Used to customize display component inner container.
135
+ */
136
+ innerRender?: VirtualContainerRender;
137
+ }
138
+ /**
139
+ * Common props for all virtual scrollable components
140
+ */
141
+ interface VirtualScrollableProps extends ComponentProps {
142
+ /**
143
+ * Determines whether the component should track whether it's being actively scrolled
144
+ * and pass through when rendering its content.
145
+ *
146
+ * @defaultValue false
147
+ * */
14
148
  useIsScrolling?: boolean;
149
+ /**
150
+ * Maximum size for CSS element beyond which layout breaks. You should never normally need to change this.
151
+ * The default value is compatible with all major browsers.
152
+ *
153
+ * @defaultValue 6000000
154
+ * */
15
155
  maxCssSize?: number;
156
+ /**
157
+ * The minimum number of virtual pages to use when inner container would otherwise be more than {@link VirtualScrollableProps.maxCssSize} big.
158
+ * You should never normally need to change this.
159
+ *
160
+ * @defaultValue 100
161
+ */
16
162
  minNumPages?: number;
17
163
  }
18
- interface VirtualInnerProps {
19
- className: string | undefined;
20
- children: React.ReactNode;
21
- style: React.CSSProperties;
22
- }
23
- type VirtualInnerComponent = React.ComponentType<VirtualInnerProps>;
24
- interface VirtualOuterProps {
25
- className: string | undefined;
26
- children: React.ReactNode;
27
- style: React.CSSProperties;
28
- onScroll: (event: ScrollEvent) => void;
164
+ /**
165
+ * Common props for {@link VirtualList} and {@link VirtualGrid}
166
+ */
167
+ interface VirtualBaseProps extends VirtualScrollableProps {
168
+ /** Passed as {@link DisplayBaseItemProps.data} to each child item */
169
+ itemData?: unknown;
29
170
  }
30
- type VirtualOuterComponent = React.ComponentType<VirtualOuterProps>;
171
+ /**
172
+ * Interface that {@link VirtualList} and {@link VirtualGrid} use to determine size and
173
+ * positioning offset for items in a single dimension.
174
+ */
31
175
  interface ItemOffsetMapping {
176
+ /** Size of item with given index */
32
177
  itemSize(itemIndex: number): number;
178
+ /** Offset from start of container to specified item
179
+ *
180
+ * `itemOffset(n)` should be equal to `Sum{i:0->n-1}(itemSize(i))`
181
+ *
182
+ * To efficiently support large containers, cost should be `O(logn)` or better.
183
+ */
33
184
  itemOffset(itemIndex: number): number;
185
+ /** Given an offset, return the index of the item that intersects that offset, together with the start offset of that item */
34
186
  offsetToItem(offset: number): [itemIndex: number, startOffset: number];
35
187
  }
36
- type ScrollEvent = React.SyntheticEvent<HTMLDivElement>;
188
+ /** Alias for type of event that React passes to a `div` element's `OnScroll` handler. */
189
+ type ScrollEvent = React$1.SyntheticEvent<HTMLDivElement>;
190
+ /**
191
+ * Option for {@link VirtualGridProxy.scrollToItem} and {@link VirtualListProxy.scrollToItem}
192
+ *
193
+ * * `topleft` scrolls the item as far to the top and left as possible
194
+ * * `visible` scrolls the item the minimum amount needed to ensure that it's visible
195
+ *
196
+ * @defaultValue `topleft`
197
+ */
198
+ type ScrollToOption = 'topleft' | 'visible';
199
+ /** Specifies the direction over which lists should implement virtual scrolling */
200
+ type ScrollLayout = "horizontal" | "vertical";
37
201
 
202
+ /** Direction of scrolling */
38
203
  type ScrollDirection = "forward" | "backward";
204
+ /**
205
+ * Overall scroll state for a single dimension.
206
+ */
39
207
  interface ScrollState {
208
+ /** Scroll bar offset. Equal to outer container's `scrollTop` or `scrollLeft` depending on dimension. */
40
209
  scrollOffset: number;
210
+ /** Offset used to position current page of items in virtual space. Overall offset is `scrollOffset+renderOffset`. */
41
211
  renderOffset: number;
212
+ /** Index of current page. */
42
213
  page: number;
214
+ /** Current scrolling direction. Calculated by comparing current overall offset to that when last rendered. */
43
215
  scrollDirection: ScrollDirection;
44
216
  }
45
217
 
46
- interface VirtualGridItemProps extends VirtualBaseItemProps {
218
+ /**
219
+ * Custom ref handle returned by {@link VirtualScroll} that exposes imperative methods
220
+ *
221
+ * Use `React.useRef<VirtualScrollProxy>(null)` to create a ref.
222
+ */
223
+ interface VirtualScrollProxy {
224
+ /**
225
+ * Scrolls to the specified vertical and horizontal offset in pixels
226
+ * Either offset can be left undefined to scroll in one dimension only
227
+ * @param verticalOffset - Offset to scroll to vertically
228
+ * @param horizontalOffset - Offset to scroll to horizontally
229
+ */
230
+ scrollTo(verticalOffset?: number, horizontalOffset?: number): void;
231
+ /**
232
+ * Scrolls to the specified area
233
+ * Either offset/size pair can be left undefined to scroll in one dimension only
234
+ * @param verticalOffset - Offset to scroll to vertically
235
+ * @param verticalSize - Size of target area vertically
236
+ * @param horizontalOffset - Offset to scroll to horizontally
237
+ * @param horizontalSize - Size of target area horizontally
238
+ * @param option - Where to {@link ScrollToOption | position} the area within the viewport
239
+ */
240
+ scrollToArea(verticalOffset?: number, verticalSize?: number, horizontalOffset?: number, horizontalSize?: number, option?: ScrollToOption): void;
241
+ /** Exposes DOM clientWidth property */
242
+ get clientWidth(): number;
243
+ /** Exposes DOM clientHeight property */
244
+ get clientHeight(): number;
245
+ }
246
+ /**
247
+ * Returns the offset needed to scroll in one dimension for a specified range
248
+ *
249
+ * Used internally to implement {@link VirtualScrollProxy.scrollToArea}. Can be used directly for
250
+ * advanced customization scenarios.
251
+ */
252
+ declare function getOffsetToScrollRange(offset: number | undefined, size: number | undefined, clientExtent: number, scrollOffset: number, option?: ScrollToOption): number | undefined;
253
+
254
+ /**
255
+ * Props that an implementation of {@link VirtualContentRender} must accept.
256
+ */
257
+ interface VirtualContentProps {
258
+ /**
259
+ * Is the owning component being actively scrolled? Used to change how the content is rendered depending on scroll state.
260
+ *
261
+ * Only defined if {@link VirtualScrollableProps.useIsScrolling} is true.
262
+ * */
263
+ isScrolling?: boolean;
264
+ }
265
+ /**
266
+ * Render prop for content container in {@link VirtualScroll}
267
+ *
268
+ * Pass to {@link VirtualScroll} to render content into the viewport
269
+ * implementation. Function must render a div and forward {@link VirtualContentProps}
270
+ * and any `ref` to it.
271
+ *
272
+ * @example Minimal compliant implementation
273
+ * ```
274
+ * const contentRender: VirtualContentRender = ({isScrolling, ...rest}, ref) => (
275
+ * <div ref={ref} {...rest} />
276
+ * )
277
+ * ```
278
+ */
279
+ type VirtualContentRender = (props: VirtualContentProps, ref?: React$1.ForwardedRef<HTMLDivElement>) => JSX.Element;
280
+ /**
281
+ * Props accepted by {@link VirtualScroll}
282
+ */
283
+ interface VirtualScrollProps extends VirtualScrollableProps {
284
+ /** Function implementing {@link VirtualContentRender} that renders the content that needs to respond to scrolling */
285
+ children: VirtualContentRender;
286
+ /**
287
+ * Height of area to scroll over
288
+ *
289
+ * @defaultValue 0
290
+ */
291
+ scrollHeight?: number;
292
+ /**
293
+ * Width of area to scroll over
294
+ *
295
+ * @defaultValue 0
296
+ */
297
+ scrollWidth?: number;
298
+ /**
299
+ * Callback after a scroll event has been processed and state updated but before rendering
300
+ * @param verticalOffset - Resulting overall vertical offset.
301
+ * @param horizontalOffset - Resulting overall horizontal offset.
302
+ * @param newVerticalScrollState - New vertical {@link ScrollState} that will be used for rendering.
303
+ * @param newHorizontalScrollState - New horizontal {@link ScrollState} that will be used for rendering.
304
+ */
305
+ onScroll?: (verticalOffset: number, horizontalOffset: number, newVerticalScrollState: ScrollState, newHorizontalScrollState: ScrollState) => void;
306
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualScroll} outer container. */
307
+ outerRender?: VirtualContainerRender;
308
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualScroll} inner container. */
309
+ innerRender?: VirtualContainerRender;
310
+ }
311
+ /**
312
+ * Customizable Virtual Scrolling Component
313
+ *
314
+ * Allows user to scroll over a virtual area `scrollHeight` x `scrollWidth` pixels.
315
+ * Use `onScroll` to track scroll state and `innerRender` to render scroll state specific content into the viewport
316
+ *
317
+ * Accepts props defined by {@link VirtualScrollProps}.
318
+ * Refs are forwarded to {@link VirtualScrollProxy}.
319
+ * @group Components
320
+ */
321
+ declare const VirtualScroll: React$1.ForwardRefExoticComponent<VirtualScrollProps & React$1.RefAttributes<VirtualScrollProxy>>;
322
+
323
+ /**
324
+ * Props accepted by {@link DisplayListItem}
325
+ */
326
+ interface DisplayListItemProps extends DisplayBaseItemProps {
327
+ /** Index of item in the list being rendered */
328
+ index: number;
329
+ }
330
+ /**
331
+ * Type of item in a {@link DisplayList}
332
+ *
333
+ * Must be passed as a child to {@link DisplayList}.
334
+ * Accepts props defined by {@link DisplayListItemProps}.
335
+ * Component must pass {@link DisplayBaseItemProps.style} to whatever it renders.
336
+ *
337
+ * @example Basic implementation
338
+ * ```
339
+ * const Row = ({ index, style }: { index: number, style: React.CSSProperties }) => (
340
+ * <div className="row" style={style}>
341
+ * { index }
342
+ * </div>
343
+ * );
344
+ * ```
345
+ */
346
+ type DisplayListItem = React$1.ComponentType<DisplayListItemProps>;
347
+ /**
348
+ * Props accepted by {@link DisplayList}
349
+ */
350
+ interface DisplayListProps extends DisplayBaseProps {
351
+ /** Component used as a template to render items in the list. Must implement {@link DisplayListItem} interface. */
352
+ children: DisplayListItem;
353
+ /** Number of items in the list */
354
+ itemCount: number;
355
+ /** Offset to start of displayed content */
356
+ offset: number;
357
+ /**
358
+ * Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each item in the list
359
+ *
360
+ * Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
361
+ * for common cases.
362
+ */
363
+ itemOffsetMapping: ItemOffsetMapping;
364
+ /**
365
+ * Function that defines the key to use for each item given item index and value of {@link DisplayBaseProps.itemData}.
366
+ * @defaultValue `(index, _data) => index`
367
+ */
368
+ itemKey?: (index: number, data: unknown) => React$1.Key;
369
+ /**
370
+ * Choice of 'vertical' or 'horizontal' layouts
371
+ * @defaultValue 'vertical'
372
+ */
373
+ layout?: ScrollLayout;
374
+ }
375
+ /**
376
+ * Displays a window onto the contents of a virtualized list starting from `offset`.
377
+ *
378
+ * Accepts props defined by {@link DisplayListProps}.
379
+ * You must pass a single instance of {@link DisplayListItem} as a child.
380
+ * @group Components
381
+ */
382
+ declare function DisplayList(props: DisplayListProps): react_jsx_runtime.JSX.Element;
383
+
384
+ /**
385
+ * Props accepted by {@link DisplayGridItem}
386
+ */
387
+ interface DisplayGridItemProps extends DisplayBaseItemProps {
388
+ /** Row index of item in the grid being rendered */
47
389
  rowIndex: number;
390
+ /** Column index of item in the grid being rendered */
48
391
  columnIndex: number;
49
392
  }
50
- type VirtualGridItem = React.ComponentType<VirtualGridItemProps>;
51
- interface VirtualGridProps extends VirtualBaseProps {
52
- children: VirtualGridItem;
393
+ /**
394
+ * Type of item in a {@link DisplayGrid}
395
+ *
396
+ * Must be passed as a child to {@link DisplayGrid}.
397
+ * Accepts props defined by {@link DisplayGridItemProps}.
398
+ * Component must pass {@link DisplayBaseItemProps.style} to whatever it renders.
399
+ *
400
+ * @example Basic implementation
401
+ * ```
402
+ * const Row = ({ index, style }: { index: number, style: React.CSSProperties }) => (
403
+ * <div className="row" style={style}>
404
+ * { index }
405
+ * </div>
406
+ * );
407
+ * ```
408
+ */
409
+ type DisplayGridItem = React$1.ComponentType<DisplayGridItemProps>;
410
+ /**
411
+ * Props accepted by {@link DisplayGrid}
412
+ */
413
+ interface DisplayGridProps extends DisplayBaseProps {
414
+ /** Component used as a template to render items in the list. Must implement {@link DisplayGridItem} interface. */
415
+ children: DisplayGridItem;
416
+ /** Number of rows in the grid */
53
417
  rowCount: number;
418
+ /**
419
+ * Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each row in the grid
420
+ *
421
+ * Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
422
+ * for common cases.
423
+ */
54
424
  rowOffsetMapping: ItemOffsetMapping;
425
+ /** Number of columns in the grid */
55
426
  columnCount: number;
427
+ /**
428
+ * Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each column in the grid
429
+ *
430
+ * Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
431
+ * for common cases.
432
+ */
56
433
  columnOffsetMapping: ItemOffsetMapping;
57
- itemKey?: (rowIndex: number, columnIndex: number, data: any) => any;
58
- onScroll?: (rowOffset: number, columnOffset: number, newRowScrollState: ScrollState, newColumnScrollState: ScrollState) => void;
59
- outerComponent?: VirtualOuterComponent;
60
- innerComponent?: VirtualInnerComponent;
434
+ /** Vertical offset to start of displayed content */
435
+ rowOffset: number;
436
+ /** Horizontal offset to start of displayed content */
437
+ columnOffset: number;
438
+ /**
439
+ * Function that defines the key to use for each item given row and column index and value of {@link DisplayBaseProps.itemData}.
440
+ * @defaultValue
441
+ * ```ts
442
+ * (rowIndex, columnIndex, _data) => `${rowIndex}:${columnIndex}`
443
+ * ```
444
+ */
445
+ itemKey?: (rowIndex: number, columnIndex: number, data: unknown) => React$1.Key;
61
446
  }
447
+ /**
448
+ * Displays a window onto the contents of a virtualized grid starting from `rowOffset`, `columnOffset`.
449
+ *
450
+ * Accepts props defined by {@link DisplayGridProps}.
451
+ * You must pass a single instance of {@link DisplayGridItem} as a child.
452
+ * @group Components
453
+ */
454
+ declare function DisplayGrid(props: DisplayGridProps): react_jsx_runtime.JSX.Element;
455
+
456
+ /**
457
+ * Custom ref handle returned by {@link VirtualGrid} that exposes imperative methods
458
+ *
459
+ * Use `React.useRef<VirtualGridProxy>(null)` to create a ref.
460
+ */
62
461
  interface VirtualGridProxy {
63
- scrollTo(rowOffset: number, columnOffset: number): void;
64
- scrollToItem(rowIndex: number, columnIndex: number): void;
462
+ /**
463
+ * Scrolls the list to the specified row and column in pixels
464
+ */
465
+ scrollTo(rowOffset?: number, columnOffset?: number): void;
466
+ /**
467
+ * Scrolls the list so that the specified item is visible
468
+ * @param rowIndex - Row of item to scroll to
469
+ * @param columnIndex - Column of item to scroll to
470
+ * @param option - Where to {@link ScrollToOption | position} the item within the viewport
471
+ */
472
+ scrollToItem(rowIndex?: number, columnIndex?: number, option?: ScrollToOption): void;
473
+ /** Exposes DOM clientWidth property */
474
+ get clientWidth(): number;
475
+ /** Exposes DOM clientHeight property */
476
+ get clientHeight(): number;
65
477
  }
66
- declare const VirtualGrid: React.ForwardRefExoticComponent<VirtualGridProps & React.RefAttributes<VirtualGridProxy>>;
478
+ /** Range to scroll to in one dimension specified as (offset,size). May be undefined if no need to scroll. */
479
+ type ScrollRange = [offset: number | undefined, size: number | undefined];
480
+ /**
481
+ * Returns the {@link ScrollRange} corresponding to a specified item.
482
+ *
483
+ * Used internally to implement {@link VirtualGridProxy.scrollToItem}. Can be used directly for
484
+ * advanced customization scenarios.
485
+ */
486
+ declare function getRangeToScroll(index: number | undefined, mapping: ItemOffsetMapping): ScrollRange;
487
+ /**
488
+ * Same logic as {@link VirtualGridProxy.scrollToItem} usable with your own {@link VirtualScroll}
489
+ *
490
+ * You're encouraged to put together your own combination of {@link VirtualScroll} and {@link DisplayGrid} for
491
+ * advanced customization scenarios. This function provides `ScrollToItem` functionality for use with your own {@link VirtualScroll}.
492
+ */
493
+ declare function virtualGridScrollToItem(scrollRef: React.RefObject<VirtualScrollProxy>, rowOffsetMapping: ItemOffsetMapping, columnOffsetMapping: ItemOffsetMapping, rowIndex?: number, columnIndex?: number, option?: ScrollToOption): void;
67
494
 
68
- type ScrollLayout = "horizontal" | "vertical";
69
- interface VirtualListItemProps extends VirtualBaseItemProps {
70
- index: number;
495
+ /**
496
+ * Props accepted by {@link VirtualGrid}
497
+ */
498
+ interface VirtualGridProps extends VirtualBaseProps {
499
+ /** Component used as a template to render items in the grid. Must implement {@link DisplayGridItem} interface. */
500
+ children: DisplayGridItem;
501
+ /** Number of rows in the grid */
502
+ rowCount: number;
503
+ /**
504
+ * Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each row in the grid
505
+ *
506
+ * Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
507
+ * for common cases.
508
+ */
509
+ rowOffsetMapping: ItemOffsetMapping;
510
+ /** Number of columns in the grid */
511
+ columnCount: number;
512
+ /**
513
+ * Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each column in the grid
514
+ *
515
+ * Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
516
+ * for common cases.
517
+ */
518
+ columnOffsetMapping: ItemOffsetMapping;
519
+ /**
520
+ * Function that defines the key to use for each item given row and column index and value of {@link VirtualBaseProps.itemData}.
521
+ * @defaultValue
522
+ * ```ts
523
+ * (rowIndex, columnIndex, _data) => `${rowIndex}:${columnIndex}`
524
+ * ```
525
+ */
526
+ itemKey?: (rowIndex: number, columnIndex: number, data: unknown) => React$1.Key;
527
+ /**
528
+ * Callback after a scroll event has been processed and state updated but before rendering
529
+ * @param rowOffset - Resulting overall row offset. Can be passed to {@link ItemOffsetMapping} to determine first row.
530
+ * @param columnOffset - Resulting overall column offset. Can be passed to {@link ItemOffsetMapping} to determine first column.
531
+ * @param newRowScrollState - New {@link ScrollState} for rows that will be used for rendering.
532
+ * @param newColumnScrollState - New {@link ScrollState} for columns that will be used for rendering.
533
+ */
534
+ onScroll?: (rowOffset: number, columnOffset: number, newRowScrollState: ScrollState, newColumnScrollState: ScrollState) => void;
535
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualGrid} outer container. */
536
+ outerRender?: VirtualContainerRender;
537
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link DisplayGrid} within {@link VirtualGrid} inner container. */
538
+ innerRender?: VirtualContainerRender;
539
+ }
540
+ /**
541
+ * Virtual Scrolling Grid
542
+ *
543
+ * Accepts props defined by {@link VirtualGridProps}.
544
+ * Refs are forwarded to {@link VirtualGridProxy}.
545
+ * You must pass a single instance of {@link DisplayGridItem} as a child.
546
+ * @group Components
547
+ */
548
+ declare const VirtualGrid: React$1.ForwardRefExoticComponent<VirtualGridProps & React$1.RefAttributes<VirtualGridProxy>>;
549
+
550
+ /**
551
+ * Custom ref handle returned by {@link VirtualList} that exposes imperative methods
552
+ *
553
+ * Use `React.useRef<VirtualListProxy>(null)` to create a ref.
554
+ */
555
+ interface VirtualListProxy {
556
+ /**
557
+ * Scrolls the list to the specified offset in pixels
558
+ * @param offset - Offset to scroll to
559
+ */
560
+ scrollTo(offset: number): void;
561
+ /**
562
+ * Scrolls the list so that the specified item is visible
563
+ * @param index - Index of item to scroll to
564
+ * @param option - Where to {@link ScrollToOption | position} the item within the viewport
565
+ */
566
+ scrollToItem(index: number, option?: ScrollToOption): void;
71
567
  }
72
- type VirtualListItem = React.ComponentType<VirtualListItemProps>;
568
+ /**
569
+ * Same logic as {@link VirtualListProxy.scrollToItem} usable with your own {@link VirtualScroll}
570
+ *
571
+ * You're encouraged to put together your own combination of {@link VirtualScroll} and {@link DisplayList} for
572
+ * advanced customization scenarios. This function provides `ScrollToItem` functionality for use with your own {@link VirtualScroll}.
573
+ */
574
+ declare function virtualListScrollToItem(scrollRef: React.RefObject<VirtualScrollProxy>, itemOffsetMapping: ItemOffsetMapping, isVertical: boolean, index: number, option?: ScrollToOption): void;
575
+
576
+ /**
577
+ * Props accepted by {@link VirtualList}
578
+ */
73
579
  interface VirtualListProps extends VirtualBaseProps {
74
- children: VirtualListItem;
580
+ /** Component used as a template to render items in the list. Must implement {@link DisplayListItem} interface. */
581
+ children: DisplayListItem;
582
+ /** Number of items in the list */
75
583
  itemCount: number;
584
+ /**
585
+ * Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each item in the list
586
+ *
587
+ * Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
588
+ * for common cases.
589
+ */
76
590
  itemOffsetMapping: ItemOffsetMapping;
77
- itemKey?: (index: number, data: any) => any;
591
+ /**
592
+ * Function that defines the key to use for each item given item index and value of {@link VirtualBaseProps.itemData}.
593
+ * @defaultValue `(index, _data) => index`
594
+ */
595
+ itemKey?: (index: number, data: unknown) => React$1.Key;
596
+ /**
597
+ * Choice of 'vertical' or 'horizontal' layouts
598
+ * @defaultValue 'vertical'
599
+ */
78
600
  layout?: ScrollLayout;
601
+ /**
602
+ * Callback after a scroll event has been processed and state updated but before rendering
603
+ * @param offset - Resulting overall offset. Can be passed to {@link ItemOffsetMapping} to determine top item.
604
+ * @param newScrollState - New {@link ScrollState} that will be used for rendering.
605
+ */
79
606
  onScroll?: (offset: number, newScrollState: ScrollState) => void;
80
- outerComponent?: VirtualOuterComponent;
81
- innerComponent?: VirtualInnerComponent;
607
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualList} outer container. */
608
+ outerRender?: VirtualContainerRender;
609
+ /** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link DisplayList} within {@link VirtualList} inner container. */
610
+ innerRender?: VirtualContainerRender;
82
611
  }
83
- interface VirtualListProxy {
84
- scrollTo(offset: number): void;
85
- scrollToItem(index: number): void;
86
- }
87
- declare const VirtualList: React.ForwardRefExoticComponent<VirtualListProps & React.RefAttributes<VirtualListProxy>>;
612
+ /**
613
+ * Virtual Scrolling List
614
+ *
615
+ * Accepts props defined by {@link VirtualListProps}.
616
+ * Refs are forwarded to {@link VirtualListProxy}.
617
+ * You must pass a single instance of {@link DisplayListItem} as a child.
618
+ * @group Components
619
+ */
620
+ declare const VirtualList: React$1.ForwardRefExoticComponent<VirtualListProps & React$1.RefAttributes<VirtualListProxy>>;
88
621
 
89
- declare class FixedSizeItemOffsetMapping implements ItemOffsetMapping {
90
- constructor(itemSize: number);
91
- itemSize(_itemIndex: number): number;
92
- itemOffset(itemIndex: number): number;
93
- offsetToItem(offset: number): [itemIndex: number, startOffset: number];
94
- fixedItemSize: number;
95
- }
96
- declare function useFixedSizeItemOffsetMapping(itemSize: number): FixedSizeItemOffsetMapping;
622
+ /**
623
+ * Returns an instance of {@link ItemOffsetMapping} suitable for use when all items have a fixed size.
624
+ *
625
+ * @param itemSize - Size to use for all items
626
+ */
627
+ declare function useFixedSizeItemOffsetMapping(itemSize: number): ItemOffsetMapping;
97
628
 
98
- declare class VariableSizeItemOffsetMapping implements ItemOffsetMapping {
99
- constructor(defaultItemSize: number, sizes: number[]);
100
- itemSize(itemIndex: number): number;
101
- itemOffset(itemIndex: number): number;
102
- offsetToItem(offset: number): [itemIndex: number, startOffset: number];
103
- defaultItemSize: number;
104
- sizes: number[];
105
- }
106
- declare function useVariableSizeItemOffsetMapping(defaultItemSize: number, sizes?: number[]): VariableSizeItemOffsetMapping;
629
+ /**
630
+ * Returns an instance of {@link ItemOffsetMapping} suitable for use when initial items have variable sizes.
631
+ *
632
+ * @param defaultItemSize - Size to use for all other items
633
+ * @param sizes - Array of sizes to use for the initial items, one size per item
634
+ */
635
+ declare function useVariableSizeItemOffsetMapping(defaultItemSize: number, sizes?: number[]): ItemOffsetMapping;
107
636
 
108
- export { type ScrollLayout, type ScrollState, VirtualGrid, type VirtualGridItemProps, type VirtualGridProps, type VirtualGridProxy, type VirtualInnerProps, VirtualList, type VirtualListItemProps, type VirtualListProps, type VirtualListProxy, type VirtualOuterProps, useFixedSizeItemOffsetMapping, useVariableSizeItemOffsetMapping };
637
+ export { AutoSizer, type AutoSizerProps, type AutoSizerRender, type AutoSizerRenderProps, type ComponentProps, type DisplayBaseItemProps, type DisplayBaseProps, DisplayGrid, type DisplayGridItem, type DisplayGridItemProps, type DisplayGridProps, DisplayList, type DisplayListItem, type DisplayListItemProps, type DisplayListProps, type ItemOffsetMapping, type ScrollDirection, type ScrollEvent, type ScrollLayout, type ScrollRange, type ScrollState, type ScrollToOption, type VirtualBaseProps, VirtualContainer, type VirtualContainerComponentProps, type VirtualContainerRender, type VirtualContainerRenderProps, type VirtualContentProps, type VirtualContentRender, VirtualGrid, type VirtualGridProps, type VirtualGridProxy, VirtualList, type VirtualListProps, type VirtualListProxy, VirtualScroll, type VirtualScrollProps, type VirtualScrollProxy, type VirtualScrollableProps, getOffsetToScrollRange, getRangeToScroll, useFixedSizeItemOffsetMapping, useVariableSizeItemOffsetMapping, virtualGridScrollToItem, virtualListScrollToItem };