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
90 lines (79 loc) · 2.59 KB
/
Copy pathMenuItem.js
File metadata and controls
90 lines (79 loc) · 2.59 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 = {
attributes: PropTypes.object,
children: PropTypes.node,
className: PropTypes.string,
data: PropTypes.object,
disabled: PropTypes.bool,
divider: PropTypes.bool,
onClick: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseMove: PropTypes.func,
preventClose: PropTypes.bool,
selected: PropTypes.bool
};
static defaultProps = {
attributes: {},
children: null,
className: '',
data: {},
disabled: false,
divider: false,
onClick() { return null; },
onMouseMove: () => null,
onMouseLeave: () => null,
preventClose: false,
selected: false
};
handleClick = (event) => {
if (event.button !== 0 && event.button !== 1) {
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 {
attributes,
children,
className,
disabled,
divider,
selected
} = this.props;
const menuItemClassNames = cx(
className,
cssClasses.menuItem,
attributes.className,
{
[cx(cssClasses.menuItemDisabled, attributes.disabledClassName)]: disabled,
[cx(cssClasses.menuItemDivider, attributes.dividerClassName)]: divider,
[cx(cssClasses.menuItemSelected, attributes.selectedClassName)]: 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>
);
}
}