@candidstartup/react-virtual-scroll 0.5.0 → 0.6.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.
- package/README.md +16 -4
- package/dist/index.d.ts +432 -141
- package/dist/index.js +348 -140
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,106 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React$1 from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
3
|
|
|
3
4
|
/**
|
|
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
|
|
5
82
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
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 */
|
|
8
90
|
data: unknown;
|
|
9
91
|
/**
|
|
10
92
|
* Is the owning component being actively scrolled? Used to change how the item is rendered depending on scroll state.
|
|
11
93
|
*
|
|
12
|
-
*
|
|
94
|
+
* Value passed through from {@link DisplayBaseProps.isScrolling}.
|
|
13
95
|
* */
|
|
14
96
|
isScrolling?: boolean;
|
|
15
97
|
/** Style that should be applied to each item rendered. Positions the item within the inner container. */
|
|
16
|
-
style: React.CSSProperties;
|
|
98
|
+
style: React$1.CSSProperties;
|
|
17
99
|
}
|
|
18
100
|
/**
|
|
19
|
-
* Common props for
|
|
101
|
+
* Common props for all components
|
|
20
102
|
*/
|
|
21
|
-
interface
|
|
103
|
+
interface ComponentProps {
|
|
22
104
|
/** The `className` applied to the outer container element. Use when styling the entire component. */
|
|
23
105
|
className?: string;
|
|
24
106
|
/** The `className` applied to the inner container element. Use for special cases when styling only the inner container and items. */
|
|
@@ -27,11 +109,39 @@ interface VirtualBaseProps {
|
|
|
27
109
|
height: number;
|
|
28
110
|
/** Component width */
|
|
29
111
|
width: number;
|
|
30
|
-
|
|
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 */
|
|
31
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 {
|
|
32
142
|
/**
|
|
33
143
|
* Determines whether the component should track whether it's being actively scrolled
|
|
34
|
-
* and pass
|
|
144
|
+
* and pass through when rendering its content.
|
|
35
145
|
*
|
|
36
146
|
* @defaultValue false
|
|
37
147
|
* */
|
|
@@ -44,7 +154,7 @@ interface VirtualBaseProps {
|
|
|
44
154
|
* */
|
|
45
155
|
maxCssSize?: number;
|
|
46
156
|
/**
|
|
47
|
-
* The minimum number of virtual pages to use when inner container would otherwise be more than {@link
|
|
157
|
+
* The minimum number of virtual pages to use when inner container would otherwise be more than {@link VirtualScrollableProps.maxCssSize} big.
|
|
48
158
|
* You should never normally need to change this.
|
|
49
159
|
*
|
|
50
160
|
* @defaultValue 100
|
|
@@ -52,59 +162,12 @@ interface VirtualBaseProps {
|
|
|
52
162
|
minNumPages?: number;
|
|
53
163
|
}
|
|
54
164
|
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
interface VirtualInnerProps {
|
|
58
|
-
/** The `className` to apply to the inner container div. Passed through from {@link VirtualBaseProps.innerClassName} */
|
|
59
|
-
className: string | undefined;
|
|
60
|
-
/** The visible child items rendered into the inner container div */
|
|
61
|
-
children: React.ReactNode;
|
|
62
|
-
/** Style to apply to the inner container div */
|
|
63
|
-
style: React.CSSProperties;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Render prop for inner container in a virtual scrolling component
|
|
67
|
-
*
|
|
68
|
-
* Can be passed to {@link VirtualList} or {@link VirtualGrid} to replace default
|
|
69
|
-
* implementation. Function must render a div and forward {@link VirtualInnerProps}
|
|
70
|
-
* and any `ref` to it.
|
|
71
|
-
*
|
|
72
|
-
* @example Minimal compliant implementation
|
|
73
|
-
* ```
|
|
74
|
-
* const innerRender: VirtualInnerRender = ({...rest}, ref) => (
|
|
75
|
-
* <div ref={ref} {...rest} />
|
|
76
|
-
* )
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
type VirtualInnerRender = (props: VirtualInnerProps, ref?: React.ForwardedRef<HTMLDivElement>) => JSX.Element;
|
|
80
|
-
/**
|
|
81
|
-
* Props that an implementation of {@link VirtualOuterRender} must accept.
|
|
165
|
+
* Common props for {@link VirtualList} and {@link VirtualGrid}
|
|
82
166
|
*/
|
|
83
|
-
interface
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
/** The child inner container rendered into the outer container div */
|
|
87
|
-
children: React.ReactNode;
|
|
88
|
-
/** Style to apply to the outer container div */
|
|
89
|
-
style: React.CSSProperties;
|
|
90
|
-
/** Scroll callback that should be applied to the outer container div */
|
|
91
|
-
onScroll: (event: ScrollEvent) => void;
|
|
167
|
+
interface VirtualBaseProps extends VirtualScrollableProps {
|
|
168
|
+
/** Passed as {@link DisplayBaseItemProps.data} to each child item */
|
|
169
|
+
itemData?: unknown;
|
|
92
170
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Render prop for outer container in a virtual scrolling component
|
|
95
|
-
*
|
|
96
|
-
* Can be passed to {@link VirtualList} or {@link VirtualGrid} to replace default
|
|
97
|
-
* implementation. Function must render a div and forward {@link VirtualOuterProps}
|
|
98
|
-
* and any `ref` to it.
|
|
99
|
-
*
|
|
100
|
-
* @example Minimal compliant implementation
|
|
101
|
-
* ```
|
|
102
|
-
* const outerRender: VirtualOuterRender = ({style, ...rest}, ref) => (
|
|
103
|
-
* <div ref={ref} {...rest} />
|
|
104
|
-
* )
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
type VirtualOuterRender = (props: VirtualOuterProps, ref?: React.ForwardedRef<HTMLDivElement>) => JSX.Element;
|
|
108
171
|
/**
|
|
109
172
|
* Interface that {@link VirtualList} and {@link VirtualGrid} use to determine size and
|
|
110
173
|
* positioning offset for items in a single dimension.
|
|
@@ -123,7 +186,18 @@ interface ItemOffsetMapping {
|
|
|
123
186
|
offsetToItem(offset: number): [itemIndex: number, startOffset: number];
|
|
124
187
|
}
|
|
125
188
|
/** Alias for type of event that React passes to a `div` element's `OnScroll` handler. */
|
|
126
|
-
type ScrollEvent = React.SyntheticEvent<HTMLDivElement>;
|
|
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";
|
|
127
201
|
|
|
128
202
|
/** Direction of scrolling */
|
|
129
203
|
type ScrollDirection = "forward" | "backward";
|
|
@@ -142,37 +216,207 @@ interface ScrollState {
|
|
|
142
216
|
}
|
|
143
217
|
|
|
144
218
|
/**
|
|
145
|
-
*
|
|
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
|
+
/** Current scroll position vertical offset */
|
|
265
|
+
verticalOffset: number;
|
|
266
|
+
/** Current scroll position horizontal offset */
|
|
267
|
+
horizontalOffset: number;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Render prop for content container in {@link VirtualScroll}
|
|
271
|
+
*
|
|
272
|
+
* Pass to {@link VirtualScroll} to render content into the viewport
|
|
273
|
+
* implementation. Function must render a div and forward {@link VirtualContentProps}
|
|
274
|
+
* and any `ref` to it.
|
|
275
|
+
*
|
|
276
|
+
* @example Minimal compliant implementation
|
|
277
|
+
* ```
|
|
278
|
+
* const contentRender: VirtualContentRender = ({isScrolling, ...rest}, ref) => (
|
|
279
|
+
* <div ref={ref} {...rest} />
|
|
280
|
+
* )
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
type VirtualContentRender = (props: VirtualContentProps, ref?: React$1.ForwardedRef<HTMLDivElement>) => JSX.Element;
|
|
284
|
+
/**
|
|
285
|
+
* Props accepted by {@link VirtualScroll}
|
|
286
|
+
*/
|
|
287
|
+
interface VirtualScrollProps extends VirtualScrollableProps {
|
|
288
|
+
/** Function implementing {@link VirtualContentRender} that renders the content that needs to respond to scrolling */
|
|
289
|
+
children: VirtualContentRender;
|
|
290
|
+
/**
|
|
291
|
+
* Height of area to scroll over
|
|
292
|
+
*
|
|
293
|
+
* @defaultValue 0
|
|
294
|
+
*/
|
|
295
|
+
scrollHeight?: number;
|
|
296
|
+
/**
|
|
297
|
+
* Width of area to scroll over
|
|
298
|
+
*
|
|
299
|
+
* @defaultValue 0
|
|
300
|
+
*/
|
|
301
|
+
scrollWidth?: number;
|
|
302
|
+
/**
|
|
303
|
+
* Callback after a scroll event has been processed and state updated but before rendering
|
|
304
|
+
* @param verticalOffset - Resulting overall vertical offset.
|
|
305
|
+
* @param horizontalOffset - Resulting overall horizontal offset.
|
|
306
|
+
* @param newVerticalScrollState - New vertical {@link ScrollState} that will be used for rendering.
|
|
307
|
+
* @param newHorizontalScrollState - New horizontal {@link ScrollState} that will be used for rendering.
|
|
308
|
+
*/
|
|
309
|
+
onScroll?: (verticalOffset: number, horizontalOffset: number, newVerticalScrollState: ScrollState, newHorizontalScrollState: ScrollState) => void;
|
|
310
|
+
/** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualScroll} outer container. */
|
|
311
|
+
outerRender?: VirtualContainerRender;
|
|
312
|
+
/** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualScroll} inner container. */
|
|
313
|
+
innerRender?: VirtualContainerRender;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Customizable Virtual Scrolling Component
|
|
317
|
+
*
|
|
318
|
+
* Allows user to scroll over a virtual area `scrollHeight` x `scrollWidth` pixels.
|
|
319
|
+
* Use `onScroll` to track scroll state and `innerRender` to render scroll state specific content into the viewport
|
|
320
|
+
*
|
|
321
|
+
* Accepts props defined by {@link VirtualScrollProps}.
|
|
322
|
+
* Refs are forwarded to {@link VirtualScrollProxy}.
|
|
323
|
+
* @group Components
|
|
324
|
+
*/
|
|
325
|
+
declare const VirtualScroll: React$1.ForwardRefExoticComponent<VirtualScrollProps & React$1.RefAttributes<VirtualScrollProxy>>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Props accepted by {@link DisplayListItem}
|
|
329
|
+
*/
|
|
330
|
+
interface DisplayListItemProps extends DisplayBaseItemProps {
|
|
331
|
+
/** Index of item in the list being rendered */
|
|
332
|
+
index: number;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Type of item in a {@link DisplayList}
|
|
336
|
+
*
|
|
337
|
+
* Must be passed as a child to {@link DisplayList}.
|
|
338
|
+
* Accepts props defined by {@link DisplayListItemProps}.
|
|
339
|
+
* Component must pass {@link DisplayBaseItemProps.style} to whatever it renders.
|
|
340
|
+
*
|
|
341
|
+
* @example Basic implementation
|
|
342
|
+
* ```
|
|
343
|
+
* const Row = ({ index, style }: { index: number, style: React.CSSProperties }) => (
|
|
344
|
+
* <div className="row" style={style}>
|
|
345
|
+
* { index }
|
|
346
|
+
* </div>
|
|
347
|
+
* );
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
type DisplayListItem = React$1.ComponentType<DisplayListItemProps>;
|
|
351
|
+
/**
|
|
352
|
+
* Props accepted by {@link DisplayList}
|
|
353
|
+
*/
|
|
354
|
+
interface DisplayListProps extends DisplayBaseProps {
|
|
355
|
+
/** Component used as a template to render items in the list. Must implement {@link DisplayListItem} interface. */
|
|
356
|
+
children: DisplayListItem;
|
|
357
|
+
/** Number of items in the list */
|
|
358
|
+
itemCount: number;
|
|
359
|
+
/** Offset to start of displayed content */
|
|
360
|
+
offset: number;
|
|
361
|
+
/**
|
|
362
|
+
* Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each item in the list
|
|
363
|
+
*
|
|
364
|
+
* Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
|
|
365
|
+
* for common cases.
|
|
366
|
+
*/
|
|
367
|
+
itemOffsetMapping: ItemOffsetMapping;
|
|
368
|
+
/**
|
|
369
|
+
* Function that defines the key to use for each item given item index and value of {@link DisplayBaseProps.itemData}.
|
|
370
|
+
* @defaultValue `(index, _data) => index`
|
|
371
|
+
*/
|
|
372
|
+
itemKey?: (index: number, data: unknown) => React$1.Key;
|
|
373
|
+
/**
|
|
374
|
+
* Choice of 'vertical' or 'horizontal' layouts
|
|
375
|
+
* @defaultValue 'vertical'
|
|
376
|
+
*/
|
|
377
|
+
layout?: ScrollLayout;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Displays a window onto the contents of a virtualized list starting from `offset`.
|
|
381
|
+
*
|
|
382
|
+
* Accepts props defined by {@link DisplayListProps}.
|
|
383
|
+
* You must pass a single instance of {@link DisplayListItem} as a child.
|
|
384
|
+
* @group Components
|
|
385
|
+
*/
|
|
386
|
+
declare function DisplayList(props: DisplayListProps): react_jsx_runtime.JSX.Element;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Props accepted by {@link DisplayGridItem}
|
|
146
390
|
*/
|
|
147
|
-
interface
|
|
391
|
+
interface DisplayGridItemProps extends DisplayBaseItemProps {
|
|
148
392
|
/** Row index of item in the grid being rendered */
|
|
149
393
|
rowIndex: number;
|
|
150
394
|
/** Column index of item in the grid being rendered */
|
|
151
395
|
columnIndex: number;
|
|
152
396
|
}
|
|
153
397
|
/**
|
|
154
|
-
* Type of item in a {@link
|
|
398
|
+
* Type of item in a {@link DisplayGrid}
|
|
155
399
|
*
|
|
156
|
-
* Must be passed as a child to {@link
|
|
157
|
-
* Accepts props defined by {@link
|
|
158
|
-
* Component must pass {@link
|
|
400
|
+
* Must be passed as a child to {@link DisplayGrid}.
|
|
401
|
+
* Accepts props defined by {@link DisplayGridItemProps}.
|
|
402
|
+
* Component must pass {@link DisplayBaseItemProps.style} to whatever it renders.
|
|
159
403
|
*
|
|
160
404
|
* @example Basic implementation
|
|
161
405
|
* ```
|
|
162
|
-
* const
|
|
163
|
-
* <div className="
|
|
164
|
-
* {
|
|
406
|
+
* const Row = ({ index, style }: { index: number, style: React.CSSProperties }) => (
|
|
407
|
+
* <div className="row" style={style}>
|
|
408
|
+
* { index }
|
|
165
409
|
* </div>
|
|
166
410
|
* );
|
|
167
411
|
* ```
|
|
168
412
|
*/
|
|
169
|
-
type
|
|
413
|
+
type DisplayGridItem = React$1.ComponentType<DisplayGridItemProps>;
|
|
170
414
|
/**
|
|
171
|
-
* Props accepted by {@link
|
|
415
|
+
* Props accepted by {@link DisplayGrid}
|
|
172
416
|
*/
|
|
173
|
-
interface
|
|
174
|
-
/** Component used as a template to render items in the
|
|
175
|
-
children:
|
|
417
|
+
interface DisplayGridProps extends DisplayBaseProps {
|
|
418
|
+
/** Component used as a template to render items in the list. Must implement {@link DisplayGridItem} interface. */
|
|
419
|
+
children: DisplayGridItem;
|
|
176
420
|
/** Number of rows in the grid */
|
|
177
421
|
rowCount: number;
|
|
178
422
|
/**
|
|
@@ -191,27 +435,28 @@ interface VirtualGridProps extends VirtualBaseProps {
|
|
|
191
435
|
* for common cases.
|
|
192
436
|
*/
|
|
193
437
|
columnOffsetMapping: ItemOffsetMapping;
|
|
438
|
+
/** Vertical offset to start of displayed content */
|
|
439
|
+
rowOffset: number;
|
|
440
|
+
/** Horizontal offset to start of displayed content */
|
|
441
|
+
columnOffset: number;
|
|
194
442
|
/**
|
|
195
|
-
* Function that defines the key to use for each item given row and column index and value of {@link
|
|
443
|
+
* Function that defines the key to use for each item given row and column index and value of {@link DisplayBaseProps.itemData}.
|
|
196
444
|
* @defaultValue
|
|
197
445
|
* ```ts
|
|
198
446
|
* (rowIndex, columnIndex, _data) => `${rowIndex}:${columnIndex}`
|
|
199
447
|
* ```
|
|
200
448
|
*/
|
|
201
|
-
itemKey?: (rowIndex: number, columnIndex: number, data: unknown) => React.Key;
|
|
202
|
-
/**
|
|
203
|
-
* Callback after a scroll event has been processed and state updated but before rendering
|
|
204
|
-
* @param rowOffset - Resulting overall row offset. Can be passed to {@link ItemOffsetMapping} to determine first row.
|
|
205
|
-
* @param columnOffset - Resulting overall column offset. Can be passed to {@link ItemOffsetMapping} to determine first column.
|
|
206
|
-
* @param newRowScrollState - New {@link ScrollState} for rows that will be used for rendering.
|
|
207
|
-
* @param newColumnScrollState - New {@link ScrollState} for columns that will be used for rendering.
|
|
208
|
-
*/
|
|
209
|
-
onScroll?: (rowOffset: number, columnOffset: number, newRowScrollState: ScrollState, newColumnScrollState: ScrollState) => void;
|
|
210
|
-
/** Render prop implementing {@link VirtualOuterRender}. Used to customize {@link VirtualGrid}. */
|
|
211
|
-
outerRender?: VirtualOuterRender;
|
|
212
|
-
/** Render prop implementing {@link VirtualInnerRender}. Used to customize {@link VirtualGrid}. */
|
|
213
|
-
innerRender?: VirtualInnerRender;
|
|
449
|
+
itemKey?: (rowIndex: number, columnIndex: number, data: unknown) => React$1.Key;
|
|
214
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Displays a window onto the contents of a virtualized grid starting from `rowOffset`, `columnOffset`.
|
|
453
|
+
*
|
|
454
|
+
* Accepts props defined by {@link DisplayGridProps}.
|
|
455
|
+
* You must pass a single instance of {@link DisplayGridItem} as a child.
|
|
456
|
+
* @group Components
|
|
457
|
+
*/
|
|
458
|
+
declare function DisplayGrid(props: DisplayGridProps): react_jsx_runtime.JSX.Element;
|
|
459
|
+
|
|
215
460
|
/**
|
|
216
461
|
* Custom ref handle returned by {@link VirtualGrid} that exposes imperative methods
|
|
217
462
|
*
|
|
@@ -226,55 +471,118 @@ interface VirtualGridProxy {
|
|
|
226
471
|
* Scrolls the list so that the specified item is visible
|
|
227
472
|
* @param rowIndex - Row of item to scroll to
|
|
228
473
|
* @param columnIndex - Column of item to scroll to
|
|
474
|
+
* @param option - Where to {@link ScrollToOption | position} the item within the viewport
|
|
229
475
|
*/
|
|
230
|
-
scrollToItem(rowIndex?: number, columnIndex?: number): void;
|
|
476
|
+
scrollToItem(rowIndex?: number, columnIndex?: number, option?: ScrollToOption): void;
|
|
231
477
|
/** Exposes DOM clientWidth property */
|
|
232
478
|
get clientWidth(): number;
|
|
233
479
|
/** Exposes DOM clientHeight property */
|
|
234
480
|
get clientHeight(): number;
|
|
235
481
|
}
|
|
482
|
+
/** Range to scroll to in one dimension specified as (offset,size). May be undefined if no need to scroll. */
|
|
483
|
+
type ScrollRange = [offset: number | undefined, size: number | undefined];
|
|
484
|
+
/**
|
|
485
|
+
* Returns the {@link ScrollRange} corresponding to a specified item.
|
|
486
|
+
*
|
|
487
|
+
* Used internally to implement {@link VirtualGridProxy.scrollToItem}. Can be used directly for
|
|
488
|
+
* advanced customization scenarios.
|
|
489
|
+
*/
|
|
490
|
+
declare function getRangeToScroll(index: number | undefined, mapping: ItemOffsetMapping): ScrollRange;
|
|
491
|
+
/**
|
|
492
|
+
* Same logic as {@link VirtualGridProxy.scrollToItem} usable with your own {@link VirtualScroll}
|
|
493
|
+
*
|
|
494
|
+
* You're encouraged to put together your own combination of {@link VirtualScroll} and {@link DisplayGrid} for
|
|
495
|
+
* advanced customization scenarios. This function provides `ScrollToItem` functionality for use with your own {@link VirtualScroll}.
|
|
496
|
+
*/
|
|
497
|
+
declare function virtualGridScrollToItem(scrollRef: React.RefObject<VirtualScrollProxy>, rowOffsetMapping: ItemOffsetMapping, columnOffsetMapping: ItemOffsetMapping, rowIndex?: number, columnIndex?: number, option?: ScrollToOption): void;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Props accepted by {@link VirtualGrid}
|
|
501
|
+
*/
|
|
502
|
+
interface VirtualGridProps extends VirtualBaseProps {
|
|
503
|
+
/** Component used as a template to render items in the grid. Must implement {@link DisplayGridItem} interface. */
|
|
504
|
+
children: DisplayGridItem;
|
|
505
|
+
/** Number of rows in the grid */
|
|
506
|
+
rowCount: number;
|
|
507
|
+
/**
|
|
508
|
+
* Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each row in the grid
|
|
509
|
+
*
|
|
510
|
+
* Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
|
|
511
|
+
* for common cases.
|
|
512
|
+
*/
|
|
513
|
+
rowOffsetMapping: ItemOffsetMapping;
|
|
514
|
+
/** Number of columns in the grid */
|
|
515
|
+
columnCount: number;
|
|
516
|
+
/**
|
|
517
|
+
* Implementation of {@link ItemOffsetMapping} interface that defines size and offset to each column in the grid
|
|
518
|
+
*
|
|
519
|
+
* Use {@link useFixedSizeItemOffsetMapping} or {@link useVariableSizeItemOffsetMapping} to create implementations
|
|
520
|
+
* for common cases.
|
|
521
|
+
*/
|
|
522
|
+
columnOffsetMapping: ItemOffsetMapping;
|
|
523
|
+
/**
|
|
524
|
+
* Function that defines the key to use for each item given row and column index and value of {@link VirtualBaseProps.itemData}.
|
|
525
|
+
* @defaultValue
|
|
526
|
+
* ```ts
|
|
527
|
+
* (rowIndex, columnIndex, _data) => `${rowIndex}:${columnIndex}`
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
itemKey?: (rowIndex: number, columnIndex: number, data: unknown) => React$1.Key;
|
|
531
|
+
/**
|
|
532
|
+
* Callback after a scroll event has been processed and state updated but before rendering
|
|
533
|
+
* @param rowOffset - Resulting overall row offset. Can be passed to {@link ItemOffsetMapping} to determine first row.
|
|
534
|
+
* @param columnOffset - Resulting overall column offset. Can be passed to {@link ItemOffsetMapping} to determine first column.
|
|
535
|
+
* @param newRowScrollState - New {@link ScrollState} for rows that will be used for rendering.
|
|
536
|
+
* @param newColumnScrollState - New {@link ScrollState} for columns that will be used for rendering.
|
|
537
|
+
*/
|
|
538
|
+
onScroll?: (rowOffset: number, columnOffset: number, newRowScrollState: ScrollState, newColumnScrollState: ScrollState) => void;
|
|
539
|
+
/** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualGrid} outer container. */
|
|
540
|
+
outerRender?: VirtualContainerRender;
|
|
541
|
+
/** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link DisplayGrid} within {@link VirtualGrid} inner container. */
|
|
542
|
+
innerRender?: VirtualContainerRender;
|
|
543
|
+
}
|
|
236
544
|
/**
|
|
237
545
|
* Virtual Scrolling Grid
|
|
238
546
|
*
|
|
239
547
|
* Accepts props defined by {@link VirtualGridProps}.
|
|
240
548
|
* Refs are forwarded to {@link VirtualGridProxy}.
|
|
241
|
-
* You must pass a single instance of {@link
|
|
549
|
+
* You must pass a single instance of {@link DisplayGridItem} as a child.
|
|
242
550
|
* @group Components
|
|
243
551
|
*/
|
|
244
|
-
declare const VirtualGrid: React.ForwardRefExoticComponent<VirtualGridProps & React.RefAttributes<VirtualGridProxy>>;
|
|
552
|
+
declare const VirtualGrid: React$1.ForwardRefExoticComponent<VirtualGridProps & React$1.RefAttributes<VirtualGridProxy>>;
|
|
245
553
|
|
|
246
|
-
/** Specifies the direction over which the list should implement virtual scrolling */
|
|
247
|
-
type ScrollLayout = "horizontal" | "vertical";
|
|
248
554
|
/**
|
|
249
|
-
*
|
|
555
|
+
* Custom ref handle returned by {@link VirtualList} that exposes imperative methods
|
|
556
|
+
*
|
|
557
|
+
* Use `React.useRef<VirtualListProxy>(null)` to create a ref.
|
|
250
558
|
*/
|
|
251
|
-
interface
|
|
252
|
-
/**
|
|
253
|
-
|
|
559
|
+
interface VirtualListProxy {
|
|
560
|
+
/**
|
|
561
|
+
* Scrolls the list to the specified offset in pixels
|
|
562
|
+
* @param offset - Offset to scroll to
|
|
563
|
+
*/
|
|
564
|
+
scrollTo(offset: number): void;
|
|
565
|
+
/**
|
|
566
|
+
* Scrolls the list so that the specified item is visible
|
|
567
|
+
* @param index - Index of item to scroll to
|
|
568
|
+
* @param option - Where to {@link ScrollToOption | position} the item within the viewport
|
|
569
|
+
*/
|
|
570
|
+
scrollToItem(index: number, option?: ScrollToOption): void;
|
|
254
571
|
}
|
|
255
572
|
/**
|
|
256
|
-
*
|
|
573
|
+
* Same logic as {@link VirtualListProxy.scrollToItem} usable with your own {@link VirtualScroll}
|
|
257
574
|
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* Component must pass {@link VirtualBaseItemProps.style} to whatever it renders.
|
|
261
|
-
*
|
|
262
|
-
* @example Basic implementation
|
|
263
|
-
* ```
|
|
264
|
-
* const Row = ({ index, style }: { index: number, style: React.CSSProperties }) => (
|
|
265
|
-
* <div className="row" style={style}>
|
|
266
|
-
* { index }
|
|
267
|
-
* </div>
|
|
268
|
-
* );
|
|
269
|
-
* ```
|
|
575
|
+
* You're encouraged to put together your own combination of {@link VirtualScroll} and {@link DisplayList} for
|
|
576
|
+
* advanced customization scenarios. This function provides `ScrollToItem` functionality for use with your own {@link VirtualScroll}.
|
|
270
577
|
*/
|
|
271
|
-
|
|
578
|
+
declare function virtualListScrollToItem(scrollRef: React.RefObject<VirtualScrollProxy>, itemOffsetMapping: ItemOffsetMapping, isVertical: boolean, index: number, option?: ScrollToOption): void;
|
|
579
|
+
|
|
272
580
|
/**
|
|
273
581
|
* Props accepted by {@link VirtualList}
|
|
274
582
|
*/
|
|
275
583
|
interface VirtualListProps extends VirtualBaseProps {
|
|
276
|
-
/** Component used as a template to render items in the list. Must implement {@link
|
|
277
|
-
children:
|
|
584
|
+
/** Component used as a template to render items in the list. Must implement {@link DisplayListItem} interface. */
|
|
585
|
+
children: DisplayListItem;
|
|
278
586
|
/** Number of items in the list */
|
|
279
587
|
itemCount: number;
|
|
280
588
|
/**
|
|
@@ -288,7 +596,7 @@ interface VirtualListProps extends VirtualBaseProps {
|
|
|
288
596
|
* Function that defines the key to use for each item given item index and value of {@link VirtualBaseProps.itemData}.
|
|
289
597
|
* @defaultValue `(index, _data) => index`
|
|
290
598
|
*/
|
|
291
|
-
itemKey?: (index: number, data: unknown) => React.Key;
|
|
599
|
+
itemKey?: (index: number, data: unknown) => React$1.Key;
|
|
292
600
|
/**
|
|
293
601
|
* Choice of 'vertical' or 'horizontal' layouts
|
|
294
602
|
* @defaultValue 'vertical'
|
|
@@ -300,37 +608,20 @@ interface VirtualListProps extends VirtualBaseProps {
|
|
|
300
608
|
* @param newScrollState - New {@link ScrollState} that will be used for rendering.
|
|
301
609
|
*/
|
|
302
610
|
onScroll?: (offset: number, newScrollState: ScrollState) => void;
|
|
303
|
-
/** Render prop implementing {@link
|
|
304
|
-
outerRender?:
|
|
305
|
-
/** Render prop implementing {@link
|
|
306
|
-
innerRender?:
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Custom ref handle returned by {@link VirtualList} that exposes imperative methods
|
|
310
|
-
*
|
|
311
|
-
* Use `React.useRef<VirtualListProxy>(null)` to create a ref.
|
|
312
|
-
*/
|
|
313
|
-
interface VirtualListProxy {
|
|
314
|
-
/**
|
|
315
|
-
* Scrolls the list to the specified offset in pixels
|
|
316
|
-
* @param offset - Offset to scroll to
|
|
317
|
-
*/
|
|
318
|
-
scrollTo(offset: number): void;
|
|
319
|
-
/**
|
|
320
|
-
* Scrolls the list so that the specified item is visible
|
|
321
|
-
* @param index - Index of item to scroll to
|
|
322
|
-
*/
|
|
323
|
-
scrollToItem(index: number): void;
|
|
611
|
+
/** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link VirtualList} outer container. */
|
|
612
|
+
outerRender?: VirtualContainerRender;
|
|
613
|
+
/** Render prop implementing {@link VirtualContainerRender}. Used to customize {@link DisplayList} within {@link VirtualList} inner container. */
|
|
614
|
+
innerRender?: VirtualContainerRender;
|
|
324
615
|
}
|
|
325
616
|
/**
|
|
326
617
|
* Virtual Scrolling List
|
|
327
618
|
*
|
|
328
619
|
* Accepts props defined by {@link VirtualListProps}.
|
|
329
620
|
* Refs are forwarded to {@link VirtualListProxy}.
|
|
330
|
-
* You must pass a single instance of {@link
|
|
621
|
+
* You must pass a single instance of {@link DisplayListItem} as a child.
|
|
331
622
|
* @group Components
|
|
332
623
|
*/
|
|
333
|
-
declare const VirtualList: React.ForwardRefExoticComponent<VirtualListProps & React.RefAttributes<VirtualListProxy>>;
|
|
624
|
+
declare const VirtualList: React$1.ForwardRefExoticComponent<VirtualListProps & React$1.RefAttributes<VirtualListProxy>>;
|
|
334
625
|
|
|
335
626
|
/**
|
|
336
627
|
* Returns an instance of {@link ItemOffsetMapping} suitable for use when all items have a fixed size.
|
|
@@ -347,4 +638,4 @@ declare function useFixedSizeItemOffsetMapping(itemSize: number): ItemOffsetMapp
|
|
|
347
638
|
*/
|
|
348
639
|
declare function useVariableSizeItemOffsetMapping(defaultItemSize: number, sizes?: number[]): ItemOffsetMapping;
|
|
349
640
|
|
|
350
|
-
export { type ItemOffsetMapping, type ScrollDirection, type ScrollEvent, type ScrollLayout, type ScrollState, type
|
|
641
|
+
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 };
|