diff --git a/react-virtualized/react-virtualized-tests.tsx b/react-virtualized/react-virtualized-tests.tsx new file mode 100644 index 0000000000..d3ee9c3590 --- /dev/null +++ b/react-virtualized/react-virtualized-tests.tsx @@ -0,0 +1,309 @@ +/// +/// +/// + +import * as React from "react"; +import * as ReactDOM from "react-dom"; + +import { + Collection, + FlexTable, + FlexColumn, + SortDirection, + Grid, + VirtualScroll, + ArrowKeyStepper, + AutoSizer, + CellMeasurer, + ColumnSizer, + InfiniteLoader, + ScrollSync, + WindowScroller, +} 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 + }; + } } + height={300} + width={300} + />, + document.getElementById("example") + ); +} + + +function FlexTableTest() { + const list = [ + { name: 'Brian Vaughn', description: 'Software engineer' } + // And so on... + ]; + + // Render your table + ReactDOM.render( + list[index] + } + > + + + , + 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 VirtualScrollTest() { + // List data as an array of strings + const list = [ + 'Brian Vaughn' + // And so on... + ]; + + // Render your list + ReactDOM.render( + list[index]} + />, + document.getElementById('example') + ); +} + +function ArrowKeyStepperTest() { + const columnCount = 12; + const rowCount = 3; + + ReactDOM.render( + + {({ onSectionRendered, scrollToColumn, scrollToRow }) => ( + + ) } + , + document.getElementById('example') + ); +} + +function AutoSizerTest() { + // List data as an array of strings + const list = [ + 'Brian Vaughn' + // And so on... + ]; + + // Render your list + ReactDOM.render( + + {({ height, width }) => ( + list[index] // Could also be a DOM element + } + /> + ) } + , + 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 }) { + return list.push('test'); + } + + // Render your list + ReactDOM.render( + + {({ onRowsRendered, registerChild }) => ( + list[index] // Could also be a DOM element + } + /> + ) } + , + document.getElementById('example') + ); +} + +function ScrollSyncTest() { + return ( + + {({ clientHeight, clientWidth, onScroll, scrollHeight, scrollLeft, scrollTop, scrollWidth }) => ( + + + "test"} + rowCount={42} + height={12} + width={12} + rowHeight={120} + scrollTop={scrollTop}/> + /> + + + + + + ) } + + ); +} + +function WindowScrollerTest() { + ReactDOM.render( + + {({ height, isScrolling, scrollTop }) => ( + 'test'} + scrollTop={scrollTop} + width={120}/> + ) } + , + document.getElementById('example') + ); +} diff --git a/react-virtualized/react-virtualized.d.ts b/react-virtualized/react-virtualized.d.ts new file mode 100644 index 0000000000..aad19c44a3 --- /dev/null +++ b/react-virtualized/react-virtualized.d.ts @@ -0,0 +1,123 @@ +// Type definitions for react-virtualized +// Project: https://github.com/bvaughn/react-virtualized +// Definitions by: Ian Ker-Seymer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "react-virtualized" { + import * as React from "react"; + + /* + * Components + */ + + interface VirtualScrollProps { + className?: string; + autoHeight?: boolean; + estimatedRowSize?: number; + height: number; + noRowsRenderer?: Function; + onRowsRendered?: (info: { overscanStartIndex: number, overscanStopIndex: number, startIndex: number, stopIndex: number }) => void; + onScroll?: (info: { clientHeight: number, scrollHeight: number, scrollTop: number }) => void; + overscanRowCount?: number; + rowHeight: number | ((info: { index: number }) => number); + rowRenderer: (info: { index: number, isScrolling: boolean }) => React.ReactNode; + rowClassName?: string | ((info: { index: number }) => string); + rowCount: number; + rowStyle?: React.CSSProperties | ((info: { index: number }) => React.CSSProperties); + scrollToAlignment?: string; + scrollToIndex?: number; + scrollTop?: number; + style?: React.CSSProperties; + tabIndex?: number; + width: number; + } + export class VirtualScroll extends React.Component { } + + type CollectionProps = any; + export class Collection extends React.Component { } + + type FlexTableProps = any; + export class FlexTable extends React.Component { } + + type FlexColumnProps = any; + export class FlexColumn extends React.Component { } + + type SortDirectionProps = any; + export class SortDirection extends React.Component { } + + type GridProps = any; + export class Grid extends React.Component { } + + + /* + * Higher-Order Components + */ + + interface AutoSizerProps { + disableHeight?: boolean; + disableWidth?: boolean; + onResize?: (info: { height: number, width: number }) => any; + } + export class AutoSizer extends React.Component { } + + interface ArrowKeyStepperProps { + children?: React.StatelessComponent<{ + onSectionRendered: Function, + scrollToColumn: number, + scrollToRow: number + }>; + className?: string; + columnCount: number; + rowCount: number; + } + export class ArrowKeyStepper extends React.Component { } + + interface CellMeasurerProps { + cellRenderer: (info: { columnIndex: number, rowIndex: number }) => React.ReactNode; + cellSizeCache?: { + clearAllColumnWidths(): void; + clearAllRowHeights(): void; + clearColumnWidth(index: number): void; + clearRowHeight(index: number): void; + getColumnWidth(index: number): number; + getRowHeight(index: number): number; + hasColumnWidth(index: number): boolean; + hasRowHeight(index: number): boolean; + setColumnWidth(index: number, width: number): void; + setRowHeight(index: number, height: number): void; + }; + children?: React.StatelessComponent<{ + getColumnWidth: () => number, + getRowHeight: () => number, + resetMeasurements: () => any, + resetMeasurementsForColumn: (index: number) => any, + resetMeasurementsForRow: (index: number) => any, + }>; + columnCount: number; + container?: React.ReactType; + height?: number; + rowCount: number; + width?: number; + } + export class CellMeasurer extends React.Component { } + + interface ColumnSizerProps { + children?: React.StatelessComponent<{ adjustedWidth: number, getColumnWidth: () => number, registerChild: any }>; + columnMaxWidth?: number; + columnMinWidth?: number; + columnCount?: number; + width: number; + } + export class ColumnSizer extends React.Component { } + + type InfiniteLoaderProps = any; + export class InfiniteLoader extends React.Component { } + + type ScrollSyncProps = any; + export class ScrollSync extends React.Component { } + + type WindowScrollerProps = any; + export class WindowScroller extends React.Component { } +}