Skip to content

Commit c5799df

Browse files
committed
feat(badge): Eva theme (#1407)
BREAKING CHANGE: NbBadgeComponent status static fields removed. STATUS_PRIMARY, STATUS_INFO, STATUS_SUCCESS, STATUS_WARNING, STATUS_DANGER. NbBadgeComponent position static fields replaced with NbBadgePosition type. Removed properties: TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, TOP_START, TOP_END, BOTTOM_START, BOTTOM_END. Badge status class now set on host element NbBadgeComponent 'positionClass' getter removed. Badge position class set on host element. Position class names prefixed with 'position-'. Following theme properties were renamed: badge-fg-text -> badge-[status]-text-color badge-primary-bg-color -> badge-primary-background-color badge-success-bg-color -> badge-success-background-color badge-info-bg-color -> badge-info-background-color badge-warning-bg-color -> badge-warning-background-color badge-danger-bg-color -> badge-danger-background-color
1 parent 8c6c677 commit c5799df

File tree

15 files changed

+316
-144
lines changed

15 files changed

+316
-144
lines changed

e2e/actions.e2e-spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { browser } from 'protractor';
8-
import { NbBadgeComponent } from '../src/framework/theme/components/badge/badge.component';
98
import badgeTests from './badge.e2e-spec';
109

1110
describe('nb-action', () => {
@@ -19,7 +18,7 @@ describe('nb-action', () => {
1918
const badgesConf = {
2019
selector: (i) => `nb-card:nth-child(4) nb-actions nb-action:nth-child(${i + 1}) nb-badge > span`,
2120
badges: [
22-
{ position: NbBadgeComponent.BOTTOM_LEFT, status: NbBadgeComponent.STATUS_SUCCESS, text: badgeText },
21+
{ position: 'bottom left', status: 'success', text: badgeText },
2322
],
2423
};
2524
badgeTests(badgesConf);

e2e/user.e2e-spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { browser, element, by } from 'protractor';
8-
import { NbBadgeComponent } from '../src/framework/theme/components/badge/badge.component';
98
import badgeTests from './badge.e2e-spec';
109

1110
describe('nb-user', () => {
@@ -20,7 +19,7 @@ describe('nb-user', () => {
2019
const badgesConf = {
2120
selector: (i) => `.test-row:nth-child(${elementsOffset + i + 1}) nb-badge > span`,
2221
badges: [
23-
{ position: NbBadgeComponent.TOP_RIGHT, status: NbBadgeComponent.STATUS_PRIMARY, text: badgeText },
22+
{ position: 'top right', status: 'primary', text: badgeText },
2423
],
2524
};
2625
badgeTests(badgesConf);

src/framework/theme/components/actions/actions.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { Component, HostBinding, Input } from '@angular/core';
88

99
import { convertToBoolProperty } from '../helpers';
1010
import { NbComponentSize } from '../component-size';
11+
import { NbComponentStatus } from '../component-status';
12+
import { NbBadgePosition } from '../badge/badge.component';
1113

1214
/**
1315
* Action item, display a link with an icon, or any other content provided instead.
@@ -100,7 +102,7 @@ export class NbActionComponent {
100102
* 'primary', 'info', 'success', 'warning', 'danger'
101103
* @param {string} val
102104
*/
103-
@Input() badgeStatus: string;
105+
@Input() badgeStatus: NbComponentStatus;
104106

105107
/**
106108
* Badge position.
@@ -109,7 +111,7 @@ export class NbActionComponent {
109111
* 'top start', 'top end', 'bottom start', 'bottom end'
110112
* @type string
111113
*/
112-
@Input() badgePosition: string;
114+
@Input() badgePosition: NbBadgePosition;
113115
}
114116

115117
/**

src/framework/theme/components/actions/actions.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ describe('NbActionComponent link with icon', () => {
188188

189189
it('should pass set badge position and status to badge component', () => {
190190
actionComponent.badgeText = '1';
191-
actionComponent.badgePosition = NbBadgeComponent.BOTTOM_RIGHT;
192-
actionComponent.badgeStatus = NbBadgeComponent.STATUS_INFO;
191+
actionComponent.badgePosition = 'bottom right';
192+
actionComponent.badgeStatus = 'info';
193193
fixture.detectChanges();
194194

195195
const badge = fixture.debugElement.query(By.directive(NbBadgeComponent));
196196
const badgeComponent: NbBadgeComponent = badge.componentInstance;
197-
expect(badgeComponent.position).toEqual(NbBadgeComponent.BOTTOM_RIGHT);
198-
expect(badgeComponent.colorClass).toEqual(NbBadgeComponent.STATUS_INFO);
197+
expect(badgeComponent.position).toEqual('bottom right');
198+
expect(badgeComponent.status).toEqual('info');
199199
});
200200
});
201201

src/framework/theme/components/badge/_badge.component.theme.scss

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55
*/
66

77
@mixin nb-badge-theme() {
8-
.nb-badge {
9-
color: nb-theme(badge-fg-text);
8+
nb-badge {
9+
border-radius: nb-theme(badge-border-radius);
10+
font-family: nb-theme(badge-text-font-family);
11+
font-size: nb-theme(badge-text-font-size);
12+
font-weight: nb-theme(badge-text-font-weight);
13+
line-height: nb-theme(badge-text-line-height);
14+
padding: nb-theme(badge-padding);
15+
}
1016

11-
&.nb-badge-primary {
12-
background-color: nb-theme(badge-primary-bg-color);
13-
}
14-
&.nb-badge-info {
15-
background-color: nb-theme(badge-info-bg-color);
16-
}
17-
&.nb-badge-success {
18-
background-color: nb-theme(badge-success-bg-color);
19-
}
20-
&.nb-badge-warning {
21-
background-color: nb-theme(badge-warning-bg-color);
22-
}
23-
&.nb-badge-danger {
24-
background-color: nb-theme(badge-danger-bg-color);
17+
@each $status in nb-get-statuses() {
18+
nb-badge.status-#{$status} {
19+
color: nb-theme(badge-#{$status}-text-color);
20+
background-color: nb-theme(badge-#{$status}-background-color);
2521
}
2622
}
2723
}

src/framework/theme/components/badge/badge.component.scss

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,37 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*/
66

7-
:host .nb-badge {
7+
@import '../../styles/core/mixins';
8+
9+
:host {
810
position: absolute;
9-
padding: 0.25em 0.4em;
10-
font-size: 75%;
11-
font-weight: 700;
12-
line-height: 1;
1311
text-align: center;
1412
white-space: nowrap;
1513
vertical-align: baseline;
16-
border-radius: 0.25rem;
14+
}
15+
16+
:host(.position-top) {
17+
top: 0;
18+
}
19+
20+
:host(.position-right) {
21+
right: 0;
22+
}
23+
24+
:host(.position-bottom) {
25+
bottom: 0;
26+
}
27+
28+
:host(.position-left) {
29+
left: 0;
30+
}
31+
32+
:host(.position-start) {
33+
@include nb-ltr(left, 0);
34+
@include nb-rtl(right, 0);
35+
}
1736

18-
&.top { top: 0; }
19-
&.right { right: 0; }
20-
&.bottom { bottom: 0; }
21-
&.left { left: 0; }
37+
:host(.position-end) {
38+
@include nb-ltr(right, 0);
39+
@include nb-rtl(left, 0);
2240
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { NbBadgeComponent, NbBadgeModule, NbBadgePosition, NbComponentStatus } from '@nebular/theme';
3+
4+
describe('NbBadgeComponent', () => {
5+
let fixture: ComponentFixture<NbBadgeComponent>;
6+
let badgeComponent: NbBadgeComponent;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({
10+
imports: [ NbBadgeModule ],
11+
});
12+
13+
fixture = TestBed.createComponent(NbBadgeComponent);
14+
badgeComponent = fixture.componentInstance;
15+
});
16+
17+
it(`should contain text set to 'text' input`, () => {
18+
const text = 'random badge text';
19+
badgeComponent.text = text;
20+
fixture.detectChanges();
21+
22+
expect(fixture.debugElement.nativeElement.textContent).toEqual(text);
23+
});
24+
25+
it('should has primary status by default', () => {
26+
expect(badgeComponent.status).toEqual('primary');
27+
});
28+
29+
it('should set status class', () => {
30+
const statuses: NbComponentStatus[] = [ 'primary', 'success', 'info', 'warning', 'danger' ];
31+
32+
for (const status of statuses) {
33+
badgeComponent.status = status;
34+
fixture.detectChanges();
35+
36+
expect(fixture.debugElement.classes[`status-${status}`]).toEqual(true);
37+
}
38+
});
39+
40+
it(`should has 'top' class if position contains 'top'`, () => {
41+
const topPositions: NbBadgePosition[] = [ 'top end', 'top left', 'top right', 'top start' ];
42+
43+
for (const position of topPositions) {
44+
badgeComponent.position = position;
45+
fixture.detectChanges();
46+
47+
expect(badgeComponent.top).toEqual(true);
48+
expect(fixture.debugElement.classes['position-top']).toEqual(true);
49+
}
50+
});
51+
52+
it(`should has 'right' class if position contains 'right'`, () => {
53+
const rightPositions: NbBadgePosition[] = [ 'top right', 'bottom right' ];
54+
55+
for (const position of rightPositions) {
56+
badgeComponent.position = position;
57+
fixture.detectChanges();
58+
59+
expect(badgeComponent.right).toEqual(true);
60+
expect(fixture.debugElement.classes['position-right']).toEqual(true);
61+
}
62+
});
63+
64+
it(`should has 'bottom' class if position contains 'bottom'`, () => {
65+
const bottomPositions: NbBadgePosition[] = [ 'bottom end', 'bottom left', 'bottom right', 'bottom start' ];
66+
67+
for (const position of bottomPositions) {
68+
badgeComponent.position = position;
69+
fixture.detectChanges();
70+
71+
expect(badgeComponent.bottom).toEqual(true);
72+
expect(fixture.debugElement.classes['position-bottom']).toEqual(true);
73+
}
74+
});
75+
76+
it(`should has 'left' class if position contains 'left'`, () => {
77+
const leftPositions: NbBadgePosition[] = [ 'top left', 'bottom left' ];
78+
79+
for (const position of leftPositions) {
80+
badgeComponent.position = position;
81+
fixture.detectChanges();
82+
83+
expect(badgeComponent.left).toEqual(true);
84+
expect(fixture.debugElement.classes['position-left']).toEqual(true);
85+
}
86+
});
87+
88+
it(`should has 'start' class if position contains 'start'`, () => {
89+
const startPositions: NbBadgePosition[] = [ 'top start', 'bottom start' ];
90+
91+
for (const position of startPositions) {
92+
badgeComponent.position = position;
93+
fixture.detectChanges();
94+
95+
expect(badgeComponent.start).toEqual(true);
96+
expect(fixture.debugElement.classes['position-start']).toEqual(true);
97+
}
98+
});
99+
100+
it(`should has 'end' class if position contains 'end'`, () => {
101+
const endPositions: NbBadgePosition[] = [ 'top end', 'bottom end' ];
102+
103+
for (const position of endPositions) {
104+
badgeComponent.position = position;
105+
fixture.detectChanges();
106+
107+
expect(badgeComponent.end).toEqual(true);
108+
expect(fixture.debugElement.classes['position-end']).toEqual(true);
109+
}
110+
});
111+
});

0 commit comments

Comments
 (0)