react-toolbox/components/tabs/Tab.js

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-05-31 00:23:55 +03:00
import React, { Component, PropTypes } from 'react';
2016-05-26 22:01:54 +03:00
import classnames from 'classnames';
import { FontIcon } from '../font_icon';
2016-05-26 22:01:54 +03:00
import { themr } from 'react-css-themr';
2016-05-31 00:23:55 +03:00
import { TABS } from '../identifiers.js';
2015-09-19 19:48:09 +03:00
2016-05-31 00:23:55 +03:00
class Tab extends Component {
static propTypes = {
2016-05-31 00:23:55 +03:00
active: PropTypes.bool,
activeClassName: PropTypes.string,
className: PropTypes.string,
disabled: PropTypes.bool,
hidden: PropTypes.bool,
icon: PropTypes.node,
label: PropTypes.node,
2016-05-31 00:23:55 +03:00
onActive: PropTypes.func,
onClick: PropTypes.func,
theme: PropTypes.shape({
active: PropTypes.string,
disabled: PropTypes.string,
hidden: PropTypes.string,
label: PropTypes.string
2016-05-26 22:01:54 +03:00
})
};
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();
}
}
2016-01-22 16:49:06 +03:00
handleClick = (event) => {
2015-11-13 03:01:27 +03:00
if (!this.props.disabled && this.props.onClick) {
2016-01-22 16:49:06 +03:00
this.props.onClick(event);
2015-11-13 03:01:27 +03:00
}
};
2015-09-19 19:48:09 +03:00
renderIcon = () => {
if (!this.props.icon) {
return null;
} else {
return (
<div>
<FontIcon value={this.props.icon}/>
</div>
);
}
};
2015-09-19 19:48:09 +03:00
render () {
const {
onActive, // eslint-disable-line
active, activeClassName, className, disabled, hidden, theme, ...other
} = this.props;
2016-05-26 22:01:54 +03:00
const _className = classnames(theme.label, {
[theme.active]: active,
[theme.hidden]: hidden,
[theme.disabled]: disabled,
[activeClassName]: active
}, className);
2015-09-19 19:48:09 +03:00
return (
<label {...other} data-react-toolbox='tab' className={_className} onClick={this.handleClick}>
{this.renderIcon()}
2015-11-13 03:01:27 +03:00
{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
2016-05-31 00:23:55 +03:00
export default themr(TABS)(Tab);
export { Tab };