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