import React from 'react';
import ReactDOM from 'react-dom';
import VirtualList from '..';
const dataSource = [];
function generateLi(index) {
    if (index % 3 === 0) {
        return (React.createElement("li", { key: `key-${index}`, style: { lineHeight: '30px', background: '#5f83ff', color: '#fff' } },
            "key-",
            index));
    }
    return (React.createElement("li", { key: `key-${index}`, style: { lineHeight: '20px' } },
        "key-",
        index));
}
function generateData(len) {
    for (let i = 0; i < len; i++) {
        dataSource.push(generateLi(i));
    }
}
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            initial: 20,
            dataSource: generateData(1000),
        };
    }
    componentDidMount() {
        setTimeout(() => {
            const instance = this.refs.virtual.getInstance();
            instance.scrollTo(50);
        }, 200);
    }
    getHeight(index) {
        return index % 3 === 0 ? 30 : 20;
    }
    onClick() {
        this.setState({
            initial: this.state.initial + 20,
        });
    }
    render() {
        return (React.createElement("div", null,
            React.createElement("button", { onClick: this.onClick.bind(this) },
                "jump to ",
                this.state.initial + 20),
            React.createElement("br", null),
            React.createElement("br", null),
            React.createElement("div", { className: 'virtual-box' },
                React.createElement(VirtualList, { ref: "virtual", jumpIndex: this.state.initial, itemSizeGetter: this.getHeight.bind(this) }, dataSource))));
    }
}
ReactDOM.render(React.createElement(App, null), document.getElementById('virtual-list-demo-3'));
