1 | import _Object$values from 'babel-runtime/core-js/object/values';
|
2 | import _extends from 'babel-runtime/helpers/extends';
|
3 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
4 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
5 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
6 | import _inherits from 'babel-runtime/helpers/inherits';
|
7 | import classNames from 'classnames';
|
8 | import React, { cloneElement } from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 |
|
11 | import { bsClass, bsStyles, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils';
|
12 | import { State } from './utils/StyleConfig';
|
13 |
|
14 | var propTypes = {
|
15 | active: PropTypes.any,
|
16 | disabled: PropTypes.any,
|
17 | header: PropTypes.node,
|
18 | listItem: PropTypes.bool,
|
19 | onClick: PropTypes.func,
|
20 | href: PropTypes.string,
|
21 | type: PropTypes.string
|
22 | };
|
23 |
|
24 | var defaultProps = {
|
25 | listItem: false
|
26 | };
|
27 |
|
28 | var ListGroupItem = function (_React$Component) {
|
29 | _inherits(ListGroupItem, _React$Component);
|
30 |
|
31 | function ListGroupItem() {
|
32 | _classCallCheck(this, ListGroupItem);
|
33 |
|
34 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
35 | }
|
36 |
|
37 | ListGroupItem.prototype.renderHeader = function renderHeader(header, headingClassName) {
|
38 | if (React.isValidElement(header)) {
|
39 | return cloneElement(header, {
|
40 | className: classNames(header.props.className, headingClassName)
|
41 | });
|
42 | }
|
43 |
|
44 | return React.createElement(
|
45 | 'h4',
|
46 | { className: headingClassName },
|
47 | header
|
48 | );
|
49 | };
|
50 |
|
51 | ListGroupItem.prototype.render = function render() {
|
52 | var _props = this.props,
|
53 | active = _props.active,
|
54 | disabled = _props.disabled,
|
55 | className = _props.className,
|
56 | header = _props.header,
|
57 | listItem = _props.listItem,
|
58 | children = _props.children,
|
59 | props = _objectWithoutProperties(_props, ['active', 'disabled', 'className', 'header', 'listItem', 'children']);
|
60 |
|
61 | var _splitBsProps = splitBsProps(props),
|
62 | bsProps = _splitBsProps[0],
|
63 | elementProps = _splitBsProps[1];
|
64 |
|
65 | var classes = _extends({}, getClassSet(bsProps), {
|
66 | active: active,
|
67 | disabled: disabled
|
68 | });
|
69 |
|
70 | var Component = void 0;
|
71 |
|
72 | if (elementProps.href) {
|
73 | Component = 'a';
|
74 | } else if (elementProps.onClick) {
|
75 | Component = 'button';
|
76 | elementProps.type = elementProps.type || 'button';
|
77 | } else if (listItem) {
|
78 | Component = 'li';
|
79 | } else {
|
80 | Component = 'span';
|
81 | }
|
82 |
|
83 | elementProps.className = classNames(className, classes);
|
84 |
|
85 |
|
86 | if (header) {
|
87 | return React.createElement(
|
88 | Component,
|
89 | elementProps,
|
90 | this.renderHeader(header, prefix(bsProps, 'heading')),
|
91 | React.createElement(
|
92 | 'p',
|
93 | { className: prefix(bsProps, 'text') },
|
94 | children
|
95 | )
|
96 | );
|
97 | }
|
98 |
|
99 | return React.createElement(
|
100 | Component,
|
101 | elementProps,
|
102 | children
|
103 | );
|
104 | };
|
105 |
|
106 | return ListGroupItem;
|
107 | }(React.Component);
|
108 |
|
109 | ListGroupItem.propTypes = propTypes;
|
110 | ListGroupItem.defaultProps = defaultProps;
|
111 |
|
112 | export default bsClass('list-group-item', bsStyles(_Object$values(State), ListGroupItem)); |
\ | No newline at end of file |