UNPKG

1.98 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import classNames from 'classnames';
4import React, { useCallback } from 'react';
5import AbstractNavItem from './AbstractNavItem';
6import { makeEventKey } from './SelectableContext';
7import { useBootstrapPrefix } from './ThemeProvider';
8var defaultProps = {
9 variant: undefined,
10 active: false,
11 disabled: false
12};
13var ListGroupItem = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
14 var bsPrefix = _ref.bsPrefix,
15 active = _ref.active,
16 disabled = _ref.disabled,
17 className = _ref.className,
18 variant = _ref.variant,
19 action = _ref.action,
20 as = _ref.as,
21 eventKey = _ref.eventKey,
22 onClick = _ref.onClick,
23 props = _objectWithoutPropertiesLoose(_ref, ["bsPrefix", "active", "disabled", "className", "variant", "action", "as", "eventKey", "onClick"]);
24
25 bsPrefix = useBootstrapPrefix(bsPrefix, 'list-group-item');
26 var handleClick = useCallback(function (event) {
27 if (disabled) {
28 event.preventDefault();
29 event.stopPropagation();
30 return;
31 }
32
33 if (onClick) onClick(event);
34 }, [disabled, onClick]);
35
36 if (disabled && props.tabIndex === undefined) {
37 props.tabIndex = -1;
38 props['aria-disabled'] = true;
39 }
40
41 return /*#__PURE__*/React.createElement(AbstractNavItem, _extends({
42 ref: ref
43 }, props, {
44 // TODO: Restrict eventKey to string in v5?
45 eventKey: makeEventKey(eventKey, props.href) // eslint-disable-next-line no-nested-ternary
46 ,
47 as: as || (action ? props.href ? 'a' : 'button' : 'div'),
48 onClick: handleClick,
49 className: classNames(className, bsPrefix, active && 'active', disabled && 'disabled', variant && bsPrefix + "-" + variant, action && bsPrefix + "-action")
50 }));
51});
52ListGroupItem.defaultProps = defaultProps;
53ListGroupItem.displayName = 'ListGroupItem';
54export default ListGroupItem;
\No newline at end of file