aboutsummaryrefslogtreecommitdiffstats
path: root/src/react/PopupMenu.js
blob: d2cd29af7df4734c1d0584bbcaa1e56835253fe1 (plain)
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
import React from 'react';
import PropTypes from 'prop-types';
import PopupMenuItem from './PopupMenuItem';

class PopupMenu extends React.Component {
	render() {
		const {children = [], onMenuItemClick, position = {}, relative} = this.props;
		const style = relative ? {left: position.x, top: position.y} : {};

		return (
			<ul className={`sdc-menu-list ${relative ? 'relative' : ''}`} style={style}>
					{React.Children.toArray(children).map((child, i) => React.cloneElement(child,
						{
							onClick: child.props.onClick || onMenuItemClick,
							key: i
						}))}
			</ul>
		);
	}
}

PopupMenu.propTypes = {
	relative: PropTypes.bool,
	position: PropTypes.shape({
		x: PropTypes.number,
		y: PropTypes.number
	}),
	onMenuItemClick: PropTypes.func
};

PopupMenu.defaultProps = {
	relative: false
};

export const PopupMenuSeparator = () => <li className='separator' />;

PopupMenu.Separator = PopupMenuSeparator;
PopupMenu.Item = PopupMenuItem;
export default PopupMenu;