@talend/react-bootstrap
Version:
Bootstrap 3 components built with React
79 lines (78 loc) • 2.25 kB
JavaScript
import classNames from 'classnames';
import React, { cloneElement } from 'react';
import PropTypes from 'prop-types';
import { bsClass, bsStyles, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils';
import { State } from './utils/StyleConfig';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const propTypes = {
active: PropTypes.any,
disabled: PropTypes.any,
header: PropTypes.node,
listItem: PropTypes.bool,
onClick: PropTypes.func,
href: PropTypes.string,
type: PropTypes.string
};
const defaultProps = {
listItem: false
};
class ListGroupItem extends React.Component {
renderHeader(header, headingClassName) {
if (/*#__PURE__*/React.isValidElement(header)) {
return /*#__PURE__*/cloneElement(header, {
className: classNames(header.props.className, headingClassName)
});
}
return /*#__PURE__*/_jsx("h4", {
className: headingClassName,
children: header
});
}
render() {
const {
active,
disabled,
className,
header,
listItem,
children,
...props
} = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const classes = {
...getClassSet(bsProps),
active,
disabled
};
let Component;
if (elementProps.href) {
Component = 'a';
} else if (elementProps.onClick) {
Component = 'button';
elementProps.type = elementProps.type || 'button';
} else if (listItem) {
Component = 'li';
} else {
Component = 'span';
}
elementProps.className = classNames(className, classes);
// TODO: Deprecate `header` prop.
if (header) {
return /*#__PURE__*/_jsxs(Component, {
...elementProps,
children: [this.renderHeader(header, prefix(bsProps, 'heading')), /*#__PURE__*/_jsx("p", {
className: prefix(bsProps, 'text'),
children: children
})]
});
}
return /*#__PURE__*/_jsx(Component, {
...elementProps,
children: children
});
}
}
ListGroupItem.propTypes = propTypes;
ListGroupItem.defaultProps = defaultProps;
export default bsClass('list-group-item', bsStyles(Object.values(State), ListGroupItem));
//# sourceMappingURL=ListGroupItem.js.map