mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 22:38:33 +08:00
Add type definitions for react-infinite package
Project: https://github.com/seatgeek/react-infinite
This commit is contained in:
113
react-infinite/react-infinite-tests.tsx
Normal file
113
react-infinite/react-infinite-tests.tsx
Normal file
@@ -0,0 +1,113 @@
|
||||
///<reference path='../react/react.d.ts' />
|
||||
///<reference path='../react-infinite/react-infinite.d.ts' />
|
||||
|
||||
import * as React from 'react';
|
||||
import Infinite = require('react-infinite');
|
||||
|
||||
class Test1 extends React.Component<{}, {}> {
|
||||
render() {
|
||||
return (
|
||||
<Infinite containerHeight={200} elementHeight={40}>
|
||||
<div className="one"/>
|
||||
<div className="two"/>
|
||||
<div className="three"/>
|
||||
</Infinite>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 extends React.Component<{}, {}> {
|
||||
render() {
|
||||
return (
|
||||
<Infinite containerHeight={200} elementHeight={[111, 252, 143]}>
|
||||
<div className="111-px"/>
|
||||
<div className="252-px"/>
|
||||
<div className="143-px"/>
|
||||
</Infinite>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 extends React.Component<{}, {}> {
|
||||
render() {
|
||||
return (
|
||||
<Infinite containerHeight={200} elementHeight={[111, 252, 143]}
|
||||
useWindowAsScrollContainer>
|
||||
<div className="111-px"/>
|
||||
<div className="252-px"/>
|
||||
<div className="143-px"/>
|
||||
</Infinite>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 extends React.Component<{}, {}> {
|
||||
render() {
|
||||
return (
|
||||
<Infinite containerHeight={200} elementHeight={[111, 252, 143]}
|
||||
displayBottomUpwards>
|
||||
<div className="third-latest-chat"/>
|
||||
<div className="second-latest-chat"/>
|
||||
<div className="latest-chat-message"/>
|
||||
</Infinite>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var ListItem = React.createClass<{key: number; num: number;}, {}>({
|
||||
render: function() {
|
||||
return <div className="infinite-list-item">
|
||||
List Item {this.props.num}
|
||||
</div>;
|
||||
}
|
||||
});
|
||||
|
||||
var InfiniteList = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
elements: this.buildElements(0, 20),
|
||||
isInfiniteLoading: false
|
||||
}
|
||||
},
|
||||
|
||||
buildElements: function(start: number, end: number) {
|
||||
var elements = [] as React.ReactElement<any>[];
|
||||
for (var i = start; i < end; i++) {
|
||||
elements.push(<ListItem key={i} num={i}/>)
|
||||
}
|
||||
return elements;
|
||||
},
|
||||
|
||||
handleInfiniteLoad: function() {
|
||||
var that = this;
|
||||
this.setState({
|
||||
isInfiniteLoading: true
|
||||
});
|
||||
setTimeout(function() {
|
||||
var elemLength = that.state.elements.length,
|
||||
newElements = that.buildElements(elemLength, elemLength + 1000);
|
||||
that.setState({
|
||||
isInfiniteLoading: false,
|
||||
elements: that.state.elements.concat(newElements)
|
||||
});
|
||||
}, 2500);
|
||||
},
|
||||
|
||||
elementInfiniteLoad: function() {
|
||||
return <div className="infinite-list-item">
|
||||
Loading...
|
||||
</div>;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return <Infinite elementHeight={40}
|
||||
containerHeight={250}
|
||||
infiniteLoadBeginEdgeOffset={200}
|
||||
onInfiniteLoad={this.handleInfiniteLoad}
|
||||
loadingSpinnerDelegate={this.elementInfiniteLoad()}
|
||||
isInfiniteLoading={this.state.isInfiniteLoading}
|
||||
>
|
||||
{this.state.elements}
|
||||
</Infinite>;
|
||||
}
|
||||
});
|
||||
36
react-infinite/react-infinite.d.ts
vendored
Normal file
36
react-infinite/react-infinite.d.ts
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// Type definitions for react-infinite
|
||||
// Project: https://github.com/seatgeek/react-infinite
|
||||
// Definitions by: rhysd <https://github.com/rhysd>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
///<reference path='../react/react.d.ts' />
|
||||
|
||||
declare module "react-infinite" {
|
||||
import Infinite = ReactInfinite.Infinite;
|
||||
export = Infinite;
|
||||
}
|
||||
|
||||
declare namespace ReactInfinite {
|
||||
import React = __React;
|
||||
|
||||
interface InfiniteProps extends React.Props<Infinite> {
|
||||
elementHeight: number | number[];
|
||||
containerHeight?: number;
|
||||
preloadBatchSize?: number | Object;
|
||||
preloadAdditionalHeight?: number | Object;
|
||||
handleScroll?: (node: React.ReactElement<any>) => void;
|
||||
infiniteLoadBeginBottomOffset?: number;
|
||||
infiniteLoadBeginEdgeOffset?: number;
|
||||
onInfiniteLoad?: () => void;
|
||||
loadingSpinnerDelegate?: React.ReactElement<any>;
|
||||
isInfiniteLoading?: boolean;
|
||||
timeScrollStateLastsForAfterUserScrolls?: number;
|
||||
className?: string;
|
||||
useWindowAsScrollContainer?: boolean;
|
||||
displayBottomUpwards?: boolean;
|
||||
}
|
||||
|
||||
export class Infinite extends React.Component<InfiniteProps, {}> {
|
||||
static containerHeightScaleFactor(n: number): any;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user