UNPKG

2.21 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
4import _inherits from 'babel-runtime/helpers/inherits';
5import PropTypes from 'prop-types';
6import React from 'react';
7import cn from 'classnames';
8import { prefix, splitBsPropsAndOmit, bsClass } from './utils/bootstrapUtils';
9import PanelCollapse from './PanelCollapse';
10
11var propTypes = {
12 /**
13 * A convenience prop that renders a Collapse component around the Body for
14 * situations when the parent Panel only contains a single Panel.Body child.
15 *
16 * renders:
17 * ```jsx
18 * <Panel.Collapse>
19 * <Panel.Body />
20 * </Panel.Collapse>
21 * ```
22 */
23 collapsible: PropTypes.bool.isRequired
24};
25
26var defaultProps = {
27 collapsible: false
28};
29
30var contextTypes = {
31 $bs_panel: PropTypes.shape({
32 bsClass: PropTypes.string
33 })
34};
35
36var PanelBody = function (_React$Component) {
37 _inherits(PanelBody, _React$Component);
38
39 function PanelBody() {
40 _classCallCheck(this, PanelBody);
41
42 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
43 }
44
45 PanelBody.prototype.render = function render() {
46 var _props = this.props,
47 children = _props.children,
48 className = _props.className,
49 collapsible = _props.collapsible;
50
51 var _ref = this.context.$bs_panel || {},
52 _bsClass = _ref.bsClass;
53
54 var _splitBsPropsAndOmit = splitBsPropsAndOmit(this.props, ['collapsible']),
55 bsProps = _splitBsPropsAndOmit[0],
56 elementProps = _splitBsPropsAndOmit[1];
57
58 bsProps.bsClass = _bsClass || bsProps.bsClass;
59
60 var body = React.createElement(
61 'div',
62 _extends({}, elementProps, { className: cn(className, prefix(bsProps, 'body')) }),
63 children
64 );
65
66 if (collapsible) {
67 body = React.createElement(
68 PanelCollapse,
69 null,
70 body
71 );
72 }
73
74 return body;
75 };
76
77 return PanelBody;
78}(React.Component);
79
80PanelBody.propTypes = propTypes;
81PanelBody.defaultProps = defaultProps;
82PanelBody.contextTypes = contextTypes;
83
84export default bsClass('panel', PanelBody);
\No newline at end of file