import * as React from 'react'
import { ScrollContainerProps } from '../interfaces'
import * as cx from 'classnames'

const styles = require('../../src/styles/components/scroll-container.scss')

export class ScrollContainer extends React.Component<ScrollContainerProps, {}> {

    private scrollContainer: HTMLDivElement

    public componentDidUpdate() {
        if (this.props.scrollTop) {
            this.scrollContainer.scrollTop = this.props.scrollTop;
        }
    }

    public render() {
        /* tslint:disable:jsx-no-lambda */
        return (
            <div
                ref={(e: HTMLDivElement) => this.scrollContainer = e}
                className={cx(styles.container, this.props.className)}
                style={this.props.style}>
                {this.props.children}
            </div>
        )
        /* tslint:enable:jsx-no-lambda */
    }
}
