2016-07-13 12:44:24 -08:00
|
|
|
import React from 'react';
|
2017-09-16 11:17:22 -08:00
|
|
|
import {PureComponent} from '../base-components';
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2017-09-16 11:17:22 -08:00
|
|
|
export default class Tab extends PureComponent {
|
2016-09-21 06:27:11 -08:00
|
|
|
constructor() {
|
2016-07-13 12:44:24 -08:00
|
|
|
super();
|
2016-09-21 06:27:11 -08:00
|
|
|
|
|
|
|
|
this.handleHover = this.handleHover.bind(this);
|
|
|
|
|
this.handleBlur = this.handleBlur.bind(this);
|
2016-07-21 16:33:10 -08:00
|
|
|
this.handleClick = this.handleClick.bind(this);
|
2016-09-21 06:27:11 -08:00
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
this.state = {
|
|
|
|
|
hovered: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
shouldComponentUpdate() {
|
|
|
|
|
return true;
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
handleHover() {
|
|
|
|
|
this.setState({
|
|
|
|
|
hovered: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleBlur() {
|
|
|
|
|
this.setState({
|
|
|
|
|
hovered: false
|
|
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
handleClick(event) {
|
2016-07-21 16:33:10 -08:00
|
|
|
const isLeftClick = event.nativeEvent.which === 1;
|
|
|
|
|
const isMiddleClick = event.nativeEvent.which === 2;
|
|
|
|
|
|
2016-09-21 10:44:47 -08:00
|
|
|
if (isLeftClick && !this.props.isActive) {
|
|
|
|
|
this.props.onSelect();
|
2016-07-21 16:33:10 -08:00
|
|
|
} else if (isMiddleClick) {
|
|
|
|
|
this.props.onClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
template(css) {
|
|
|
|
|
const {isActive, isFirst, isLast, borderColor, hasActivity} = this.props;
|
|
|
|
|
const {hovered} = this.state;
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2017-09-10 05:35:10 -08:00
|
|
|
return (
|
|
|
|
|
<li
|
|
|
|
|
onMouseEnter={this.handleHover}
|
|
|
|
|
onMouseLeave={this.handleBlur}
|
|
|
|
|
onClick={this.props.onClick}
|
|
|
|
|
style={{borderColor}}
|
2016-09-21 06:27:11 -08:00
|
|
|
className={css(
|
2017-09-10 05:35:10 -08:00
|
|
|
'tab',
|
|
|
|
|
isFirst && 'first',
|
|
|
|
|
isActive && 'active',
|
|
|
|
|
isFirst && isActive && 'firstActive',
|
|
|
|
|
hasActivity && 'hasActivity'
|
2016-09-21 06:27:11 -08:00
|
|
|
)}
|
2017-09-10 05:35:10 -08:00
|
|
|
>
|
|
|
|
|
{this.props.customChildrenBefore}
|
|
|
|
|
<span className={css('text', isLast && 'textLast', isActive && 'textActive')} onClick={this.handleClick}>
|
|
|
|
|
<span title={this.props.text} className={css('textInner')}>
|
|
|
|
|
{this.props.text}
|
|
|
|
|
</span>
|
2016-07-13 12:44:24 -08:00
|
|
|
</span>
|
2017-09-10 05:35:10 -08:00
|
|
|
<i className={css('icon', hovered && 'iconHovered')} onClick={this.props.onClose}>
|
|
|
|
|
<svg className={css('shape')}>
|
|
|
|
|
<use xlinkHref="./renderer/assets/icons.svg#close-tab" />
|
|
|
|
|
</svg>
|
|
|
|
|
</i>
|
|
|
|
|
{this.props.customChildren}
|
|
|
|
|
</li>
|
|
|
|
|
);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
styles() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return {
|
|
|
|
|
tab: {
|
|
|
|
|
color: '#ccc',
|
2016-09-18 22:47:33 -08:00
|
|
|
borderColor: '#ccc',
|
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
|
borderBottomStyle: 'solid',
|
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
|
borderLeftStyle: 'solid',
|
2016-07-13 12:44:24 -08:00
|
|
|
listStyleType: 'none',
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
position: 'relative',
|
|
|
|
|
':hover': {
|
|
|
|
|
color: '#ccc'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
first: {
|
2016-09-18 22:47:33 -08:00
|
|
|
borderLeftWidth: 0,
|
|
|
|
|
paddingLeft: 1
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
firstActive: {
|
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
|
paddingLeft: 0
|
2016-07-13 12:44:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
active: {
|
|
|
|
|
color: '#fff',
|
2016-09-18 22:47:33 -08:00
|
|
|
borderBottomWidth: 0,
|
2016-07-13 12:44:24 -08:00
|
|
|
':hover': {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
hasActivity: {
|
|
|
|
|
color: '#50E3C2',
|
|
|
|
|
':hover': {
|
|
|
|
|
color: '#50E3C2'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
text: {
|
|
|
|
|
transition: 'color .2s ease',
|
|
|
|
|
height: '34px',
|
|
|
|
|
display: 'block',
|
|
|
|
|
width: '100%',
|
|
|
|
|
position: 'relative',
|
|
|
|
|
overflow: 'hidden'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
textInner: {
|
|
|
|
|
position: 'absolute',
|
2017-02-17 10:48:56 -09:00
|
|
|
left: '24px',
|
|
|
|
|
right: '24px',
|
2016-07-13 12:44:24 -08:00
|
|
|
top: 0,
|
|
|
|
|
bottom: 0,
|
2017-02-16 09:41:04 -09:00
|
|
|
textAlign: 'center',
|
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
overflow: 'hidden'
|
2016-07-13 12:44:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
icon: {
|
|
|
|
|
transition: `opacity .2s ease, color .2s ease,
|
|
|
|
|
transform .25s ease, background-color .1s ease`,
|
|
|
|
|
pointerEvents: 'none',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
right: '7px',
|
|
|
|
|
top: '10px',
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
width: '14px',
|
|
|
|
|
height: '14px',
|
|
|
|
|
borderRadius: '100%',
|
|
|
|
|
color: '#e9e9e9',
|
|
|
|
|
opacity: 0,
|
|
|
|
|
transform: 'scale(.95)',
|
|
|
|
|
|
|
|
|
|
':hover': {
|
|
|
|
|
backgroundColor: 'rgba(255,255,255, .13)',
|
|
|
|
|
color: '#fff'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
':active': {
|
|
|
|
|
backgroundColor: 'rgba(255,255,255, .1)',
|
|
|
|
|
color: '#909090'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
iconHovered: {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
transform: 'none',
|
|
|
|
|
pointerEvents: 'all'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
shape: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
left: '4px',
|
|
|
|
|
top: '4px',
|
|
|
|
|
width: '6px',
|
|
|
|
|
height: '6px',
|
|
|
|
|
verticalAlign: 'middle',
|
2016-11-11 08:18:04 -09:00
|
|
|
fill: 'currentColor',
|
|
|
|
|
shapeRendering: 'crispEdges'
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|