/**
 * @file ScrollableTable component
 * @author liangxiaojun(liangxiaojun@derbysoft.com)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';

class ScrollableTable extends Component {

    constructor(props, ...restArgs) {
        super(props, ...restArgs);
    }

    getStyle = () => {

        const {style, scroll, overflowHidden, horizontalOverflowScroll} = this.props;

        if (overflowHidden) {
            return style;
        }

        return {
            ...style,
            overflowX: horizontalOverflowScroll ? 'scroll' : scroll.width ? 'auto' : null,
            overflowY: scroll.height || scroll.maxHeight ? 'scroll' : null
        };

    };

    render() {

        const {

            children, style, scroll,

            // not passing down these props
            overflowHidden, horizontalOverflowScroll,

            ...restProps

        } = this.props;

        return scroll ?
            <div {...restProps}
                 style={this.getStyle()}>
                {children}
            </div>
            :
            children;

    }
}

ScrollableTable.propTypes = {

    children: PropTypes.any,

    style: PropTypes.object,

    /**
     * scroll
     */
    scroll: PropTypes.shape({
        width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
        height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
        maxHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
    }),

    overflowHidden: PropTypes.bool,
    horizontalOverflowScroll: PropTypes.bool

};

ScrollableTable.defaultProps = {
    overflowHidden: false,
    horizontalOverflowScroll: false
};

export default ScrollableTable;

@@ -113,16 +113,27 @@
 omponent
+, createRef
 %7D from '
@@ -254,24 +254,25 @@
 restArgs) %7B%0A
+%0A
         supe
@@ -294,16 +294,117 @@
 tArgs);%0A
+%0A        this.wrapper = createRef();%0A%0A        this.state = %7B%0A            wrapperEl: null%0A        %7D;%0A%0A
     %7D%0A%0A 
@@ -801,24 +801,153 @@
 %7D;%0A%0A    %7D;%0A%0A
+    componentDidMount() %7B%0A        this.setState(%7B%0A            wrapperEl: this.wrapper && this.wrapper.current%0A        %7D);%0A    %7D%0A%0A
     render()
@@ -971,32 +971,36 @@
  %7B%0A%0A            
+ 
+   
 children, style,
@@ -1001,32 +1001,36 @@
 style, scroll,%0A%0A
+    
             // n
@@ -1057,16 +1057,20 @@
 e props%0A
+    
         
@@ -1128,16 +1128,20 @@
         
+    
 ...restP
@@ -1154,16 +1154,20 @@
         
+  
+  
 %7D = this
@@ -1164,32 +1164,70 @@
   %7D = this.props
+,%0A            %7BwrapperEl%7D = this.state
 ;%0A%0A        retur
@@ -1269,16 +1269,52 @@
 tProps%7D%0A
+                 ref=%7Bthis.wrapper%7D%0A
         
@@ -1364,24 +1364,31 @@
        %7B
+typeof 
 children
 %7D%0A      
@@ -1379,16 +1379,72 @@
 children
+ === 'function' ? children(wrapperEl) : children %7C%7C null
 %7D%0A      

update ScrollableTable