UNPKG

2.46 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';
7
8import { prefix, splitBsProps, bsClass } from './utils/bootstrapUtils';
9import Collapse from './Collapse';
10
11var propTypes = {
12 /**
13 * Callback fired before the component expands
14 */
15 onEnter: PropTypes.func,
16 /**
17 * Callback fired after the component starts to expand
18 */
19 onEntering: PropTypes.func,
20 /**
21 * Callback fired after the component has expanded
22 */
23 onEntered: PropTypes.func,
24 /**
25 * Callback fired before the component collapses
26 */
27 onExit: PropTypes.func,
28 /**
29 * Callback fired after the component starts to collapse
30 */
31 onExiting: PropTypes.func,
32 /**
33 * Callback fired after the component has collapsed
34 */
35 onExited: PropTypes.func
36};
37
38var contextTypes = {
39 $bs_panel: PropTypes.shape({
40 headingId: PropTypes.string,
41 bodyId: PropTypes.string,
42 bsClass: PropTypes.string,
43 expanded: PropTypes.bool
44 })
45};
46
47var PanelCollapse = function (_React$Component) {
48 _inherits(PanelCollapse, _React$Component);
49
50 function PanelCollapse() {
51 _classCallCheck(this, PanelCollapse);
52
53 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
54 }
55
56 PanelCollapse.prototype.render = function render() {
57 var children = this.props.children;
58
59 var _ref = this.context.$bs_panel || {},
60 headingId = _ref.headingId,
61 bodyId = _ref.bodyId,
62 _bsClass = _ref.bsClass,
63 expanded = _ref.expanded;
64
65 var _splitBsProps = splitBsProps(this.props),
66 bsProps = _splitBsProps[0],
67 props = _splitBsProps[1];
68
69 bsProps.bsClass = _bsClass || bsProps.bsClass;
70
71 if (headingId && bodyId) {
72 props.id = bodyId;
73 props.role = props.role || 'tabpanel';
74 props['aria-labelledby'] = headingId;
75 }
76
77 return React.createElement(
78 Collapse,
79 _extends({ 'in': expanded }, props),
80 React.createElement(
81 'div',
82 { className: prefix(bsProps, 'collapse') },
83 children
84 )
85 );
86 };
87
88 return PanelCollapse;
89}(React.Component);
90
91PanelCollapse.propTypes = propTypes;
92PanelCollapse.contextTypes = contextTypes;
93
94export default bsClass('panel', PanelCollapse);
\No newline at end of file