react-toolbox/components/tabs/Tab.js

73 lines
1.9 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,
2017-01-10 21:14:55 +03:00
index: PropTypes.number,
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,
2016-12-19 22:39:07 +03:00
label: PropTypes.string,
withIcon: PropTypes.string,
withText: 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) {
2017-01-10 21:14:55 +03:00
this.props.onClick(event, this.props.index);
2015-11-13 03:01:27 +03:00
}
};
2015-09-19 19:48:09 +03:00
render () {
const {
2017-01-10 21:14:55 +03:00
index, onActive, // eslint-disable-line
2016-09-03 12:48:05 +03:00
active, activeClassName, className, disabled, hidden, label, icon, theme, ...other
} = 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 (
<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-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 };