-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #892 from mobi/Feature#814
[Feature] Progress Bar
- Loading branch information
Showing
13 changed files
with
478 additions
and
4 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
35 changes: 35 additions & 0 deletions
35
projects/go-lib/src/lib/components/go-progress-bar/go-progress-bar.component.html
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,35 @@ | ||
<div class="go-progress-bar" tabindex="-1"> | ||
<ng-container | ||
*ngTemplateOutlet="mode === 'determinate' ? determinate : indeterminate" | ||
> | ||
</ng-container> | ||
</div> | ||
|
||
<ng-template #determinate> | ||
<div class="go-progress-bar__determinate"> | ||
<span class="go-progress-bar__determinate__left-label"> | ||
{{ leftLabel }}</span | ||
> | ||
<div class="go-progress-bar__determinate--track"> | ||
<div | ||
class="go-progress-bar__determinate--indicator" | ||
[ngStyle]="{ width: indicatorWidth + '%' }" | ||
></div> | ||
</div> | ||
<span class="go-progress-bar__determinate__right-label">{{ | ||
rightLabel | ||
}}</span> | ||
</div> | ||
</ng-template> | ||
|
||
<ng-template #indeterminate> | ||
<div class="go-progress-bar__indeterminate"> | ||
<div class="go-progress-bar__indeterminate--track"></div> | ||
<div | ||
class="go-progress-bar__indeterminate--indicator go-progress-bar__indeterminate--primary-indicator" | ||
></div> | ||
<div | ||
class="go-progress-bar__indeterminate--indicator go-progress-bar__indeterminate--secondary-indicator" | ||
></div> | ||
</div> | ||
</ng-template> |
125 changes: 125 additions & 0 deletions
125
projects/go-lib/src/lib/components/go-progress-bar/go-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,125 @@ | ||
@import '../../../../styles/variables'; | ||
@import '../../../../styles/mixins'; | ||
|
||
@mixin label-style($float, $padding) { | ||
float: $float; | ||
padding: $padding; | ||
font-weight: $weight-regular; | ||
white-space: nowrap; | ||
} | ||
|
||
@mixin determinate-elem($width, $background-color) { | ||
width: $width; | ||
height: 10px; | ||
background-color: $background-color; | ||
} | ||
|
||
@mixin indeterminate-elem($background-color) { | ||
height: 100%; | ||
position: absolute; | ||
width: 100%; | ||
background-color: $background-color; | ||
} | ||
|
||
.go-progress-bar { | ||
&__determinate { | ||
align-items: center; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
position: relative; | ||
width: 100%; | ||
|
||
&__left-label { | ||
@include label-style(left, 0 8px 0 0); | ||
} | ||
|
||
&__right-label { | ||
@include label-style(right, 0 0 0 8px); | ||
} | ||
|
||
&--track { | ||
@include determinate-elem(100%, $theme-light-app-bg); | ||
border-radius: 5px; | ||
overflow: hidden; | ||
} | ||
|
||
&--indicator { | ||
@include determinate-elem(0%, $ui-color-primary); | ||
transition: width 2s ease-in; | ||
transition-timing-function: ease-in; | ||
} | ||
} | ||
|
||
&__indeterminate { | ||
backface-visibility: hidden; | ||
border-radius: 5px; | ||
height: 10px; | ||
overflow: hidden; | ||
position: relative; | ||
transform: translate3d(0, 0, 0); | ||
width: 100%; | ||
|
||
&--track { | ||
@include indeterminate-elem($theme-light-app-bg); | ||
} | ||
|
||
&--indicator { | ||
@include indeterminate-elem($ui-color-primary); | ||
backface-visibility: hidden; | ||
transform-origin: top left; | ||
transition: transform 250ms ease; | ||
} | ||
|
||
&--primary-indicator { | ||
animation: primary-indeterminate-translate 2000ms infinite linear; | ||
left: -99.166611%; | ||
} | ||
|
||
&--secondary-indicator { | ||
animation: secondary-indeterminate-translate 2000ms infinite linear; | ||
left: 0; | ||
} | ||
} | ||
} | ||
|
||
@keyframes primary-indeterminate-translate { | ||
0% { | ||
transform: translateX(0) scaleX(0.4); | ||
} | ||
|
||
20% { | ||
animation-timing-function: cubic-bezier(0.5, 0, 0.701732, 0.495819); | ||
transform: translateX(20%) scaleX(0.2); | ||
} | ||
|
||
60% { | ||
animation-timing-function: cubic-bezier(0.302435, 0.381352, 0.55, 0.956352); | ||
transform: translateX(80%) scaleX(0.9); | ||
} | ||
|
||
100% { | ||
transform: translateX(200%) scaleX(0.2); | ||
} | ||
} | ||
|
||
@keyframes secondary-indeterminate-translate { | ||
0% { | ||
animation-timing-function: cubic-bezier(0.15, 0, 0.515058, 0.409685); | ||
transform: translateX(0) scaleX(0); | ||
} | ||
|
||
25% { | ||
animation-timing-function: cubic-bezier(0.31033, 0.284058, 0.8, 0.733712); | ||
transform: translateX(25%) scaleX(0.5); | ||
} | ||
|
||
60.35% { | ||
animation-timing-function: cubic-bezier(0.4, 0.627035, 0.6, 0.902026); | ||
transform: translateX(100%) scaleX(0.8); | ||
} | ||
|
||
100% { | ||
transform: translateX(200%); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
projects/go-lib/src/lib/components/go-progress-bar/go-progress-bar.component.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,49 @@ | ||
import { SimpleChange, SimpleChanges } from "@angular/core"; | ||
import { | ||
async, | ||
ComponentFixture, | ||
fakeAsync, | ||
TestBed, | ||
tick, | ||
} from "@angular/core/testing"; | ||
|
||
import { GoProgressBarComponent } from "./go-progress-bar.component"; | ||
|
||
describe("GoProgressBarComponent", () => { | ||
let component: GoProgressBarComponent; | ||
let fixture: ComponentFixture<GoProgressBarComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [GoProgressBarComponent], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GoProgressBarComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe("ngOnChanges()", () => { | ||
it("should test when value is undefined", fakeAsync(() => { | ||
component.ngOnChanges({ | ||
value: new SimpleChange(undefined, undefined, false), | ||
}); | ||
|
||
tick(500); | ||
expect(component.indicatorWidth).toBe(undefined); | ||
})); | ||
|
||
it("should test when value is defined", fakeAsync(() => { | ||
component.ngOnChanges({ value: new SimpleChange(undefined, 40, true) }); | ||
|
||
tick(501); | ||
expect(component.indicatorWidth).toEqual(40); | ||
})); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
projects/go-lib/src/lib/components/go-progress-bar/go-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,23 @@ | ||
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'go-progress-bar', | ||
templateUrl: './go-progress-bar.component.html', | ||
styleUrls: ['./go-progress-bar.component.scss'], | ||
}) | ||
export class GoProgressBarComponent implements OnChanges { | ||
@Input() mode: 'determinate' | 'indeterminate' = 'determinate'; | ||
@Input() value: number; | ||
@Input() leftLabel?: string; | ||
@Input() rightLabel?: string; | ||
|
||
indicatorWidth: number; | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
if ('value' in changes) { | ||
setTimeout(() => { | ||
this.indicatorWidth = changes.value.currentValue; | ||
}, 500); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
projects/go-lib/src/lib/components/go-progress-bar/go-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,16 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { GoProgressBarComponent } from './go-progress-bar.component'; | ||
|
||
|
||
|
||
@NgModule({ | ||
declarations: [GoProgressBarComponent], | ||
imports: [ | ||
CommonModule | ||
], | ||
exports: [ | ||
GoProgressBarComponent | ||
] | ||
}) | ||
export class GoProgressBarModule { } |
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
Oops, something went wrong.