forked from vkbansal/react-contextmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuItem.js
More file actions
73 lines (63 loc) · 2.21 KB
/
Copy pathMenuItem.js
File metadata and controls
73 lines (63 loc) · 2.21 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import assign from 'object-assign';
import { hideMenu } from './actions';
import { callIfExists, cssClasses, store } from './helpers';
export default class MenuItem extends Component {
static propTypes = {
children: PropTypes.node,
attributes: PropTypes.object,
data: PropTypes.object,
disabled: PropTypes.bool,
divider: PropTypes.bool,
preventClose: PropTypes.bool,
onClick: PropTypes.func,
selected: PropTypes.bool,
onMouseMove: PropTypes.func,
onMouseLeave: PropTypes.func
};
static defaultProps = {
disabled: false,
data: {},
divider: false,
attributes: {},
preventClose: false,
onClick() { return null; },
children: null,
selected: false,
onMouseMove: () => null,
onMouseLeave: () => null
};
handleClick = (event) => {
event.preventDefault();
if (this.props.disabled || this.props.divider) return;
callIfExists(
this.props.onClick,
event,
assign({}, this.props.data, store.data),
store.target
);
if (this.props.preventClose) return;
hideMenu();
}
render() {
const { disabled, divider, children, attributes, selected } = this.props;
const menuItemClassNames = cx(cssClasses.menuItem, attributes && attributes.className, {
[cssClasses.menuItemDisabled]: disabled,
[cssClasses.menuItemDivider]: divider,
[cssClasses.menuItemSelected]: selected
});
return (
<div
{...attributes} className={menuItemClassNames}
role='menuitem' tabIndex='-1' aria-disabled={disabled ? 'true' : 'false'}
aria-orientation={divider ? 'horizontal' : null}
ref={(ref) => { this.ref = ref; }}
onMouseMove={this.props.onMouseMove} onMouseLeave={this.props.onMouseLeave}
onTouchEnd={this.handleClick} onClick={this.handleClick}>
{divider ? null : children}
</div>
);
}
}