import React from "react";
import { createPortal } from "react-dom";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import classnames from "classnames";
import "../../css/context-menu.css";
class Portal extends React.Component {
componentWillMount() {
this._node = document.createElement("div");
this._node.id = "webamp-context-menu";
this._node.style.position = "absolute";
this._node.style.top = 0;
this._node.style.left = 0;
this._node.style.zIndex = this.props.zIndex + 1;
document.body.appendChild(this._node);
}
componentWillUnmount() {
document.body.removeChild(this._node);
}
render() {
const style = {
position: "absolute",
top: this.props.top,
left: this.props.left
};
return createPortal(
{this.props.children}
,
this._node
);
}
}
export const Hr = () => (
);
export const Parent = ({ children, label }) => (
{label}
);
export const LinkNode = props => (
{props.label}
);
LinkNode.propTypes = {
label: PropTypes.string.isRequired,
href: PropTypes.string.isRequired
};
export const Node = props => {
const { label, checked, className = "", ...passThroughProps } = props;
return (
{label}
);
};
Node.propTypes = {
label: PropTypes.string.isRequired,
hotkey: PropTypes.string
};
class ContextMenu extends React.Component {
render() {
const {
children,
offsetTop,
offsetLeft,
top,
bottom,
selected,
zIndex
} = this.props;
return (
selected && (
)
);
}
}
const mapStateToProps = state => ({
zIndex: state.display.zIndex
});
export default connect(mapStateToProps)(ContextMenu);