-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabPanel.js
More file actions
71 lines (58 loc) · 1.67 KB
/
TabPanel.js
File metadata and controls
71 lines (58 loc) · 1.67 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import TabIcon from './TabIcon';
import CamelCase from 'lodash/camelCase';
/**
* Tabs sub-component responsible for rendering individual tab content panels
* @param {Object} props
* @returns {JSX}
*/
class TabPanel extends Component {
constructor(props) {
super();
this.props = props;
this.panel = null;
}
setHeight() {
if ( !this.props.isVert) {
return;
}
if (!this.panel && this.props.selected === this.props.index) {
return 'none';
}
return this.props.selected === this.props.index
? this.panel.scrollHeight
: 0;
}
render() {
const isSelected = this.props.selected === this.props.index
const panelClassName = isSelected
? 'tabs__panel tabs__panel--isActive'
: 'tabs__panel';
const panelID = CamelCase(this.props.label);
return (
<div
className={panelClassName}
id={panelID}
role="tabpanel"
ref={panel => this.panel = panel}
style={{ maxHeight: this.setHeight() }}
tabindex={isSelected ? 0 : -1}
aria-hidden={!isSelected}
>
<div className="tabs__panelContent">
{this.props.children}
</div>
</div>
);
}
};
TabPanel.propTypes = {
children: PropTypes.node.isRequired,
icon: PropTypes.object,
label: PropTypes.string.isRequired,
};
TabPanel.defaultProps = {
icon: <TabIcon/>,
}
export default TabPanel;