Skip to content

Commit 1bd89a8

Browse files
committed
Added support for badges in TabBar icons.
Added support for TabBar icon badges using the attribute badge in the tab directive. Ex: <tab icon-on="icon ion-ios7-person" icon-off="icon ion-ios7-person-outline" href="#/tab/myprofile" badge="3"> I’ve used the colors of the TabBar itself but inverted for the badge. I don’t know if you’ll want to merge this straight on but I think it can help as a start point for this feature. I’ve tried to do it as integrated as possible.
1 parent 8b44004 commit 1bd89a8

File tree

9 files changed

+97
-10
lines changed

9 files changed

+97
-10
lines changed

dist/css/ionic.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,51 +3489,81 @@ a.subdued {
34893489
border-top-width: 1px;
34903490
background-size: 0;
34913491
line-height: 49px; }
3492+
.tabs .tab-item .icon.badge {
3493+
background-color: #444444;
3494+
color: #f8f8f8; }
34923495
.tabs.tabs-light {
34933496
background-color: white;
34943497
background-image: linear-gradient(0deg, #dddddd, #dddddd 50%, transparent 50%);
34953498
border-color: #dddddd;
34963499
color: #444444; }
3500+
.tabs.tabs-light .tab-item .icon.badge {
3501+
background-color: #444444;
3502+
color: white; }
34973503
.tabs.tabs-stable {
34983504
background-color: #f8f8f8;
34993505
background-image: linear-gradient(0deg, #b2b2b2, #b2b2b2 50%, transparent 50%);
35003506
border-color: #b2b2b2;
35013507
color: #444444; }
3508+
.tabs.tabs-stable .tab-item .icon.badge {
3509+
background-color: #444444;
3510+
color: #f8f8f8; }
35023511
.tabs.tabs-positive {
35033512
background-color: #4a87ee;
35043513
background-image: linear-gradient(0deg, #145dd7, #145dd7 50%, transparent 50%);
35053514
border-color: #145dd7;
35063515
color: white; }
3516+
.tabs.tabs-positive .tab-item .icon.badge {
3517+
background-color: white;
3518+
color: #4a87ee; }
35073519
.tabs.tabs-calm {
35083520
background-color: #43cee6;
35093521
background-image: linear-gradient(0deg, #1aaac3, #1aaac3 50%, transparent 50%);
35103522
border-color: #1aaac3;
35113523
color: white; }
3524+
.tabs.tabs-calm .tab-item .icon.badge {
3525+
background-color: white;
3526+
color: #43cee6; }
35123527
.tabs.tabs-assertive {
35133528
background-color: #ef4e3a;
35143529
background-image: linear-gradient(0deg, #cc2511, #cc2511 50%, transparent 50%);
35153530
border-color: #cc2511;
35163531
color: white; }
3532+
.tabs.tabs-assertive .tab-item .icon.badge {
3533+
background-color: white;
3534+
color: #ef4e3a; }
35173535
.tabs.tabs-balanced {
35183536
background-color: #66cc33;
35193537
background-image: linear-gradient(0deg, #478f24, #478f24 50%, transparent 50%);
35203538
border-color: #478f24;
35213539
color: white; }
3540+
.tabs.tabs-balanced .tab-item .icon.badge {
3541+
background-color: white;
3542+
color: #66cc33; }
35223543
.tabs.tabs-energized {
35233544
background-color: #f0b840;
35243545
background-image: linear-gradient(0deg, #d39511, #d39511 50%, transparent 50%);
35253546
border-color: #d39511;
35263547
color: white; }
3548+
.tabs.tabs-energized .tab-item .icon.badge {
3549+
background-color: white;
3550+
color: #f0b840; }
35273551
.tabs.tabs-royal {
35283552
background-color: #8a6de9;
35293553
background-image: linear-gradient(0deg, #552bdf, #552bdf 50%, transparent 50%);
35303554
border-color: #552bdf;
35313555
color: white; }
3556+
.tabs.tabs-royal .tab-item .icon.badge {
3557+
background-color: white;
3558+
color: #8a6de9; }
35323559
.tabs.tabs-dark {
35333560
background-color: #444444;
35343561
background-image: linear-gradient(0deg, #111111, #111111 50%, transparent 50%);
35353562
border-color: #111111;
35363563
color: white; }
3564+
.tabs.tabs-dark .tab-item .icon.badge {
3565+
background-color: white;
3566+
color: #444444; }
35373567
@media (min--moz-device-pixel-ratio: 1.5), (-webkit-min-device-pixel-ratio: 1.5), (min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) {
35383568
.tabs {
35393569
padding-top: 2px;
@@ -3600,6 +3630,16 @@ a.subdued {
36003630
.tabs-icon-only .icon:before {
36013631
line-height: inherit; }
36023632

3633+
.tab-item.has-badge {
3634+
position: relative; }
3635+
3636+
.tab-item .icon.badge {
3637+
position: absolute;
3638+
padding: 2px 6px;
3639+
top: 2%;
3640+
right: 10%;
3641+
font-size: 12px; }
3642+
36033643
/* Navigational tab */
36043644
/* Active state for tab */
36053645
.tab-item.active,

dist/css/ionic.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/ionic-angular.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
23602360
$scope.icon = $attr.icon;
23612361
$scope.iconOn = $attr.iconOn;
23622362
$scope.iconOff = $attr.iconOff;
2363+
$scope.badge = $attr.badge;
23632364
$scope.viewSref = $attr.uiSref;
23642365
$scope.url = $attr.href;
23652366
if($scope.url && $scope.url.indexOf('#') === 0) {
@@ -2449,7 +2450,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
24492450
replace: true,
24502451
scope: true,
24512452
template: '<div class="tabs">' +
2452-
'<tab-controller-item icon-title="{{c.title}}" icon="{{c.icon}}" icon-on="{{c.iconOn}}" icon-off="{{c.iconOff}}" active="c.isVisible" index="$index" ng-repeat="c in controllers"></tab-controller-item>' +
2453+
'<tab-controller-item icon-title="{{c.title}}" icon="{{c.icon}}" icon-on="{{c.iconOn}}" icon-off="{{c.iconOff}}" badge="{{c.badge}}" active="c.isVisible" index="$index" ng-repeat="c in controllers"></tab-controller-item>' +
24532454
'</div>',
24542455
link: function($scope, $element, $attr, tabsCtrl) {
24552456
$element.addClass($scope.tabsType);
@@ -2468,6 +2469,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
24682469
icon: '@',
24692470
iconOn: '@',
24702471
iconOff: '@',
2472+
badge: '@',
24712473
active: '=',
24722474
tabSelected: '@',
24732475
index: '='
@@ -2482,7 +2484,8 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
24822484
};
24832485
},
24842486
template:
2485-
'<a ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' +
2487+
'<a ng-class="{active:active, \'has-badge\':badge}" ng-click="selectTab()" class="tab-item">' +
2488+
'<i class="icon badge" ng-if="badge">{{badge}}</i>' +
24862489
'<i class="icon {{icon}}" ng-if="icon"></i>' +
24872490
'<i class="{{iconOn}}" ng-if="active"></i>' +
24882491
'<i class="{{iconOff}}" ng-if="!active"></i> {{iconTitle}}' +
@@ -2756,6 +2759,10 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
27562759
updateHeaderData(data);
27572760
});
27582761

2762+
$rootScope.$on('viewState.titleUpdated', function(e, data) {
2763+
$scope.currentTitle = (data && data.title ? data.title : '');
2764+
});
2765+
27592766
// If a nav page changes the left or right buttons, update our scope vars
27602767
$scope.$parent.$on('viewState.leftButtonsChanged', function(e, data) {
27612768
$scope.leftButtons = data;
@@ -2817,10 +2824,16 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
28172824
$scope.$emit('viewState.rightButtonsChanged', $scope.rightButtons);
28182825
});
28192826

2827+
// watch for changes in the title
2828+
var deregTitle = $scope.$watch('title', function(val) {
2829+
$scope.$emit('viewState.titleUpdated', $scope);
2830+
});
2831+
28202832
$scope.$on('$destroy', function(){
28212833
// deregister on destroy
28222834
deregLeftButtons();
28232835
deregRightButtons();
2836+
deregTitle();
28242837
});
28252838

28262839
};

dist/js/ionic-angular.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/ionic.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/ext/angular/src/directive/ionicTabBar.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
147147
$scope.icon = $attr.icon;
148148
$scope.iconOn = $attr.iconOn;
149149
$scope.iconOff = $attr.iconOff;
150+
$scope.badge = $attr.badge;
150151
$scope.viewSref = $attr.uiSref;
151152
$scope.url = $attr.href;
152153
if($scope.url && $scope.url.indexOf('#') === 0) {
@@ -236,7 +237,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
236237
replace: true,
237238
scope: true,
238239
template: '<div class="tabs">' +
239-
'<tab-controller-item icon-title="{{c.title}}" icon="{{c.icon}}" icon-on="{{c.iconOn}}" icon-off="{{c.iconOff}}" active="c.isVisible" index="$index" ng-repeat="c in controllers"></tab-controller-item>' +
240+
'<tab-controller-item icon-title="{{c.title}}" icon="{{c.icon}}" icon-on="{{c.iconOn}}" icon-off="{{c.iconOff}}" badge="{{c.badge}}" active="c.isVisible" index="$index" ng-repeat="c in controllers"></tab-controller-item>' +
240241
'</div>',
241242
link: function($scope, $element, $attr, tabsCtrl) {
242243
$element.addClass($scope.tabsType);
@@ -255,6 +256,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
255256
icon: '@',
256257
iconOn: '@',
257258
iconOff: '@',
259+
badge: '@',
258260
active: '=',
259261
tabSelected: '@',
260262
index: '='
@@ -269,7 +271,8 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
269271
};
270272
},
271273
template:
272-
'<a ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' +
274+
'<a ng-class="{active:active, \'has-badge\':badge}" ng-click="selectTab()" class="tab-item">' +
275+
'<i class="icon badge" ng-if="badge">{{badge}}</i>' +
273276
'<i class="icon {{icon}}" ng-if="icon"></i>' +
274277
'<i class="{{iconOn}}" ng-if="active"></i>' +
275278
'<i class="{{iconOff}}" ng-if="!active"></i> {{iconTitle}}' +

scss/_mixins.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@
7979
color: $color;
8080
}
8181

82+
@mixin tab-badge-style($bg-color, $color) {
83+
.tab-item .icon.badge {
84+
background-color: $bg-color;
85+
color: $color;
86+
}
87+
}
8288

8389
// Item Mixins
8490
// --------------------------------------------------

scss/_tabs.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@include justify-content(center);
1212

1313
@include tab-style($tabs-default-bg, $tabs-default-border, $tabs-default-text);
14+
@include tab-badge-style($tabs-default-text, $tabs-default-bg);
1415

1516
position: absolute;
1617
bottom: 0;
@@ -28,30 +29,39 @@
2829

2930
&.tabs-light {
3031
@include tab-style($tabs-light-bg, $tabs-light-border, $tabs-light-text);
32+
@include tab-badge-style($tabs-light-text, $tabs-light-bg);
3133
}
3234
&.tabs-stable {
3335
@include tab-style($tabs-stable-bg, $tabs-stable-border, $tabs-stable-text);
36+
@include tab-badge-style($tabs-stable-text, $tabs-stable-bg);
3437
}
3538
&.tabs-positive {
3639
@include tab-style($tabs-positive-bg, $tabs-positive-border, $tabs-positive-text);
40+
@include tab-badge-style($tabs-positive-text, $tabs-positive-bg);
3741
}
3842
&.tabs-calm {
3943
@include tab-style($tabs-calm-bg, $tabs-calm-border, $tabs-calm-text);
44+
@include tab-badge-style($tabs-calm-text, $tabs-calm-bg);
4045
}
4146
&.tabs-assertive {
4247
@include tab-style($tabs-assertive-bg, $tabs-assertive-border, $tabs-assertive-text);
48+
@include tab-badge-style($tabs-assertive-text, $tabs-assertive-bg);
4349
}
4450
&.tabs-balanced {
4551
@include tab-style($tabs-balanced-bg, $tabs-balanced-border, $tabs-balanced-text);
52+
@include tab-badge-style($tabs-balanced-text, $tabs-balanced-bg);
4653
}
4754
&.tabs-energized {
4855
@include tab-style($tabs-energized-bg, $tabs-energized-border, $tabs-energized-text);
56+
@include tab-badge-style($tabs-energized-text, $tabs-energized-bg);
4957
}
5058
&.tabs-royal {
5159
@include tab-style($tabs-royal-bg, $tabs-royal-border, $tabs-royal-text);
60+
@include tab-badge-style($tabs-royal-text, $tabs-royal-bg);
5261
}
5362
&.tabs-dark {
5463
@include tab-style($tabs-dark-bg, $tabs-dark-border, $tabs-dark-text);
64+
@include tab-badge-style($tabs-dark-text, $tabs-dark-bg);
5565
}
5666
@media (min--moz-device-pixel-ratio: 1.5),
5767
(-webkit-min-device-pixel-ratio: 1.5),
@@ -132,6 +142,18 @@
132142
line-height: inherit;
133143
}
134144

145+
.tab-item.has-badge {
146+
position: relative;
147+
}
148+
149+
.tab-item .icon.badge {
150+
position: absolute;
151+
padding: $tabs-badge-padding;
152+
top: 2%;
153+
right: 10%;
154+
font-size: $tabs-badge-font-size;
155+
}
156+
135157
/* Navigational tab */
136158

137159
/* Active state for tab */

scss/_variables.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ $tabs-height: 49px !default;
231231
$tabs-text-font-size: 14px !default;
232232
$tabs-text-font-size-side-icon: 12px !default;
233233
$tabs-icon-size: 32px !default;
234+
$tabs-badge-padding: 2px 6px;
235+
$tabs-badge-font-size: 12px !default;
236+
$tabs-text-font-size: 14px !default;
234237

235238
$tabs-light-bg: $button-light-bg;
236239
$tabs-light-border: $button-light-border;

0 commit comments

Comments
 (0)