forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelHeading.js
More file actions
54 lines (42 loc) · 1.27 KB
/
PanelHeading.js
File metadata and controls
54 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { PropTypes, cloneElement } from 'react';
import cn from 'classnames';
import elementType from 'react-prop-types/lib/elementType';
import { prefix, bsClass, splitBsProps } from './utils/bootstrapUtils';
const propTypes = {
componentClass: elementType,
bsRole: PropTypes.string,
};
const defaultProps = {
bsRole: 'heading',
componentClass: 'div',
};
const contextTypes = {
$bs_panel: PropTypes.shape({
getIds: React.PropTypes.func,
bsClass: PropTypes.string
})
};
class PanelHeading extends React.Component {
render() {
const { children, className, componentClass: Component, ...props } = this.props;
const { getIds, bsClass: _bsClass } = this.context.$bs_panel || {};
const [bsProps, elementProps] = splitBsProps(props);
bsProps.bsClass = _bsClass || bsProps.bsClass;
if (getIds) {
elementProps.role = elementProps.role || 'tab';
elementProps.id = getIds().headingId;
}
return (
<Component
{...elementProps}
className={cn(className, prefix(bsProps, 'heading'))}
>
{children}
</Component>
);
}
}
PanelHeading.propTypes = propTypes;
PanelHeading.defaultProps = defaultProps;
PanelHeading.contextTypes = contextTypes;
export default bsClass('panel', PanelHeading);