tab row styling change

This commit is contained in:
zadam 2019-11-17 10:22:26 +01:00
parent 767aaa18f4
commit c141f4b2c0
4 changed files with 43 additions and 7 deletions

View File

@ -29,6 +29,7 @@ const tabTemplate = `
</div>`; </div>`;
const newTabButtonTemplate = `<div class="note-new-tab" title="Add new tab">+</div>`; const newTabButtonTemplate = `<div class="note-new-tab" title="Add new tab">+</div>`;
const fillerTemplate = `<div class="tab-row-filler"></div>`;
class TabRow { class TabRow {
constructor(el) { constructor(el) {
@ -40,9 +41,10 @@ class TabRow {
this.setupStyleEl(); this.setupStyleEl();
this.setupEvents(); this.setupEvents();
this.layoutTabs();
this.setupDraggabilly(); this.setupDraggabilly();
this.setupNewButton(); this.setupNewButton();
this.setupFiller();
this.layoutTabs();
this.setVisibility(); this.setVisibility();
} }
@ -109,12 +111,17 @@ class TabRow {
const widths = []; const widths = [];
let extraWidthRemaining = totalExtraWidthDueToFlooring; let extraWidthRemaining = totalExtraWidthDueToFlooring;
for (let i = 0; i < numberOfTabs; i += 1) { for (let i = 0; i < numberOfTabs; i += 1) {
const extraWidth = flooredClampedTargetWidth < TAB_CONTENT_MAX_WIDTH && extraWidthRemaining > 0 ? 1 : 0; const extraWidth = flooredClampedTargetWidth < TAB_CONTENT_MAX_WIDTH && extraWidthRemaining > 0 ? 1 : 0;
widths.push(flooredClampedTargetWidth + extraWidth); widths.push(flooredClampedTargetWidth + extraWidth);
if (extraWidthRemaining > 0) extraWidthRemaining -= 1; if (extraWidthRemaining > 0) extraWidthRemaining -= 1;
} }
if (this.fillerEl) {
this.fillerEl.style.width = extraWidthRemaining + "px";
}
return widths; return widths;
} }
@ -129,8 +136,9 @@ class TabRow {
}); });
const newTabPosition = position; const newTabPosition = position;
const fillerPosition = position + 32;
return {tabPositions, newTabPosition}; return {tabPositions, newTabPosition, fillerPosition};
} }
layoutTabs() { layoutTabs() {
@ -151,13 +159,14 @@ class TabRow {
let styleHTML = ''; let styleHTML = '';
const {tabPositions, newTabPosition} = this.getTabPositions(); const {tabPositions, newTabPosition, fillerPosition} = this.getTabPositions();
tabPositions.forEach((position, i) => { tabPositions.forEach((position, i) => {
styleHTML += `.note-tab:nth-child(${ i + 1 }) { transform: translate3d(${ position }px, 0, 0)} `; styleHTML += `.note-tab:nth-child(${ i + 1 }) { transform: translate3d(${ position }px, 0, 0)} `;
}); });
styleHTML += `.note-new-tab { transform: translate3d(${ newTabPosition }px, 0, 0) } `; styleHTML += `.note-new-tab { transform: translate3d(${ newTabPosition }px, 0, 0) } `;
styleHTML += `.tab-row-filler { transform: translate3d(${ fillerPosition }px, 0, 0) } `;
this.styleEl.innerHTML = styleHTML; this.styleEl.innerHTML = styleHTML;
} }
@ -387,11 +396,18 @@ class TabRow {
this.newTabEl = div.firstElementChild; this.newTabEl = div.firstElementChild;
this.tabContentEl.appendChild(this.newTabEl); this.tabContentEl.appendChild(this.newTabEl);
this.layoutTabs();
this.newTabEl.addEventListener('click', _ => this.emit('newTab')); this.newTabEl.addEventListener('click', _ => this.emit('newTab'));
} }
setupFiller() {
const div = document.createElement('div');
div.innerHTML = fillerTemplate;
this.fillerEl = div.firstElementChild;
this.tabContentEl.appendChild(this.fillerEl);
}
closest(value, array) { closest(value, array) {
let closest = Infinity; let closest = Infinity;
let closestIndex = -1; let closestIndex = -1;

View File

@ -368,7 +368,7 @@ async function treeInitialized() {
const notePath = location.hash.substr(1); const notePath = location.hash.substr(1);
const noteId = treeUtils.getNoteIdFromNotePath(notePath); const noteId = treeUtils.getNoteIdFromNotePath(notePath);
if (await treeCache.noteExists(noteId)) { if (noteId && await treeCache.noteExists(noteId)) {
for (const tab of openTabs) { for (const tab of openTabs) {
tab.active = false; tab.active = false;
} }

View File

@ -144,7 +144,7 @@ class TreeCache {
else { else {
return this.notes[noteId]; return this.notes[noteId];
} }
}).filter(note => note !== null); }).filter(note => !!note);
} }
/** @return {Promise<boolean>} */ /** @return {Promise<boolean>} */

View File

@ -68,6 +68,11 @@ body {
margin-bottom: 2px; margin-bottom: 2px;
margin-top: 2px; margin-top: 2px;
margin-right: 8px; margin-right: 8px;
border-color: transparent !important;
}
#header button:hover {
border-color: var(--button-border-color) !important;
} }
#history-navigation { #history-navigation {
@ -215,7 +220,7 @@ body {
.note-new-tab { .note-new-tab {
position: absolute; position: absolute;
left: 0; left: 0;
height: 32px; height: 33px;
width: 32px; width: 32px;
border: 0; border: 0;
margin: 0; margin: 0;
@ -223,6 +228,7 @@ body {
text-align: center; text-align: center;
font-size: 24px; font-size: 24px;
cursor: pointer; cursor: pointer;
border-bottom: 1px solid var(--button-border-color);
} }
.note-new-tab:hover { .note-new-tab:hover {
@ -230,6 +236,14 @@ body {
border-radius: 5px; border-radius: 5px;
} }
.tab-row-filler {
position: absolute;
left: 0;
background: linear-gradient(to right, var(--button-border-color), transparent);
height: 1px;
margin-top: 32px;
}
.note-tab-row .note-tab[active] { .note-tab-row .note-tab[active] {
z-index: 5; z-index: 5;
} }
@ -244,6 +258,7 @@ body {
top: 10px; top: 10px;
animation: note-tab-was-just-added 120ms forwards ease-in-out; animation: note-tab-was-just-added 120ms forwards ease-in-out;
} }
.note-tab-row .note-tab .note-tab-wrapper { .note-tab-row .note-tab .note-tab-wrapper {
position: absolute; position: absolute;
display: flex; display: flex;
@ -271,6 +286,7 @@ body {
padding-left: 2px; padding-left: 2px;
padding-right: 2px; padding-right: 2px;
} }
.note-tab-row .note-tab .note-tab-title { .note-tab-row .note-tab .note-tab-title {
flex: 1; flex: 1;
vertical-align: top; vertical-align: top;
@ -278,12 +294,15 @@ body {
white-space: nowrap; white-space: nowrap;
color: var(--muted-text-color); color: var(--muted-text-color);
} }
.note-tab-row .note-tab[is-small] .note-tab-title { .note-tab-row .note-tab[is-small] .note-tab-title {
margin-left: 0; margin-left: 0;
} }
.note-tab-row .note-tab[active] .note-tab-title { .note-tab-row .note-tab[active] .note-tab-title {
color: var(--main-text-color); color: var(--main-text-color);
} }
.note-tab-row .note-tab .note-tab-drag-handle { .note-tab-row .note-tab .note-tab-drag-handle {
position: absolute; position: absolute;
top: 0; top: 0;
@ -293,6 +312,7 @@ body {
border-top-left-radius: 8px; border-top-left-radius: 8px;
border-top-right-radius: 8px; border-top-right-radius: 8px;
} }
.note-tab-row .note-tab .note-tab-close { .note-tab-row .note-tab .note-tab-close {
flex-grow: 0; flex-grow: 0;
flex-shrink: 0; flex-shrink: 0;