hyper/lib/components/tabs.js

101 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-07-13 12:44:24 -08:00
import React from 'react';
2016-07-13 12:44:24 -08:00
import Component from '../component';
import {decorate, getTabProps} from '../utils/plugins';
import Tab_ from './tab';
2016-07-13 12:44:24 -08:00
const Tab = decorate(Tab_, 'Tab');
const isMac = /Mac/.test(navigator.userAgent);
2016-07-13 12:44:24 -08:00
export default class Tabs extends Component {
template(css) {
2016-07-13 12:44:24 -08:00
const {
tabs = [],
borderColor,
onChange,
onClose
} = this.props;
return (<nav className={css('nav')}>
{ this.props.customChildrenBefore }
2016-07-13 12:44:24 -08:00
{
tabs.length ?
tabs.length === 1 ?
<div className={css('title')}>{tabs[0].title}</div> :
[
<ul
className={css('list')}
>
2016-07-13 12:44:24 -08:00
{
tabs.map((tab, i) => {
const {uid, title, isActive, hasActivity} = tab;
2016-07-13 12:44:24 -08:00
const props = getTabProps(tab, this.props, {
text: title === '' ? 'Shell' : title,
isFirst: i === 0,
2016-07-13 12:44:24 -08:00
isLast: tabs.length - 1 === i,
borderColor,
2016-07-13 12:44:24 -08:00
isActive,
hasActivity,
onSelect: onChange.bind(null, uid),
onClose: onClose.bind(null, uid)
});
return <Tab key={`tab-${uid}`} {...props}/>;
2016-07-13 12:44:24 -08:00
})
}
</ul>,
isMac && <div
style={{borderColor}}
className={css('borderShim')}
/>
] :
null
2016-07-13 12:44:24 -08:00
}
{ this.props.customChildren }
</nav>);
2016-07-13 12:44:24 -08:00
}
styles() {
2016-07-13 12:44:24 -08:00
return {
nav: {
fontSize: '12px',
fontFamily: `-apple-system, BlinkMacSystemFont,
"Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans",
"Droid Sans", "Helvetica Neue", sans-serif`,
height: '34px',
lineHeight: '34px',
verticalAlign: 'middle',
color: '#9B9B9B',
cursor: 'default',
position: 'relative',
2016-07-13 12:44:24 -08:00
WebkitUserSelect: 'none',
WebkitAppRegion: 'drag'
},
title: {
textAlign: 'center',
color: '#fff'
},
list: {
maxHeight: '34px',
display: 'flex',
flexFlow: 'row',
marginLeft: isMac ? 76 : 0
},
borderShim: {
position: 'absolute',
width: '76px',
bottom: 0,
borderColor: '#ccc',
borderBottomStyle: 'solid',
borderBottomWidth: '1px'
2016-07-13 12:44:24 -08:00
}
};
}
}