UNPKG

2.16 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 PropTypes from 'prop-types';
7import React from 'react';
8import cn from 'classnames';
9import elementType from 'react-prop-types/lib/elementType';
10
11import { prefix, bsClass, splitBsProps } from './utils/bootstrapUtils';
12
13var propTypes = {
14 componentClass: elementType
15};
16
17var defaultProps = {
18 componentClass: 'div'
19};
20
21var contextTypes = {
22 $bs_panel: PropTypes.shape({
23 headingId: PropTypes.string,
24 bsClass: PropTypes.string
25 })
26};
27
28var PanelHeading = function (_React$Component) {
29 _inherits(PanelHeading, _React$Component);
30
31 function PanelHeading() {
32 _classCallCheck(this, PanelHeading);
33
34 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
35 }
36
37 PanelHeading.prototype.render = function render() {
38 var _props = this.props,
39 children = _props.children,
40 className = _props.className,
41 Component = _props.componentClass,
42 props = _objectWithoutProperties(_props, ['children', 'className', 'componentClass']);
43
44 var _ref = this.context.$bs_panel || {},
45 headingId = _ref.headingId,
46 _bsClass = _ref.bsClass;
47
48 var _splitBsProps = splitBsProps(props),
49 bsProps = _splitBsProps[0],
50 elementProps = _splitBsProps[1];
51
52 bsProps.bsClass = _bsClass || bsProps.bsClass;
53
54 if (headingId) {
55 elementProps.role = elementProps.role || 'tab';
56 elementProps.id = headingId;
57 }
58
59 return React.createElement(
60 Component,
61 _extends({}, elementProps, {
62 className: cn(className, prefix(bsProps, 'heading'))
63 }),
64 children
65 );
66 };
67
68 return PanelHeading;
69}(React.Component);
70
71PanelHeading.propTypes = propTypes;
72PanelHeading.defaultProps = defaultProps;
73PanelHeading.contextTypes = contextTypes;
74
75export default bsClass('panel', PanelHeading);
\No newline at end of file