All files scroll-panel.js

54.55% Statements 6/11
25% Branches 1/4
100% Functions 0/0
54.55% Lines 6/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56      1x 1x 1x                                                               1x               1x 1x                  
/**
 * A component to use when you want scrolling other places than the global document
 */
import React, { PropTypes as PT } from 'react';
import CtxTypes from './ctx-types';
import ScrollSpy from './scroll-spy';
 
class ScrollPanel extends React.Component {
    getChildContext() {
        const { offset, events, animate } = this.props;
        return {
            offset,
            events,
            animate,
            container: this.refs.container || document.body
        };
    }
 
    componentDidMount() {
        ScrollSpy.registerScrollpanel(this.refs.container);
        this.forceUpdate();
    }
 
    componentWillUnmount() {
        ScrollSpy.unregisterScrollpanel(this.refs.container);
    }
 
    render() {
        const { tag, children, ...elemProps } = this.props; // eslint-disable-line no-use-before-define
        return React.createElement(
            tag,
            { ...elemProps, ref: 'container' },
            children
        );
    }
}
 
ScrollPanel.defaultProps = {
    tag: 'div',
    className: 'scroll-panel',
    offset: 0,
    events: {},
    animate: true
};
 
ScrollPanel.childContextTypes = CtxTypes.contextTypes;
ScrollPanel.propTypes = {
    offset: PT.number,
    events: PT.object,
    animate: PT.bool,
    tag: PT.string,
    children: PT.arrayOf(PT.element)
};
 
export default ScrollPanel;