Examples
Examples use:
Minimal usage
Cardwindow works by only rendering part of a large data set (just enough to fill the viewport). This helps address some common performance bottlenecks:
- It reduces the amount of work (and time) required to render the initial view and to process updates.
- It reduces the memory footprint by avoiding over-allocation of DOM nodes.
Required properties
CardWindow has three required properties. The Type parameter is T extends any[].
| Name | Type | |
|---|---|---|
cardRect | Rect | cardRect is used to calculate the rendering of CardWindow.children component. |
children | React.ComponentType<CardProps<T>> | children is a component that receives CardProps<T>. |
data | T | data is an array. CardWindow passes data to CardWindow.children component. |
Styling
root
root is passed to the root element of CardWindow. By default, root.style has these attributes:
- width:
100% - height:
100% - minWidth:
cardRect.width - overflow:
auto
You can't override only { overflow: 'auto' }.
container
container is passed to the scrollable large container element. You can't override width and height.
Card Positions
For card positions, you can use justifyContent, lastRowAlign and spacing.
Columns
Automatically Adjust Columns
The CardWindow uses ResizeObserver internally. Therefore, the column is automatically adjusted according to the element size specified by CSS.
Max columns
You can set the maximum number of columns.
The maxCols is a prop that goes well with justifyContent="stretch".
Overscanning
The overScanPx to render outside of the visible area. This property can be important for two reasons:
- Overscanning by one row or column allows the tab key to focus on the next (not yet visible) item.
- Overscanning slightly can reduce or prevent a flash of empty space when a user first starts scrolling.
Note that overscanning too much can negatively impact performance. By default, CardWindow overscans by 200 px.
Please check the Elements in the browser console. By default, this sample render 24 or less cards.
Scroll Event
Please scroll and check the logs in the browser console.
Infinite loading
You need to manage the pending status. Set the loadMore function only if you can call it.
The loading prop has 2 types, card and row.
type: card
type: row
Component height is required for row type loading.