Skip to content

Commit

Permalink
Add close cross for tabs (#58)
Browse files Browse the repository at this point in the history
* Add .DS_Store to gitignore

* Add SVG icon component

* Add button for closing a tab (re: #40)

* Use external icon sheet for icons
  • Loading branch information
johanbrook authored and rauchg committed Jul 6, 2016
1 parent 88501ec commit bfefc2d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ npm-debug.log

# other
.next
.DS_Store
8 changes: 8 additions & 0 deletions app/assets/icons.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/css/hyperterm.css
Expand Up @@ -85,3 +85,10 @@ header {
opacity: 1;
pointer-events: inherit;
}

.icon {
vertical-align: middle;
fill: currentColor;
width: 1em;
height: 1em;
}
53 changes: 49 additions & 4 deletions app/css/tabs.css
Expand Up @@ -32,17 +32,18 @@ nav {
list-style-type: none;
flex-grow: 1;
text-align: center;
position: relative;
}

.tabs li.is_active {
color: #fff;
position: relative;
}

.tabs li span {
transition: color .2s ease;
display: block;
border-left: 1px solid transparent;
border-right: 1px solid transparent;
border-left: 1px solid transparent;
border-right: 1px solid transparent;
}

.tabs li.is_active span {
Expand All @@ -64,10 +65,54 @@ nav {
bottom: -1px;
}

.tabs li:not(.is_active):hover {
.tabs li:not(.is_active):hover span {
color: #ccc;
}

.tabs li.has_activity, .tabs li.has_activity:hover {
color: #50E3C2;
}

/* The close button */

.tabs li i {
transition: opacity .2s ease,
color .2s ease,
transform .25s ease,
background-color .1s ease;
pointer-events: none;
position: absolute;
right: 7px;
top: 7px;
display: inline-block;
width: 14px;
height: 14px;
border-radius: 100%;
color: #e9e9e9;
opacity: 0;
transform: scale(.95);
}

.tabs li:hover i {
opacity: 1;
transform: none;
pointer-events: all;
}

.tabs li i:hover {
background-color: rgba(255,255,255, .13);
color: #fff;
}

.tabs li i:active {
background-color: rgba(255,255,255, .1);
color: #909090;
}

.tabs li i .icon {
position: absolute;
left: 4px;
top: 4px;
width: 6px;
height: 6px;
}
14 changes: 10 additions & 4 deletions app/hyperterm.js
Expand Up @@ -44,6 +44,7 @@ export default class HyperTerm extends Component {
this.focusActive = this.focusActive.bind(this);
this.closeBrowser = this.closeBrowser.bind(this);
this.onHeaderMouseDown = this.onHeaderMouseDown.bind(this);
this.closeTab = this.closeTab.bind(this);

this.moveLeft = this.moveLeft.bind(this);
this.moveRight = this.moveRight.bind(this);
Expand All @@ -64,6 +65,7 @@ export default class HyperTerm extends Component {
return null != title ? title : 'Shell';
})}
onChange={this.onChange}
onClose={this.closeTab}
/>
</header>

Expand Down Expand Up @@ -113,11 +115,15 @@ export default class HyperTerm extends Component {
this.rpc.emit('new', { cols: this.state.cols, rows: this.state.rows });
}

closeTab () {
closeActiveTab () {
this.closeTab(this.state.active);
}

closeTab (id) {
if (this.state.sessions.length) {
const uid = this.state.sessions[this.state.active];
const uid = this.state.sessions[id];
this.rpc.emit('exit', { uid });
this.onSessionExit(uid);
this.onSessionExit({ uid });
}
}

Expand Down Expand Up @@ -226,7 +232,7 @@ export default class HyperTerm extends Component {
});

this.rpc.on('new tab', this.requestTab.bind(this));
this.rpc.on('close tab', this.closeTab.bind(this));
this.rpc.on('close tab', this.closeActiveTab.bind(this));
this.rpc.on('title', this.onRemoteTitle.bind(this));

this.rpc.on('move left', this.moveLeft);
Expand Down
12 changes: 8 additions & 4 deletions app/tabs.js
@@ -1,7 +1,7 @@
import React from 'react';
import classes from 'classnames';

export default function ({ data = [], active, activeMarkers = {}, onChange }) {
export default function ({ data = [], active, activeMarkers = [], onChange, onClose }) {
return <nav style={{ WebkitAppRegion: 'drag' }}>{
data.length
? 1 === data.length
Expand All @@ -13,9 +13,13 @@ export default function ({ data = [], active, activeMarkers = {}, onChange }) {
const hasActivity = ~activeMarkers.indexOf(i);
return <li
key={`tab-${i}`}
className={classes({ is_active: isActive, has_activity: hasActivity })}
onClick={ onChange ? onClick.bind(null, i, onChange, active) : null }>
<span>{ tab }</span>
className={classes({ is_active: isActive, has_activity: hasActivity })}>
<span onClick={ onChange ? onClick.bind(null, i, onChange, active) : null }>{ tab }</span>
<i onClick={ onClose ? onClose.bind(null, i) : null }>
<svg className='icon'>
<use xlinkHref='assets/icons.svg#close'></use>
</svg>
</i>
</li>;
})
}
Expand Down

0 comments on commit bfefc2d

Please sign in to comment.