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';
|
2016-08-25 11:14:29 +03:00
|
|
|
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 {
|
2015-10-20 08:40:51 +03:00
|
|
|
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,
|
2016-08-25 11:14:29 +03:00
|
|
|
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-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-19 19:48:09 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
2015-11-13 03:01:27 +03:00
|
|
|
active: false,
|
|
|
|
className: '',
|
|
|
|
disabled: false,
|
|
|
|
hidden: false
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
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
|
|
|
|
|
|
|
render () {
|
2016-08-06 23:44:05 +03:00
|
|
|
const {
|
|
|
|
onActive, // eslint-disable-line
|
2016-09-03 12:48:05 +03:00
|
|
|
active, activeClassName, className, disabled, hidden, label, icon, theme, ...other
|
2016-08-06 23:44:05 +03:00
|
|
|
} = this.props;
|
2016-05-26 22:01:54 +03:00
|
|
|
const _className = classnames(theme.label, {
|
|
|
|
[theme.active]: active,
|
|
|
|
[theme.hidden]: hidden,
|
2016-09-03 12:48:05 +03:00
|
|
|
[theme.withText]: label,
|
|
|
|
[theme.withIcon]: icon,
|
2016-05-26 22:01:54 +03:00
|
|
|
[theme.disabled]: disabled,
|
|
|
|
[activeClassName]: active
|
|
|
|
}, className);
|
2015-09-19 19:48:09 +03:00
|
|
|
|
|
|
|
return (
|
2016-08-06 23:44:05 +03:00
|
|
|
<label {...other} data-react-toolbox='tab' className={_className} onClick={this.handleClick}>
|
2016-09-03 12:48:05 +03:00
|
|
|
{icon && <FontIcon className={theme.icon} value={icon}/>}
|
|
|
|
{label}
|
2015-11-13 03:01:27 +03:00
|
|
|
</label>
|
2015-09-19 19:48:09 +03:00
|
|
|
);
|
2015-10-20 08:40:51 +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 };
|