Skip to main content

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.
Live Editor
Result
Loading...

Required properties

CardWindow has three required properties. The Type parameter is T extends any[].

NameType
cardRectRectcardRect is used to calculate the rendering of CardWindow.children component.
childrenReact.ComponentType<CardProps<T>>children is a component that receives CardProps<T>.
dataTdata 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' }.

Live Editor
Result
Loading...

container

container is passed to the scrollable large container element. You can't override width and height.

Live Editor
Result
Loading...

Card Positions

For card positions, you can use justifyContent, lastRowAlign and spacing.

Live Editor
Result
Loading...

Columns

Automatically Adjust Columns

The CardWindow uses ResizeObserver internally. Therefore, the column is automatically adjusted according to the element size specified by CSS.

Live Editor
Result
Loading...

Max columns

You can set the maximum number of columns. The maxCols is a prop that goes well with justifyContent="stretch".

Live Editor
Result
Loading...

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.

Live Editor
Result
Loading...

Scroll Event

Please scroll and check the logs in the browser console.

Live Editor
Result
Loading...

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

Live Editor
Result
Loading...

type: row

Component height is required for row type loading.

Live Editor
Result
Loading...