all files / react-dragme/src/ core.js

100% Statements 12/12
100% Branches 2/2
100% Functions 7/7
100% Lines 12/12
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 57 58 59 60                          15×     15×                         10×                                          
import React from 'react';
 
export default class DragCore extends React.Component {
   
    constructor(props) { 
        super(props);  
    } 
 
    render() {
        return (
            <div className="dragContainer" 
                 style={this.props.dragContainerStyle}
            >
                {
                    React.Children.map(this.props.children, child => {
                        let childProps = child.props;
                        // console.log('***************************')
                        // console.log(childProps)
                        if(childProps.dragInfo.draggable) {
                            return  <div className="draggable"
                                    style={{
                                        position: "absolute", 
                                        left: childProps.dragInfo.x,
                                        top: childProps.dragInfo.y,
                                        zIndex: childProps.dragInfo.zIndex,
                                        cursor: childProps.dragInfo.cursor,
                                        //transform: childProps.dragInfo.transform
                                    }}
                                    onMouseDown={(e,key)=>childProps.handleMouseDown(e,childProps.dragInfo.key)}
                                    onMouseMove={(e,key)=>childProps.handleMouseMove(e,childProps.dragInfo.key)}
                                    onMouseUp={(e,key)=>childProps.handleMouseUp(e,childProps.dragInfo.key)}
                                    onMouseLeave={(e,key)=>childProps.handleMouseLeave(e,childProps.dragInfo.key)}
                                >
                                    { child }
                                </div>
                        } else {
                            return  <div className="commonElement"
                                    style={{
                                        position: "absolute", 
                                        left: childProps.dragInfo.x,
                                        top: childProps.dragInfo.y,
                                        //transform: childProps.dragInfo.transform,
                                        zIndex: childProps.dragInfo.zIndex
                                    }}
                                >
                                    { child }
                                </div>
                        }
                    })
                }
            </div>
        );
    }
}
DragCore.propTypes = { 
    dragContainerStyle: React.PropTypes.object 
}; 
DragCore.defaultProps = { 
    dragContainerStyle: {} 
};