Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(badge): Eva theme #1407

Merged
merged 13 commits into from
Apr 22, 2019
3 changes: 1 addition & 2 deletions e2e/actions.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

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

describe('nb-action', () => {
Expand All @@ -19,7 +18,7 @@ describe('nb-action', () => {
const badgesConf = {
selector: (i) => `nb-card:nth-child(4) nb-actions nb-action:nth-child(${i + 1}) nb-badge > span`,
badges: [
{ position: NbBadgeComponent.BOTTOM_LEFT, status: NbBadgeComponent.STATUS_SUCCESS, text: badgeText },
{ position: 'bottom left', status: 'success', text: badgeText },
],
};
badgeTests(badgesConf);
Expand Down
3 changes: 1 addition & 2 deletions e2e/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

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

describe('nb-user', () => {
Expand All @@ -20,7 +19,7 @@ describe('nb-user', () => {
const badgesConf = {
selector: (i) => `.test-row:nth-child(${elementsOffset + i + 1}) nb-badge > span`,
badges: [
{ position: NbBadgeComponent.TOP_RIGHT, status: NbBadgeComponent.STATUS_PRIMARY, text: badgeText },
{ position: 'top right', status: 'primary', text: badgeText },
],
};
badgeTests(badgesConf);
Expand Down
28 changes: 12 additions & 16 deletions src/framework/theme/components/badge/_badge.component.theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
*/

@mixin nb-badge-theme() {
.nb-badge {
color: nb-theme(badge-fg-text);
nb-badge {
border-radius: nb-theme(badge-border-radius);
font-family: nb-theme(badge-text-font-family);
font-size: nb-theme(badge-text-font-size);
font-weight: nb-theme(badge-text-font-weight);
line-height: nb-theme(badge-text-line-height);
padding: nb-theme(badge-padding);
}

&.nb-badge-primary {
background-color: nb-theme(badge-primary-bg-color);
}
&.nb-badge-info {
background-color: nb-theme(badge-info-bg-color);
}
&.nb-badge-success {
background-color: nb-theme(badge-success-bg-color);
}
&.nb-badge-warning {
background-color: nb-theme(badge-warning-bg-color);
}
&.nb-badge-danger {
background-color: nb-theme(badge-danger-bg-color);
@each $status in nb-get-statuses() {
nb-badge.status-#{$status} {
color: nb-theme(badge-#{$status}-text-color);
background-color: nb-theme(badge-#{$status}-background-color);
}
}
}
38 changes: 28 additions & 10 deletions src/framework/theme/components/badge/badge.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,37 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

:host .nb-badge {
@import '../../styles/core/mixins';

:host {
position: absolute;
padding: 0.25em 0.4em;
font-size: 75%;
font-weight: 700;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: 0.25rem;
}

:host(.position-top) {
top: 0;
}

:host(.position-right) {
right: 0;
}

:host(.position-bottom) {
bottom: 0;
}

:host(.position-left) {
left: 0;
}

:host(.position-start) {
@include nb-ltr(left, 0);
@include nb-rtl(right, 0);
}

&.top { top: 0; }
&.right { right: 0; }
&.bottom { bottom: 0; }
&.left { left: 0; }
:host(.position-end) {
@include nb-ltr(right, 0);
@include nb-rtl(left, 0);
}
111 changes: 111 additions & 0 deletions src/framework/theme/components/badge/badge.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NbBadgeComponent, NbBadgeModule, NbBadgePosition, NbComponentStatus } from '@nebular/theme';

describe('NbBadgeComponent', () => {
let fixture: ComponentFixture<NbBadgeComponent>;
let badgeComponent: NbBadgeComponent;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ NbBadgeModule ],
});

fixture = TestBed.createComponent(NbBadgeComponent);
badgeComponent = fixture.componentInstance;
});

it(`should contain text set to 'text' input`, () => {
const text = 'random badge text';
badgeComponent.text = text;
fixture.detectChanges();

expect(fixture.debugElement.nativeElement.textContent).toEqual(text);
});

it('should has primary status by default', () => {
expect(badgeComponent.status).toEqual('primary');
});

it('should set status class', () => {
const statuses: NbComponentStatus[] = [ 'primary', 'success', 'info', 'warning', 'danger' ];

for (const status of statuses) {
badgeComponent.status = status;
fixture.detectChanges();

expect(fixture.debugElement.classes[`status-${status}`]).toEqual(true);
}
});

it(`should has 'top' class if position contains 'top'`, () => {
const topPositions: NbBadgePosition[] = [ 'top end', 'top left', 'top right', 'top start' ];

for (const position of topPositions) {
badgeComponent.position = position;
fixture.detectChanges();

expect(badgeComponent.top).toEqual(true);
expect(fixture.debugElement.classes['position-top']).toEqual(true);
}
});

it(`should has 'right' class if position contains 'right'`, () => {
const rightPositions: NbBadgePosition[] = [ 'top right', 'bottom right' ];

for (const position of rightPositions) {
badgeComponent.position = position;
fixture.detectChanges();

expect(badgeComponent.right).toEqual(true);
expect(fixture.debugElement.classes['position-right']).toEqual(true);
}
});

it(`should has 'bottom' class if position contains 'bottom'`, () => {
const bottomPositions: NbBadgePosition[] = [ 'bottom end', 'bottom left', 'bottom right', 'bottom start' ];

for (const position of bottomPositions) {
badgeComponent.position = position;
fixture.detectChanges();

expect(badgeComponent.bottom).toEqual(true);
expect(fixture.debugElement.classes['position-bottom']).toEqual(true);
}
});

it(`should has 'left' class if position contains 'left'`, () => {
const leftPositions: NbBadgePosition[] = [ 'top left', 'bottom left' ];

for (const position of leftPositions) {
badgeComponent.position = position;
fixture.detectChanges();

expect(badgeComponent.left).toEqual(true);
expect(fixture.debugElement.classes['position-left']).toEqual(true);
}
});

it(`should has 'start' class if position contains 'start'`, () => {
const startPositions: NbBadgePosition[] = [ 'top start', 'bottom start' ];

for (const position of startPositions) {
badgeComponent.position = position;
fixture.detectChanges();

expect(badgeComponent.start).toEqual(true);
expect(fixture.debugElement.classes['position-start']).toEqual(true);
}
});

it(`should has 'end' class if position contains 'end'`, () => {
const endPositions: NbBadgePosition[] = [ 'top end', 'bottom end' ];

for (const position of endPositions) {
badgeComponent.position = position;
fixture.detectChanges();

expect(badgeComponent.end).toEqual(true);
expect(fixture.debugElement.classes['position-end']).toEqual(true);
}
});
});
Loading