react-toolbox/components/tabs/tab.jsx

57 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';
export default React.createClass({
displayName: 'Tab',
propTypes: {
active: React.PropTypes.bool,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
hidden: React.PropTypes.bool,
label: React.PropTypes.string.isRequired,
onActive: React.PropTypes.func,
tabIndex: React.PropTypes.number
},
getDefaultProps () {
return {
className: ''
};
},
componentDidMount () {
this.active(this.props.active);
},
componentWillReceiveProps (next_props) {
if (next_props.active) this.active(next_props.active);
},
render () {
let className = `${style.tab} ${this.props.className}`;
2015-10-11 23:27:59 +03:00
if (this.props.active) className += ` ${style.active}`;
if (this.props.disabled) className += ` ${style.disabled}`;
if (this.props.hidden) className += ` ${style.hidden}`;
2015-09-19 19:48:09 +03:00
return (
<section
data-react-toolbox='tab'
className={className}
data-flex='vertical'
tabIndex={this.props.tabIndex}
>
{ this.props.children }
</section>
);
},
active (value) {
this.setState({active: value});
if (this.props.onActive && value) {
this.props.onActive(this);
}
}
});