Skip to content

Commit

Permalink
feat(indeterminate bar): add property to enable indeterminate bar style
Browse files Browse the repository at this point in the history
  • Loading branch information
kKen94 committed Aug 7, 2020
1 parent 82cf63c commit d701dc3
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ You can filter the HTTP requests that would like to be avoided by the intercepto

| Input | Description | Default value |
| ---------------------- | ------------------ | --------------- |
| ```color``` | | ```#0984e3``` |
| ```showSpinner``` | | ```true``` |
| ```color``` | | ```#0984e3``` |
| ```showSpinner``` | | ```true``` |
| ```showBar``` | | ```true``` |
| ```indeterminate``` | Indeterminate style like Material | ```false``` |
| ```barHeight``` | | ```1px``` |
| ```spinnerDiameter``` | | ```10px``` |
| ```initialValue``` | From 1 to 100 | ```undefined``` |
| ```overlay``` | Show overlay that prevent user click | ```true``` |
| ```overlayValue``` | From 0 to 1 | ```1``` |
| ```overlayValue``` | From 0 to 1 | ```1``` |
| ```spinnerSpeed``` | From 1 to 10 | ```4``` |


Expand Down
5 changes: 5 additions & 0 deletions projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<span>show bar</span>
<mat-slide-toggle [(ngModel)]="showBar"></mat-slide-toggle>
</li>
<li>
<span>indeterminate</span>
<mat-slide-toggle [(ngModel)]="indeterminate"></mat-slide-toggle>
</li>
<li>
<span class="bottom">color</span>
<div class="square" [style.background-color]="color" (click)="showPicker = !showPicker;"></div>
Expand Down Expand Up @@ -81,6 +85,7 @@
[overlay]="overlay"
[overlayValue]="overlayValue"
[showBar]="showBar"
[indeterminate]="indeterminate"
[spinnerDiameter]="spinnerDiameter"
[spinnerSpeed]="spinnerSpeed"></ngx-progress>
<div class="full-height" fxLayout="column" fxLayoutAlign="center center">
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class AppComponent {
color = '#0984e3';
showSpinner = true;
showBar = true;
indeterminate = false;
barHeight = '2px';
spinnerDiameter = '15px';
initialValue = 0;
Expand Down
7 changes: 5 additions & 2 deletions projects/lib/src/lib/bar/bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
<div class="spinner" *ngIf="includeSpinner" [style.border-color]="color" [style.margin-top]="barHeight">
<div [style.width]="diameter" [style.height]="diameter" class="icon" [style.animation-duration]="1000/spinnerSpeed+'ms'"></div>
</div>
<div id="loading-bar" *ngIf="includeBar" [style.color]="color">
<div class="bar" [style.background]="color" [style.height]="barHeight" [style.width]="loader.progress + '%'">
<div *ngIf="includeBar" [style.color]="color">
<div class="bar" *ngIf="!indeterminate" [style.background]="color" [style.height]="barHeight" [style.width]="loader.progress + '%'">
<div class="peg" [style.height]="barHeight"></div>
</div>
<div class="progress" *ngIf="indeterminate" [style.height]="barHeight">
<div class="indeterminate" [style.background]="color"></div>
</div>
</div>
</ng-container>
101 changes: 100 additions & 1 deletion projects/lib/src/lib/bar/bar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,48 @@
transition: 350ms linear all;
color: #29d;

.progress {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
border-radius: 2px;
background-clip: padding-box;
overflow: hidden;
z-index: 10002;

& .indeterminate {
&:before {
content: '';
position: absolute;
background-color: inherit;
top: 0;
left: 0;
bottom: 0;
will-change: left, right;
-webkit-animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
}

&:after {
content: '';
position: absolute;
background-color: inherit;
top: 0;
left: 0;
bottom: 0;
will-change: left, right;
-webkit-animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
-webkit-animation-delay: 1.15s;
animation-delay: 1.15s;
}
}
}

.bar {
transition: width 350ms;

background: #29d;
position: absolute;
z-index: 10002;
Expand Down Expand Up @@ -64,3 +103,63 @@
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

@-webkit-keyframes indeterminate {
0% {
left: -35%;
right: 100%;
}
60% {
left: 100%;
right: -90%;
}
100% {
left: 100%;
right: -90%;
}
}

@keyframes indeterminate {
0% {
left: -35%;
right: 100%;
}
60% {
left: 100%;
right: -90%;
}
100% {
left: 100%;
right: -90%;
}
}

@-webkit-keyframes indeterminate-short {
0% {
left: -200%;
right: 100%;
}
60% {
left: 107%;
right: -8%;
}
100% {
left: 107%;
right: -8%;
}
}

@keyframes indeterminate-short {
0% {
left: -200%;
right: 100%;
}
60% {
left: 107%;
right: -8%;
}
100% {
left: 107%;
right: -8%;
}
}
1 change: 1 addition & 0 deletions projects/lib/src/lib/bar/bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class BarComponent {
@Input() color!: string;
@Input() barHeight!: string;
@Input() diameter!: string;
@Input() indeterminate!: string;
// tslint:disable-next-line:variable-name
_initialValue!: number;
get initialValue(): number {
Expand Down
1 change: 1 addition & 0 deletions projects/lib/src/lib/ngx-progress.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*ngIf="progressService.isStarted"
[includeSpinner]="showSpinner"
[includeBar]="showBar"
[indeterminate]="indeterminate"
[barHeight]="barHeight"
[color]="color"
[diameter]="spinnerDiameter"
Expand Down
4 changes: 4 additions & 0 deletions projects/lib/src/lib/ngx-progress.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class NgxProgressComponent implements OnInit, OnDestroy {
* Show and hide progress bar
*/
@Input() showBar = true;
/**
* If true set indeterminate bar style, like Material
*/
@Input() indeterminate = false;
/**
* Height of progress bar.
*
Expand Down

0 comments on commit d701dc3

Please sign in to comment.