2023-07-23 11:21:04 -08:00
|
|
|
import React, {forwardRef} from 'react';
|
2016-09-21 06:27:11 -08:00
|
|
|
|
2023-07-25 09:30:19 -08:00
|
|
|
import type {TabsProps} from '../../typings/hyper';
|
2016-09-21 06:27:11 -08:00
|
|
|
import {decorate, getTabProps} from '../utils/plugins';
|
|
|
|
|
|
2023-06-29 20:42:32 -08:00
|
|
|
import DropdownButton from './new-tab';
|
2023-07-25 09:30:19 -08:00
|
|
|
import Tab_ from './tab';
|
2016-07-13 12:44:24 -08:00
|
|
|
|
|
|
|
|
const Tab = decorate(Tab_, 'Tab');
|
2016-09-18 22:47:33 -08:00
|
|
|
const isMac = /Mac/.test(navigator.userAgent);
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2023-07-23 11:21:04 -08:00
|
|
|
const Tabs = forwardRef<HTMLElement, TabsProps>((props, ref) => {
|
2023-07-06 06:40:14 -08:00
|
|
|
const {tabs = [], borderColor, onChange, onClose, fullScreen} = props;
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
const hide = !isMac && tabs.length === 1;
|
2016-11-11 08:18:04 -09:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
return (
|
2023-07-23 11:21:04 -08:00
|
|
|
<nav className={`tabs_nav ${hide ? 'tabs_hiddenNav' : ''}`} ref={ref}>
|
2023-07-06 06:40:14 -08:00
|
|
|
{props.customChildrenBefore}
|
|
|
|
|
{tabs.length === 1 && isMac ? <div className="tabs_title">{tabs[0].title}</div> : null}
|
|
|
|
|
{tabs.length > 1 ? (
|
|
|
|
|
<>
|
|
|
|
|
<ul key="list" className={`tabs_list ${fullScreen && isMac ? 'tabs_fullScreen' : ''}`}>
|
|
|
|
|
{tabs.map((tab, i) => {
|
|
|
|
|
const {uid, title, isActive, hasActivity} = tab;
|
|
|
|
|
const tabProps = getTabProps(tab, props, {
|
|
|
|
|
text: title === '' ? 'Shell' : title,
|
|
|
|
|
isFirst: i === 0,
|
|
|
|
|
isLast: tabs.length - 1 === i,
|
|
|
|
|
borderColor,
|
|
|
|
|
isActive,
|
|
|
|
|
hasActivity,
|
|
|
|
|
onSelect: onChange.bind(null, uid),
|
|
|
|
|
onClose: onClose.bind(null, uid)
|
|
|
|
|
});
|
|
|
|
|
return <Tab key={`tab-${uid}`} {...tabProps} />;
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
{isMac && (
|
|
|
|
|
<div
|
|
|
|
|
key="shim"
|
|
|
|
|
style={{borderColor}}
|
|
|
|
|
className={`tabs_borderShim ${fullScreen ? 'tabs_borderShimUndo' : ''}`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
<DropdownButton {...props} tabsVisible={tabs.length > 1} />
|
|
|
|
|
{props.customChildren}
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
<style jsx>{`
|
|
|
|
|
.tabs_nav {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
height: 34px;
|
|
|
|
|
line-height: 34px;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
color: #9b9b9b;
|
|
|
|
|
cursor: default;
|
|
|
|
|
position: relative;
|
|
|
|
|
-webkit-user-select: none;
|
|
|
|
|
-webkit-app-region: ${isMac ? 'drag' : ''};
|
|
|
|
|
top: ${isMac ? '0px' : '34px'};
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-flow: row;
|
|
|
|
|
}
|
2016-11-11 08:18:04 -09:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
.tabs_hiddenNav {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
.tabs_title {
|
|
|
|
|
text-align: center;
|
|
|
|
|
color: #fff;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
padding-left: 76px;
|
|
|
|
|
padding-right: 76px;
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
.tabs_list {
|
|
|
|
|
max-height: 34px;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-flow: row;
|
|
|
|
|
margin-left: ${isMac ? '76px' : '0'};
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
}
|
2016-09-18 22:47:33 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
.tabs_fullScreen {
|
|
|
|
|
margin-left: -1px;
|
|
|
|
|
}
|
2019-05-08 17:43:50 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
.tabs_borderShim {
|
|
|
|
|
position: absolute;
|
|
|
|
|
width: 76px;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
border-color: #ccc;
|
|
|
|
|
border-bottom-style: solid;
|
|
|
|
|
border-bottom-width: 1px;
|
|
|
|
|
}
|
2019-05-08 17:43:50 -08:00
|
|
|
|
2023-07-06 06:40:14 -08:00
|
|
|
.tabs_borderShimUndo {
|
|
|
|
|
border-bottom-width: 0px;
|
|
|
|
|
}
|
|
|
|
|
`}</style>
|
|
|
|
|
</nav>
|
|
|
|
|
);
|
2023-07-23 11:21:04 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Tabs.displayName = 'Tabs';
|
2023-07-06 06:40:14 -08:00
|
|
|
|
|
|
|
|
export default Tabs;
|