{"size": 1421, "ext": "js", "max_stars_repo_path": "src/component/Viewer/SelectMenu.js", "max_stars_repo_name": "HFO4/cloudreve-frontend", "max_stars_repo_stars_event_min_datetime": "2019-03-16T08:22:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-22T02:39:30.000Z", "max_issues_repo_path": "src/component/Viewer/SelectMenu.js", "max_issues_repo_name": "HFO4/cloudreve-frontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/component/Viewer/SelectMenu.js", "max_forks_repo_name": "HFO4/cloudreve-frontend", "max_forks_repo_forks_event_min_datetime": "2019-03-19T07:42:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-19T07:42:38.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.0847457627, "max_line_length": 67, "alphanum_fraction": 0.3687543983}
import React from "react";
import {
    Icon,
    ListItemIcon,
    makeStyles,
    Menu,
    MenuItem,
} from "@material-ui/core";
import CheckIcon from "@material-ui/icons/Check";

const useStyles = makeStyles((theme) => ({
    icon: {
        minWidth: 38,
    },
}));

export default function SelectMenu({
    options,
    anchorEl,
    handleClose,
    callback,
    selected,
    showIcon = true,
}) {
    const classes = useStyles();

    return (
        <Menu
            id="simple-menu"
            anchorEl={anchorEl}
            keepMounted
            open={Boolean(anchorEl)}
            onClose={handleClose}
        >
            {options.map((item) => (
                <>
                    <MenuItem
                        style={{ whiteSpace: "normal" }}
                        dense
                        onClick={() => callback(item)}
                    >
                        {showIcon && (
                            <ListItemIcon className={classes.icon}>
                                {item.name !== selected ? (
                                    <Icon />
                                ) : (
                                    <CheckIcon />
                                )}
                            </ListItemIcon>
                        )}

                        {item.name}
                    </MenuItem>
                </>
            ))}
        </Menu>
    );
}
