import React from 'react'; import PropTypes from 'prop-types'; import ls from './Menu.less'; import AuxWidget from "./AuxWidget"; import cx from 'classnames'; import Fa from './Fa'; export default function Menu({children, x, y, orientationUp, centered, menuId, ...props}) { return {children} ; } export function MenuSeparator() { return
} export function MenuItem({icon, label, hotKey, style, disabled, onClick, children, ...props}, {closeAllUpPopups}) { if (hotKey) { hotKey = hotKey.replace(/\s/g, ''); if (hotKey.length > 15) { hotKey = null; } } let clickHandler = disabled ? undefined : () => { closeAllUpPopups(); onClick(); }; return
e.stopPropagation()} style={style} onClick={clickHandler} {...props}> {icon} {label} {hotKey && {hotKey}}
; } export class ContextMenu extends React.Component { state = { active: false }; onClick = e => { e.preventDefault(); this.setState({ active: true, x: e.clientX, y: e.clientY }); }; close = () => { this.setState({active: false}) }; componentDidMount() { this.detacher = this.context.onCloseAll.attach(this.close); } componentWillUnmount() { this.detacher(); } render() { return {this.props.children} {this.state.active && {this.props.items} } } getChildContext() { return { closeMenu: this.close }; } static contextTypes = { onCloseAll: PropTypes.object }; static childContextTypes = { closeMenu: PropTypes.func }; } export function ContextMenuItem({onClick, ...props}, {closeMenu}) { return { closeMenu(); onClick(); }} {...props}/>; } ContextMenuItem.contextTypes = { closeMenu: PropTypes.func }; MenuItem.contextTypes = { closeAllUpPopups: PropTypes.func };