import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { DropdownContext } from './DropdownContext'; import { mapToCssModules, omit, tagPropType } from './utils'; var propTypes = { children: PropTypes.node, active: PropTypes.bool, disabled: PropTypes.bool, divider: PropTypes.bool, tag: tagPropType, header: PropTypes.bool, onClick: PropTypes.func, className: PropTypes.string, cssModule: PropTypes.object, toggle: PropTypes.bool, text: PropTypes.bool }; var defaultProps = { tag: 'button', toggle: true }; var DropdownItem = /*#__PURE__*/function (_React$Component) { _inheritsLoose(DropdownItem, _React$Component); function DropdownItem(props) { var _this; _this = _React$Component.call(this, props) || this; _this.onClick = _this.onClick.bind(_assertThisInitialized(_this)); _this.getTabIndex = _this.getTabIndex.bind(_assertThisInitialized(_this)); return _this; } var _proto = DropdownItem.prototype; _proto.onClick = function onClick(e) { var _this$props = this.props, disabled = _this$props.disabled, header = _this$props.header, divider = _this$props.divider, text = _this$props.text; if (disabled || header || divider || text) { e.preventDefault(); return; } if (this.props.onClick) { this.props.onClick(e); } if (this.props.toggle) { this.context.toggle(e); } }; _proto.getTabIndex = function getTabIndex() { var _this$props2 = this.props, disabled = _this$props2.disabled, header = _this$props2.header, divider = _this$props2.divider, text = _this$props2.text; if (disabled || header || divider || text) { return '-1'; } return '0'; }; _proto.render = function render() { var tabIndex = this.getTabIndex(); var role = tabIndex > -1 ? 'menuitem' : undefined; var _omit = omit(this.props, ['toggle']), className = _omit.className, cssModule = _omit.cssModule, divider = _omit.divider, Tag = _omit.tag, header = _omit.header, active = _omit.active, text = _omit.text, props = _objectWithoutPropertiesLoose(_omit, ["className", "cssModule", "divider", "tag", "header", "active", "text"]); var classes = mapToCssModules(classNames(className, { disabled: props.disabled, 'dropdown-item': !divider && !header && !text, active: active, 'dropdown-header': header, 'dropdown-divider': divider, 'dropdown-item-text': text }), cssModule); if (Tag === 'button') { if (header) { Tag = 'h6'; } else if (divider) { Tag = 'div'; } else if (props.href) { Tag = 'a'; } else if (text) { Tag = 'span'; } } return /*#__PURE__*/React.createElement(Tag, _extends({ type: Tag === 'button' && (props.onClick || this.props.toggle) ? 'button' : undefined }, props, { tabIndex: tabIndex, role: role, className: classes, onClick: this.onClick })); }; return DropdownItem; }(React.Component); DropdownItem.propTypes = propTypes; DropdownItem.defaultProps = defaultProps; DropdownItem.contextType = DropdownContext; export default DropdownItem;