UNPKG

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