All files / nexshop-web-contents/src/component/popup/context-menu context-menu.js

100% Statements 13/13
100% Branches 4/4
100% Functions 5/5
100% Lines 13/13
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 591x 1x 1x 1x       5x   5x       4x       5x 5x   5x               11x     4x                                       1x              
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {popupEnhancer} from "nexshop-web-popup";
import {CONTEXT_MENU} from "../../../constants/context-menu";
 
class ContextMenu extends Component {
    constructor(props) {
        super(props);
 
        this.onItemClick = this.onItemClick.bind(this);
    }
 
    onItemClick(item) {
        this.props[item.value]();
    }
 
    render() {
        const {popupPosition, type} = this.props;
        const items = CONTEXT_MENU[type === undefined ? 'folder' : type];
 
        return (
            <div className='context-menu-wrapper' style={{
                left: popupPosition.x,
                top: popupPosition.y,
            }}>
                <div className='context-menu'>
                    {
                        items.map((item, index) =>
                            <div key={`${index}-wrapper`}>
                                <div key={index}
                                     className="context-menu-text"
                                     onClick={() => this.onItemClick(item)}>
                                    {item.text}
                                </div>
                                {
                                    item.underline &&
                                    <div key={`${index}__divider`}
                                         className="context-menu-text__divider"/>
                                }
                            </div>
                        )
 
                    }
                </div>
            </div>
        );
    }
}
 
export default popupEnhancer(ContextMenu, 'context-menu');
 
ContextMenu.PropTypes = {
    popupPosition: PropTypes.object.isRequired,
    onClose: PropTypes.func.isRequired,
    type: PropTypes.string,
    onRenameClick: PropTypes.func,
    onMoveToClick: PropTypes.func,
    onCopyToClick: PropTypes.func,
};