UNPKG

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