UNPKG

2.92 kBJavaScriptView Raw
1var _excluded = ["className", "cssModule", "tag", "active", "disabled", "action", "color"];
2function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5import React from 'react';
6import PropTypes from 'prop-types';
7import classNames from 'classnames';
8import { mapToCssModules, tagPropType } from './utils';
9var propTypes = {
10 /** Add action prop to give effects while hovering over element */
11 action: PropTypes.bool,
12 /** Add active prop to make the current selection active */
13 active: PropTypes.bool,
14 /** Add custom class */
15 className: PropTypes.string,
16 /** Change underlying component's CSS base class name */
17 cssModule: PropTypes.object,
18 /** Add background colour to the list item */
19 color: PropTypes.string,
20 /** Make the list item appear disabled */
21 disabled: PropTypes.bool,
22 /** Set a custom element for this component */
23 tag: tagPropType
24};
25var handleDisabledOnClick = function handleDisabledOnClick(e) {
26 e.preventDefault();
27};
28function ListGroupItem(props) {
29 var className = props.className,
30 cssModule = props.cssModule,
31 _props$tag = props.tag,
32 Tag = _props$tag === void 0 ? 'li' : _props$tag,
33 active = props.active,
34 disabled = props.disabled,
35 action = props.action,
36 color = props.color,
37 attributes = _objectWithoutProperties(props, _excluded);
38 var classes = mapToCssModules(classNames(className, active ? 'active' : false, disabled ? 'disabled' : false, action ? 'list-group-item-action' : false, color ? "list-group-item-".concat(color) : false, 'list-group-item'), cssModule);
39
40 // Prevent click event when disabled.
41 if (disabled) {
42 attributes.onClick = handleDisabledOnClick;
43 }
44 return /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
45 className: classes
46 }));
47}
48ListGroupItem.propTypes = propTypes;
49export default ListGroupItem;
\No newline at end of file