-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): add progress-bar component (#459)
- Loading branch information
1 parent
f40e78f
commit 3693494
Showing
24 changed files
with
517 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/framework/theme/components/progress-bar/_progress-bar.component.theme.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@mixin nb-progress-bar-theme() { | ||
|
||
.progress-container { | ||
height: nb-theme(progress-bar-height); | ||
border-radius: nb-theme(progress-bar-radius); | ||
background-color: nb-theme(progress-bar-bg); | ||
&.xlg { | ||
.progress-value { | ||
font-size: nb-theme(progress-bar-font-size-xlg); | ||
} | ||
height: nb-theme(progress-bar-height-xlg); | ||
} | ||
&.lg { | ||
.progress-value { | ||
font-size: nb-theme(progress-bar-font-size-lg); | ||
} | ||
height: nb-theme(progress-bar-height-lg); | ||
} | ||
&.sm { | ||
.progress-value { | ||
font-size: nb-theme(progress-bar-font-size-sm); | ||
} | ||
height: nb-theme(progress-bar-height-sm); | ||
} | ||
&.xs { | ||
.progress-value { | ||
font-size: nb-theme(progress-bar-font-size-xs); | ||
} | ||
height: nb-theme(progress-bar-height-xs); | ||
} | ||
} | ||
.progress-value { | ||
background-color: nb-theme(progress-bar-default-bg); | ||
color: nb-theme(progress-bar-font-color); | ||
font-size: nb-theme(progress-bar-font-size); | ||
font-weight: nb-theme(progress-bar-font-weight); | ||
line-height: nb-theme(progress-bar-line-height); | ||
transition-duration: nb-theme(progress-bar-animation-duration); | ||
transition-property: width, background-color; | ||
&.primary { | ||
background-color: nb-theme(progress-bar-primary-bg); | ||
} | ||
&.info { | ||
background-color: nb-theme(progress-bar-info-bg); | ||
} | ||
&.success { | ||
background-color: nb-theme(progress-bar-success-bg); | ||
} | ||
&.warning { | ||
background-color: nb-theme(progress-bar-warning-bg); | ||
} | ||
&.danger { | ||
background-color: nb-theme(progress-bar-danger-bg); | ||
} | ||
} | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
src/framework/theme/components/progress-bar/progress-bar.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
:host { | ||
display: block; | ||
} | ||
|
||
.progress-container { | ||
overflow: hidden; | ||
} | ||
|
||
.progress-value { | ||
height: 100%; | ||
text-align: center; | ||
overflow: hidden; | ||
} |
95 changes: 95 additions & 0 deletions
95
src/framework/theme/components/progress-bar/progress-bar.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { Component, Input } from '@angular/core'; | ||
|
||
/** | ||
* Progress Bar is a component for indicating progress. | ||
* | ||
* Simple usage: | ||
* | ||
* ```html | ||
* <nb-progress-bar [value]="50"></nb-progress-bar> | ||
* ``` | ||
* | ||
* Progress bar accepts property `value` in range 0-100 | ||
* @stacked-example(Progress bar, progress-bar/progress-bar-showcase.component) | ||
* | ||
* Progress bar background could be configured by providing a `status` property: | ||
* @stacked-example(Progress bar status, progress-bar/progress-bar-status.component) | ||
* | ||
* Progress bar size (height and font-size) could be configured by providing a `size` property: | ||
* @stacked-example(Progress bar size, progress-bar/progress-bar-size.component) | ||
* | ||
* `displayValue` property shows current value inside progress bar. It's also possible to add custom text inside: | ||
* @stacked-example(Progress bar value, progress-bar/progress-bar-value.component) | ||
* | ||
* Progress bar supports `width` and `background-color` transition: | ||
* @stacked-example(Progress bar interactive, progress-bar/progress-bar-interactive.component) | ||
* | ||
* @styles | ||
* | ||
* progress-bar-height-xlg: | ||
* progress-bar-height-lg: | ||
* progress-bar-height: | ||
* progress-bar-height-sm: | ||
* progress-bar-height-xs: | ||
* progress-bar-font-size-xlg: | ||
* progress-bar-font-size-lg: | ||
* progress-bar-font-size: | ||
* progress-bar-font-size-sm: | ||
* progress-bar-font-size-xs: | ||
* progress-bar-radius: | ||
* progress-bar-bg-color: | ||
* progress-bar-font-color: | ||
* progress-bar-font-weight: | ||
* progress-bar-default-bg-color: | ||
* progress-bar-primary-bg-color: | ||
* progress-bar-success-bg-color: | ||
* progress-bar-info-bg-color: | ||
* progress-bar-warning-bg-color: | ||
* progress-bar-danger-bg-color: | ||
*/ | ||
@Component({ | ||
selector: 'nb-progress-bar', | ||
styleUrls: ['./progress-bar.component.scss'], | ||
template: ` | ||
<div class="progress-container {{ size ? '' + size : '' }}"> | ||
<div class="progress-value {{ status ? '' + status : '' }}" [style.width.%]="value"> | ||
<span *ngIf="displayValue">{{ value }}%</span> | ||
<ng-content></ng-content> | ||
</div> | ||
</div> | ||
`, | ||
}) | ||
export class NbProgressBarComponent { | ||
|
||
/** | ||
* Progress bar value in percent (0 - 100) | ||
* @type {number} | ||
* @private | ||
*/ | ||
@Input() value: number = 0; | ||
|
||
/** | ||
* Progress bar background (primary, info success, warning, danger) | ||
* @param {string} val | ||
*/ | ||
@Input() status: string; | ||
|
||
/** | ||
* Progress bar size (xs, sm, lg, xlg) | ||
* @param {string} val | ||
*/ | ||
@Input() size: string; | ||
|
||
/** | ||
* Displays value inside progress bar | ||
* @param {string} val | ||
*/ | ||
@Input() displayValue: boolean = false; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/framework/theme/components/progress-bar/progress-bar.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { NgModule } from '@angular/core'; | ||
|
||
import { NbSharedModule } from '../shared/shared.module'; | ||
import { NbProgressBarComponent } from './progress-bar.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
NbSharedModule, | ||
], | ||
declarations: [NbProgressBarComponent], | ||
exports: [NbProgressBarComponent], | ||
}) | ||
export class NbProgressBarModule { } |
60 changes: 60 additions & 0 deletions
60
src/framework/theme/components/progress-bar/progress-bar.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { NbProgressBarComponent } from './progress-bar.component'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('Component: NbProgressBar', () => { | ||
|
||
let progressBar: NbProgressBarComponent; | ||
let fixture: ComponentFixture<NbProgressBarComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [NbProgressBarComponent], | ||
}); | ||
|
||
fixture = TestBed.createComponent(NbProgressBarComponent); | ||
progressBar = fixture.componentInstance; | ||
}); | ||
|
||
it('Setting value 50 should set width to 50%', () => { | ||
progressBar.value = 50; | ||
fixture.detectChanges(); | ||
expect( | ||
fixture | ||
.debugElement | ||
.query(By.css('.progress-value')).nativeElement.style.width) | ||
.toBe('50%'); | ||
}); | ||
|
||
it('Setting status danger should set class danger', () => { | ||
progressBar.status = 'danger'; | ||
fixture.detectChanges(); | ||
expect( | ||
fixture | ||
.debugElement | ||
.query(By.css('.progress-value')).nativeElement.classList.contains('danger')) | ||
.toBeTruthy() | ||
}); | ||
|
||
it('Setting size sm should set class sm', () => { | ||
progressBar.size = 'sm'; | ||
fixture.detectChanges(); | ||
expect( | ||
fixture | ||
.debugElement | ||
.query(By.css('.progress-container')).nativeElement.classList.contains('sm')) | ||
.toBeTruthy() | ||
}); | ||
|
||
it('Setting displayValue should create span with value label', () => { | ||
progressBar.value = 40; | ||
progressBar.displayValue = true; | ||
fixture.detectChanges(); | ||
expect( | ||
fixture | ||
.debugElement | ||
.query(By.css('.progress-value span')).nativeElement.innerHTML) | ||
.toContain('40%') | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.