All files / nexshop-web-contents/src/component/resolution-drop-down resolution-menu.js

100% Statements 14/14
100% Branches 6/6
100% Functions 3/3
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 401x 1x 1x   1x 7x 7x 21x   18x 6x   12x       7x       21x                     1x                
import React from 'react';
import PropTypes from 'prop-types';
import ResolutionItem from "./resolution-item";
 
const ResolutionMenu = (props) => {
    const {items, selectedItem, onItemSelected, onBlur} = props;
    const getSelectedOrientation = (item, selectedItem) => {
        if (!selectedItem) return '';
 
        if (item.value === selectedItem.value && item.text === selectedItem.text) {
            return selectedItem.orientation;
        } else {
            return '';
        }
    };
 
    return (
        <div className="resolution-menu" tabIndex="0" onBlur={onBlur}>
            {
                items.map((item, index) => (
                    <ResolutionItem key={index}
                                    item={item}
                                    selectedOrientation={getSelectedOrientation(item, selectedItem)}
                                    onSelected={onItemSelected}
                    />
                ))
            }
        </div>
    );
};
 
ResolutionMenu.propTypes = {
    items: PropTypes.array.isRequired,
    selectedItem: PropTypes.object,
    selectedOrientation: PropTypes.string,
    onItemSelected: PropTypes.func,
    onBlur: PropTypes.func
};
 
export default ResolutionMenu;