Files
RoboCommander/node_modules/react-bootstrap/es/MenuItem.js

155 lines
4.3 KiB
JavaScript
Raw Normal View History

2026-04-05 16:14:49 -04:00
import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
import _assertThisInitialized from "@babel/runtime-corejs2/helpers/esm/assertThisInitialized";
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import all from 'prop-types-extra/lib/all';
import SafeAnchor from './SafeAnchor';
import { bsClass, prefix, splitBsPropsAndOmit } from './utils/bootstrapUtils';
import createChainedFunction from './utils/createChainedFunction';
var propTypes = {
/**
* Highlight the menu item as active.
*/
active: PropTypes.bool,
/**
* Disable the menu item, making it unselectable.
*/
disabled: PropTypes.bool,
/**
* Styles the menu item as a horizontal rule, providing visual separation between
* groups of menu items.
*/
divider: all(PropTypes.bool, function (_ref) {
var divider = _ref.divider,
children = _ref.children;
return divider && children ? new Error('Children will not be rendered for dividers') : null;
}),
/**
* Value passed to the `onSelect` handler, useful for identifying the selected menu item.
*/
eventKey: PropTypes.any,
/**
* Styles the menu item as a header label, useful for describing a group of menu items.
*/
header: PropTypes.bool,
/**
* HTML `href` attribute corresponding to `a.href`.
*/
href: PropTypes.string,
/**
* Callback fired when the menu item is clicked.
*/
onClick: PropTypes.func,
/**
* Callback fired when the menu item is selected.
*
* ```js
* (eventKey: any, event: Object) => any
* ```
*/
onSelect: PropTypes.func
};
var defaultProps = {
divider: false,
disabled: false,
header: false
};
var MenuItem =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(MenuItem, _React$Component);
function MenuItem(props, context) {
var _this;
_this = _React$Component.call(this, props, context) || this;
_this.handleClick = _this.handleClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
return _this;
}
var _proto = MenuItem.prototype;
_proto.handleClick = function handleClick(event) {
var _this$props = this.props,
href = _this$props.href,
disabled = _this$props.disabled,
onSelect = _this$props.onSelect,
eventKey = _this$props.eventKey;
if (!href || disabled) {
event.preventDefault();
}
if (disabled) {
return;
}
if (onSelect) {
onSelect(eventKey, event);
}
};
_proto.render = function render() {
var _this$props2 = this.props,
active = _this$props2.active,
disabled = _this$props2.disabled,
divider = _this$props2.divider,
header = _this$props2.header,
onClick = _this$props2.onClick,
className = _this$props2.className,
style = _this$props2.style,
props = _objectWithoutPropertiesLoose(_this$props2, ["active", "disabled", "divider", "header", "onClick", "className", "style"]);
var _splitBsPropsAndOmit = splitBsPropsAndOmit(props, ['eventKey', 'onSelect']),
bsProps = _splitBsPropsAndOmit[0],
elementProps = _splitBsPropsAndOmit[1];
if (divider) {
// Forcibly blank out the children; separators shouldn't render any.
elementProps.children = undefined;
return React.createElement("li", _extends({}, elementProps, {
role: "separator",
className: classNames(className, 'divider'),
style: style
}));
}
if (header) {
return React.createElement("li", _extends({}, elementProps, {
role: "heading",
className: classNames(className, prefix(bsProps, 'header')),
style: style
}));
}
return React.createElement("li", {
role: "presentation",
className: classNames(className, {
active: active,
disabled: disabled
}),
style: style
}, React.createElement(SafeAnchor, _extends({}, elementProps, {
role: "menuitem",
tabIndex: "-1",
onClick: createChainedFunction(onClick, this.handleClick)
})));
};
return MenuItem;
}(React.Component);
MenuItem.propTypes = propTypes;
MenuItem.defaultProps = defaultProps;
export default bsClass('dropdown', MenuItem);