Files
RoboCommander/node_modules/react-bootstrap/es/ListGroup.js
2026-04-05 16:14:49 -04:00

75 lines
2.5 KiB
JavaScript

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 classNames from 'classnames';
import React, { cloneElement } from 'react';
import elementType from 'prop-types-extra/lib/elementType';
import ListGroupItem from './ListGroupItem';
import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
import ValidComponentChildren from './utils/ValidComponentChildren';
var propTypes = {
/**
* You can use a custom element type for this component.
*
* If not specified, it will be treated as `'li'` if every child is a
* non-actionable `<ListGroupItem>`, and `'div'` otherwise.
*/
componentClass: elementType
};
function getDefaultComponent(children) {
if (!children) {
// FIXME: This is the old behavior. Is this right?
return 'div';
}
if (ValidComponentChildren.some(children, function (child) {
return child.type !== ListGroupItem || child.props.href || child.props.onClick;
})) {
return 'div';
}
return 'ul';
}
var ListGroup =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(ListGroup, _React$Component);
function ListGroup() {
return _React$Component.apply(this, arguments) || this;
}
var _proto = ListGroup.prototype;
_proto.render = function render() {
var _this$props = this.props,
children = _this$props.children,
_this$props$component = _this$props.componentClass,
Component = _this$props$component === void 0 ? getDefaultComponent(children) : _this$props$component,
className = _this$props.className,
props = _objectWithoutPropertiesLoose(_this$props, ["children", "componentClass", "className"]);
var _splitBsProps = splitBsProps(props),
bsProps = _splitBsProps[0],
elementProps = _splitBsProps[1];
var classes = getClassSet(bsProps);
var useListItem = Component === 'ul' && ValidComponentChildren.every(children, function (child) {
return child.type === ListGroupItem;
});
return React.createElement(Component, _extends({}, elementProps, {
className: classNames(className, classes)
}), useListItem ? ValidComponentChildren.map(children, function (child) {
return cloneElement(child, {
listItem: true
});
}) : children);
};
return ListGroup;
}(React.Component);
ListGroup.propTypes = propTypes;
export default bsClass('list-group', ListGroup);