react-toolbox/components/tabs/tab.jsx

50 lines
1.2 KiB
React
Raw Normal View History

import React from 'react';
2015-09-19 19:48:09 +03:00
import style from './style';
2015-11-13 03:01:27 +03:00
class TabHeader extends React.Component {
static propTypes = {
2015-09-19 19:48:09 +03:00
active: React.PropTypes.bool,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
hidden: React.PropTypes.bool,
2015-11-13 03:01:27 +03:00
label: React.PropTypes.any.isRequired,
2015-09-19 19:48:09 +03:00
onActive: React.PropTypes.func,
2015-11-13 03:01:27 +03:00
onClick: React.PropTypes.func
};
2015-09-19 19:48:09 +03:00
static defaultProps = {
2015-11-13 03:01:27 +03:00
active: false,
className: '',
disabled: false,
hidden: false
};
2015-09-19 19:48:09 +03:00
2015-11-13 17:01:30 +03:00
componentDidUpdate (prevProps) {
if (!prevProps.active && this.props.active && this.props.onActive) {
this.props.onActive();
}
}
2015-11-13 03:01:27 +03:00
handleClick = () => {
if (!this.props.disabled && this.props.onClick) {
this.props.onClick();
}
};
2015-09-19 19:48:09 +03:00
render () {
2015-11-13 03:01:27 +03:00
let className = style.label;
2015-10-11 23:27:59 +03:00
if (this.props.active) className += ` ${style.active}`;
if (this.props.hidden) className += ` ${style.hidden}`;
2015-11-13 03:01:27 +03:00
if (this.props.disabled) className += ` ${style.disabled}`;
if (this.props.className) className += ` ${this.props.className}`;
2015-09-19 19:48:09 +03:00
return (
2015-11-13 03:01:27 +03:00
<label className={className} onClick={this.handleClick}>
{this.props.label}
</label>
2015-09-19 19:48:09 +03:00
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
2015-11-13 03:01:27 +03:00
export default TabHeader;