1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import classNames from 'classnames';
|
7 | import React from 'react';
|
8 | import PropTypes from 'prop-types';
|
9 | import all from 'prop-types-extra/lib/all';
|
10 |
|
11 | import SafeAnchor from './SafeAnchor';
|
12 | import { bsClass, prefix, splitBsPropsAndOmit } from './utils/bootstrapUtils';
|
13 | import createChainedFunction from './utils/createChainedFunction';
|
14 |
|
15 | var propTypes = {
|
16 | |
17 |
|
18 |
|
19 | active: PropTypes.bool,
|
20 |
|
21 | |
22 |
|
23 |
|
24 | disabled: PropTypes.bool,
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 | divider: all(PropTypes.bool, function (_ref) {
|
31 | var divider = _ref.divider,
|
32 | children = _ref.children;
|
33 | return divider && children ? new Error('Children will not be rendered for dividers') : null;
|
34 | }),
|
35 |
|
36 | |
37 |
|
38 |
|
39 | eventKey: PropTypes.any,
|
40 |
|
41 | |
42 |
|
43 |
|
44 | header: PropTypes.bool,
|
45 |
|
46 | |
47 |
|
48 |
|
49 | href: PropTypes.string,
|
50 |
|
51 | |
52 |
|
53 |
|
54 | onClick: PropTypes.func,
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | onSelect: PropTypes.func
|
64 | };
|
65 |
|
66 | var defaultProps = {
|
67 | divider: false,
|
68 | disabled: false,
|
69 | header: false
|
70 | };
|
71 |
|
72 | var MenuItem = function (_React$Component) {
|
73 | _inherits(MenuItem, _React$Component);
|
74 |
|
75 | function MenuItem(props, context) {
|
76 | _classCallCheck(this, MenuItem);
|
77 |
|
78 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context));
|
79 |
|
80 | _this.handleClick = _this.handleClick.bind(_this);
|
81 | return _this;
|
82 | }
|
83 |
|
84 | MenuItem.prototype.handleClick = function handleClick(event) {
|
85 | var _props = this.props,
|
86 | href = _props.href,
|
87 | disabled = _props.disabled,
|
88 | onSelect = _props.onSelect,
|
89 | eventKey = _props.eventKey;
|
90 |
|
91 |
|
92 | if (!href || disabled) {
|
93 | event.preventDefault();
|
94 | }
|
95 |
|
96 | if (disabled) {
|
97 | return;
|
98 | }
|
99 |
|
100 | if (onSelect) {
|
101 | onSelect(eventKey, event);
|
102 | }
|
103 | };
|
104 |
|
105 | MenuItem.prototype.render = function render() {
|
106 | var _props2 = this.props,
|
107 | active = _props2.active,
|
108 | disabled = _props2.disabled,
|
109 | divider = _props2.divider,
|
110 | header = _props2.header,
|
111 | onClick = _props2.onClick,
|
112 | className = _props2.className,
|
113 | style = _props2.style,
|
114 | props = _objectWithoutProperties(_props2, ['active', 'disabled', 'divider', 'header', 'onClick', 'className', 'style']);
|
115 |
|
116 | var _splitBsPropsAndOmit = splitBsPropsAndOmit(props, ['eventKey', 'onSelect']),
|
117 | bsProps = _splitBsPropsAndOmit[0],
|
118 | elementProps = _splitBsPropsAndOmit[1];
|
119 |
|
120 | if (divider) {
|
121 |
|
122 | elementProps.children = undefined;
|
123 |
|
124 | return React.createElement('li', _extends({}, elementProps, {
|
125 | role: 'separator',
|
126 | className: classNames(className, 'divider'),
|
127 | style: style
|
128 | }));
|
129 | }
|
130 |
|
131 | if (header) {
|
132 | return React.createElement('li', _extends({}, elementProps, {
|
133 | role: 'heading',
|
134 | className: classNames(className, prefix(bsProps, 'header')),
|
135 | style: style
|
136 | }));
|
137 | }
|
138 |
|
139 | return React.createElement(
|
140 | 'li',
|
141 | {
|
142 | role: 'presentation',
|
143 | className: classNames(className, { active: active, disabled: disabled }),
|
144 | style: style
|
145 | },
|
146 | React.createElement(SafeAnchor, _extends({}, elementProps, {
|
147 | role: 'menuitem',
|
148 | tabIndex: '-1',
|
149 | onClick: createChainedFunction(onClick, this.handleClick)
|
150 | }))
|
151 | );
|
152 | };
|
153 |
|
154 | return MenuItem;
|
155 | }(React.Component);
|
156 |
|
157 | MenuItem.propTypes = propTypes;
|
158 | MenuItem.defaultProps = defaultProps;
|
159 |
|
160 | export default bsClass('dropdown', MenuItem); |
\ | No newline at end of file |