jsketcher/modules/ui/components/Menu.jsx
2018-01-17 19:19:33 -08:00

47 lines
1.2 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import ls from './Menu.less';
import AuxWidget from "./AuxWidget";
import cx from 'classnames';
export default function Menu({children, x, y, orientationUp, ...props}) {
return <AuxWidget
className={cx(ls.root, 'disable-selection')}
zIndex={500}
left={x}
top={orientationUp ? undefined : y}
bottom={orientationUp ? y : undefined}
{...props}>
{children}
</AuxWidget>;
}
export function MenuSeparator() {
return <div className={ls.separator} />
}
export function MenuItem({icon, label, hotKey, style, disabled, onClick}, {closeAllUpPopups}) {
if (hotKey) {
hotKey = hotKey.replace(/\s/g, '');
if (hotKey.length > 15) {
hotKey = null;
}
}
let clickHandler = disabled ? undefined : () => {
closeAllUpPopups();
onClick();
};
return <div className={cx(ls.item, disabled && ls.disabled)}
onMouseDown={e => e.stopPropagation()} style={style} onClick={clickHandler}>
{icon}
<span className={ls.label}>{label}</span>
{hotKey && <span className={ls.hotKey}>{hotKey}</span>}
</div>;
}
MenuItem.contextTypes = {
closeAllUpPopups: PropTypes.func
};