import * as React from "react"; import * as ReactDOM from "react-dom"; import { Collection, SortDirection, Grid, ArrowKeyStepper, AutoSizer, CellMeasurer, ColumnSizer, InfiniteLoader, ScrollSync, WindowScroller, WindowScrollerRenderCallBackParams, List, Column, Table, } from "react-virtualized"; /* * Collection */ function CollectionTest() { const list = [ { name: "Brian Vaughn", x: 13, y: 34, width: 123, size: 234, height: 123 } ]; // Render your grid ReactDOM.render( list[index].name} cellSizeAndPositionGetter={({ index }) => { const datum = list[index]; return { height: datum.height, width: datum.width, x: datum.x, y: datum.y }; }} />, document.getElementById("example") ); } function GridTest() { // Grid data as an array of arrays const list = [ ['Brian Vaughn', 'Software Engineer', 'San Jose', 'CA', 95125 /* ... */] // And so on... ]; // Render your grid ReactDOM.render( list[rowIndex][columnIndex]} />, document.getElementById('example') ); } function ListTest() { // List data const list = [ { name: 'Brian Vaughn', occupation: 'Software Engineer', location: 'San Jose, CA, 95125' /* ... */ } // And so on... ]; // Render your List ReactDOM.render( list[index]} />, document.getElementById('example') ); } function TableTest() { const list = [ { name: 'Brian Vaughn', description: 'Software engineer' } // And so on... ]; ReactDOM.render( list[index]} >
, document.getElementById('example') ); } function ArrowKeyStepperTest() { const columnCount = 12; const rowCount = 3; ReactDOM.render( {({ onSectionRendered, scrollToColumn, scrollToRow }) => ( null} columnCount={columnCount} onSectionRendered={onSectionRendered} rowCount={rowCount} scrollToColumn={scrollToColumn} scrollToRow={scrollToRow} /> )} , document.getElementById('example') ); } function AutoSizerTest() { // List data as an array of strings const list = [ 'Brian Vaughn' // And so on... ]; const _rowRenderer = ({ index, key, style }) => { const row = list[index]; return (
{row}
) } // Render your list ReactDOM.render( {({ width, height }) => ( { const row = list[index]; return (
{row}
) }} width={width} /> )}
, document.getElementById('example') ); } function CellMeasurerTest() { const columnCount = 12; const rowCount = 3; const cellRenderer = ({ columnIndex, rowIndex }) => `${rowIndex}, ${columnIndex}`; const fixedRowHeight = 42; const height = 12; const width = 12; ReactDOM.render( {({ getColumnWidth }) => ( )} , document.getElementById('example') ); } function ColumnSizerTest() { ReactDOM.render( {({ adjustedWidth, getColumnWidth, registerChild }) => ( "test"} rowHeight={50} rowCount={12} width={adjustedWidth} /> )} , document.getElementById('example') ); } function InfiniteLoaderTest() { const list: string[] = []; function isRowLoaded({ index }) { return !!list[index]; } function loadMoreRows({ startIndex, stopIndex }: { startIndex: number, stopIndex: number }) { return new Promise(resolve => resolve(list.push('test'))); } function rowRenderer({ index, key, style }) { const content = list[index]; return (
{content}
) } // Render your list ReactDOM.render( {({ onRowsRendered, registerChild }) => ( {({ width }) => ( )} )} , document.getElementById('example') ); } function ScrollSyncTest() { function hexToRgb(hex) { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null } const LEFT_COLOR_FROM = hexToRgb('#471061') const LEFT_COLOR_TO = hexToRgb('#BC3959') const TOP_COLOR_FROM = hexToRgb('#000000') const TOP_COLOR_TO = hexToRgb('#333333') const columnWidth = 20; const rowHeight = 10; const overscanColumnCount = 10; const overscanRowCount = 10; const height = 10; const rowCount = 100; const columnCount = 100; function mixColors(color1, color2, amount) { const weight1 = amount const weight2 = 1 - amount const r = Math.round(weight1 * color1.r + weight2 * color2.r) const g = Math.round(weight1 * color1.g + weight2 * color2.g) const b = Math.round(weight1 * color1.b + weight2 * color2.b) return { r, g, b } }; function renderLeftHeaderCell({ columnIndex, key, rowIndex, style }) { return (
{`C${columnIndex}`}
) }; function renderLeftSideCell({ columnIndex, key, rowIndex, style }) { const rowClass = rowIndex % 2 === 0 ? columnIndex % 2 === 0 ? 'styles.evenRow' : 'styles.oddRow' : columnIndex % 2 !== 0 ? 'styles.evenRow' : 'styles.oddRow' const classNames = [rowClass, 'styles.cell'].join(' ') return (
{`R${rowIndex}, C${columnIndex}`}
) }; function renderHeaderCell({ columnIndex, key, rowIndex, style }) { if (columnIndex < 1) { return } return renderLeftHeaderCell({ columnIndex, key, rowIndex, style }) }; function renderBodyCell({ columnIndex, key, rowIndex, style }) { if (columnIndex < 1) { return } return renderLeftSideCell({ columnIndex, key, rowIndex, style }) } return ( {({ clientHeight, clientWidth, onScroll, scrollHeight, scrollLeft, scrollTop, scrollWidth }) => { const x = scrollLeft / (scrollWidth - clientWidth) const y = scrollTop / (scrollHeight - clientHeight) const leftBackgroundColor = mixColors(LEFT_COLOR_FROM, LEFT_COLOR_TO, y) const leftColor = '#ffffff' const topBackgroundColor = mixColors(TOP_COLOR_FROM, TOP_COLOR_TO, x) const topColor = '#ffffff' const middleBackgroundColor = mixColors(leftBackgroundColor, topBackgroundColor, 0.5) const middleColor = '#ffffff' return (
{({ width }) => (
)}
) }}
); } function WindowScrollerTest() { const onScroll = function ({scrollTop}: { scrollTop: number }) { }; const onResize = function ({height}: { height: number }) { }; const list = [ { name: 'Brian Vaughn', description: 'Software engineer' } // And so on... ]; ReactDOM.render( {({ height, isScrolling, scrollTop }) => ( {({ width }) => ( list[index].name} scrollTop={scrollTop} width={width} /> )} )} , document.getElementById('example') ); // test that onScroll & onResize are optional ReactDOM.render( , document.getElementById('example') ); }