From 24ba56dcd36f3d14f85aaf2137f61669ac63efa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20W=C3=A5land?= Date: Sat, 3 Jun 2017 15:01:10 +0200 Subject: [PATCH 1/3] Add support for badges --- electron-tabs.css | 15 +++++++++++++++ index.js | 24 +++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/electron-tabs.css b/electron-tabs.css index 6cec355..a1a0df4 100644 --- a/electron-tabs.css +++ b/electron-tabs.css @@ -72,6 +72,21 @@ background-color: #aaa; } +.etabs-tab-badge { + position: absolute; + right: 0; + top: -7px; + background: red; + border-radius: 100%; + text-align: center; + font-size: 10px; + padding: 0 5px; +} + +.etabs-tab-badge.hidden { + display: none; +} + .etabs-tab-icon { display: inline-block; height: 16px; diff --git a/index.js b/index.js index 62882b9..7728e3c 100644 --- a/index.js +++ b/index.js @@ -123,6 +123,7 @@ class Tab extends EventEmitter { this.tabGroup = tabGroup; this.id = id; this.title = args.title; + this.badge = args.badge; this.iconURL = args.iconURL; this.icon = args.icon; this.closable = args.closable === false ? false : true; @@ -155,7 +156,27 @@ class Tab extends EventEmitter { if (this.isClosed) return; return this.title; } + + setBadge (badge) { + if (this.isClosed) return; + let span = this.tabElements.badge; + span.innerHTML = badge; + this.badge = badge; + + if (!badge) { + span.classList.add('hidden'); + } else { + span.classList.remove('hidden'); + } + this.emit("badge-changed", badge, this); + } + + getBadge () { + if (this.isClosed) return; + return this.badge; + } + setIcon (iconURL, icon) { if (this.isClosed) return; this.iconURL = iconURL; @@ -248,13 +269,14 @@ const TabPrivate = { // Create tab element let tab = this.tab = document.createElement("div"); tab.classList.add(tabClass); - for (let el of ["icon", "title", "buttons"]) { + for (let el of ["icon", "title", "buttons", "badge"]) { let span = tab.appendChild(document.createElement("span")); span.classList.add(`${tabClass}-${el}`); this.tabElements[el] = span; } this.setTitle(this.title); + this.setBadge(this.badge); this.setIcon(this.iconURL, this.icon); TabPrivate.initTabButtons.bind(this)(); TabPrivate.initTabClickHandler.bind(this)(); From 7b7e9f4640a04f835e60c43a0b058e7a174c2598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20W=C3=A5land?= Date: Sun, 25 Jun 2017 15:29:45 +0200 Subject: [PATCH 2/3] add README for badge --- .idea/misc.xml | 6 ++++++ README.md | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 3ef3e0d..c16bcc8 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Add a new tab to the tab group and returns a `Tab` instance. * `title`: tab title. * `src`: URL to the page which will be loaded into the view. This is actually the same than `options.webview.src`. +* `badge`: optional text to put into a badge, badge will be hidden if it's falsey * `iconURL`: optional URL to the tab icon. * `icon`: optional code for a tab icon. Can be used with symbol libraries (example with Font Awesome: `icon: 'fa fa-icon-name'`). This attribute is ignored if an `iconURL` was given. * `closable` (default: `true`): if set to `true` the close button won't be displayed and the user won't be able to close the tab. See also `tab.close()`. @@ -99,6 +100,14 @@ Set tab title. Get current tab title. +#### `tab.setBadge(badge)` + +Set tab badge. + +#### `tab.getBadge()` + +Get current tab badge. + #### `tab.setIcon (iconURL, icon)` Set tab icon (a iconURL or an icon must be given). From f286bd8d8284d0f3f42d6cf236a6fb89e01f6352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20W=C3=A5land?= Date: Sun, 25 Jun 2017 15:31:21 +0200 Subject: [PATCH 3/3] remove .idea/misc.xml --- .idea/misc.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file