Skip to content

Commit 8454020

Browse files
author
iramos
committed
feat(loading card): add hero loading state
1 parent c24ddea commit 8454020

File tree

10 files changed

+136
-11
lines changed

10 files changed

+136
-11
lines changed

src/app/core/pages/home/home.page.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
<div fxFlex="10" fxFlex.gt-sm="20"></div>
33
<div fxFlex="90" fxFlex.gt-sm="80">
44
<h1 class="header__title">{{'topHeroes' | translate}}</h1>
5-
<mat-progress-spinner *ngIf="!heroes"
6-
class="progress__spinner"
7-
[color]="'primary'"
8-
[mode]="'indeterminate'">
9-
</mat-progress-spinner>
5+
<mat-card id="loading-card" class="hero-card" *ngIf="!heroes">
6+
<mat-card-header>
7+
<div mat-card-avatar class="hero-header__image"></div>
8+
<mat-card-title>.</mat-card-title>
9+
<mat-card-subtitle>.</mat-card-subtitle>
10+
<div class="flex-spacer"></div>
11+
<div class="hero-actions">
12+
<mat-icon class="icon__like--grey">favorite</mat-icon>
13+
</div>
14+
</mat-card-header>
15+
<mat-progress-bar [color]="'warn'" [mode]="'indeterminate'"></mat-progress-bar>
16+
<app-spinner></app-spinner>
17+
<img mat-card-image src="assets/images/loading-hero.jpg">
18+
</mat-card>
1019
<div id="heroes-list" *ngIf="heroes">
1120
<ng-container *ngFor="let hero of heroes">
1221
<mat-card class="hero-card">

src/app/core/pages/home/home.page.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
@import "mixins";
2-
3-
#heroes-list {
4-
margin: 2rem;
5-
}
2+
@import "colors";
63

74
.hero-header__image, mat-card-title, mat-card-subtitle, .mat-card-image {
85
cursor: pointer;
96
}
107

118
.hero-card {
9+
margin-bottom: 2rem;
1210
@include push--auto(2rem);
1311
}
1412

@@ -25,4 +23,4 @@
2523
.mat-card {
2624
margin-bottom: 2rem;
2725
}
28-
}
26+
}

src/app/core/pages/home/home.page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {AppConfig} from '../../../config/app.config';
77
@Component({
88
selector: 'app-home',
99
templateUrl: './home.page.html',
10+
styleUrls: ['./home.page.scss']
1011
})
1112

1213
export class HomePage implements OnInit {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.spinner {
2+
width: 40px;
3+
height: 40px;
4+
background-color: #333;
5+
6+
border-radius: 100%;
7+
-webkit-animation: sk-scaleout 1.0s infinite ease-in-out;
8+
animation: sk-scaleout 1.0s infinite ease-in-out;
9+
10+
transform: translate(-50%, -50%);
11+
position: absolute;
12+
left: 50%;
13+
top: 48%;
14+
}
15+
16+
@-webkit-keyframes sk-scaleout {
17+
0% { -webkit-transform: scale(0) }
18+
100% {
19+
-webkit-transform: scale(1.0);
20+
opacity: 0;
21+
}
22+
}
23+
24+
@keyframes sk-scaleout {
25+
0% {
26+
-webkit-transform: scale(0);
27+
transform: scale(0);
28+
} 100% {
29+
-webkit-transform: scale(1.0);
30+
transform: scale(1.0);
31+
opacity: 0;
32+
}
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="spinner"></div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
import {SpinnerComponent} from './spinner.component';
3+
4+
describe('SpinnerComponent', () => {
5+
let component: SpinnerComponent;
6+
let fixture: ComponentFixture<SpinnerComponent>;
7+
8+
beforeEach(async(() => {
9+
TestBed.configureTestingModule({
10+
declarations: [SpinnerComponent]
11+
}).compileComponents();
12+
}));
13+
14+
beforeEach(() => {
15+
fixture = TestBed.createComponent(SpinnerComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-spinner',
5+
templateUrl: './spinner.component.html',
6+
styleUrls: ['./spinner.component.css']
7+
})
8+
export class SpinnerComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

src/app/shared/shared.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {TranslateModule} from '@ngx-translate/core';
44
import {FlexLayoutModule} from '@angular/flex-layout';
55
import {NgxExampleLibraryModule} from '@ismaestro/ngx-example-library';
66
import {CommonModule} from '@angular/common';
7+
import {SpinnerComponent} from './components/spinner/spinner.component';
78

89
@NgModule({
910
imports: [
@@ -13,12 +14,16 @@ import {CommonModule} from '@angular/common';
1314
TranslateModule,
1415
NgxExampleLibraryModule
1516
],
17+
declarations: [
18+
SpinnerComponent
19+
],
1620
exports: [
1721
CommonModule,
1822
MaterialModule,
1923
FlexLayoutModule,
2024
TranslateModule,
21-
NgxExampleLibraryModule
25+
NgxExampleLibraryModule,
26+
SpinnerComponent
2227
]
2328
})
2429

src/app/styles/global.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ a, .cp {
99
cursor: pointer;
1010
}
1111

12+
h1, h2 {
13+
margin-bottom: 2rem;
14+
}
15+
1216
.header__title {
1317
text-align: center;
1418
font-size: 1.5rem;
@@ -36,6 +40,11 @@ a, .cp {
3640
cursor: pointer;
3741
}
3842

43+
.icon__like--grey {
44+
color: $grey;
45+
cursor: pointer;
46+
}
47+
3948
.hero-header__image {
4049
background-size: cover;
4150
}
@@ -131,3 +140,34 @@ snack-bar-container {
131140
background-color: white !important;
132141
}
133142
}
143+
144+
#loading-card {
145+
.hero-header__image, .hero__image {
146+
background: $grey;
147+
}
148+
149+
.mat-card-header-text {
150+
width: 30%;
151+
}
152+
153+
mat-card-title, mat-card-subtitle {
154+
background: $grey;
155+
color: $grey;
156+
}
157+
158+
.mat-progress-bar {
159+
width: calc(100% + 48px);
160+
margin: 0 -24px -1px -24px;
161+
.mat-progress-bar-fill, .mat-progress-bar-buffer {
162+
background-color: $light-grey;
163+
}
164+
.mat-progress-bar-fill::after {
165+
background-color: $grey;
166+
}
167+
168+
@media (max-width: 600px) {
169+
width: calc(100% + 34px);
170+
margin: 0px -24px -17px -17px;
171+
}
172+
}
173+
}

src/assets/images/loading-hero.jpg

7.8 KB
Loading

0 commit comments

Comments
 (0)