Skip to content

Commit

Permalink
[update] page load animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Ferreira committed Feb 18, 2021
1 parent 03d6c30 commit e3b8cc1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
12 changes: 4 additions & 8 deletions src/app/components/content/content.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<app-sandbox
*ngIf="findComponent()"
[component]="findComponent()"
*ngIf="component"
[component]="component"
></app-sandbox>
<markdown
[src]="
router.url !== '/'
? './assets/docs' + router.url.split('#')[0] + '/index.md'
: ''
"
(load)="handleLoad()"
[src]="getMarkdownPath()"
(ready)="handleLoad()"
></markdown>
7 changes: 7 additions & 0 deletions src/app/components/content/content.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
height: calc(100% - 72px);
margin: -16px;
overflow: auto;
&.loaded {
transition: .5s all ease-in-out;
}
&:not(.loaded) {
margin-top: 16px;
opacity: 0;
}
> * {
padding: 0 64px 32px 64px;
margin: auto;
Expand Down
25 changes: 19 additions & 6 deletions src/app/components/content/content.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, ElementRef, OnInit } from '@angular/core';
import { DataService } from 'src/app/services/data.service';
import { Router } from '@angular/router';

Expand All @@ -8,22 +8,35 @@ import { Router } from '@angular/router';
styleUrls: ['./content.component.scss'],
})
export class ContentComponent implements OnInit {
constructor(public data: DataService, public router: Router) {}
component: any;
constructor(
public data: DataService,
public router: Router,
public elRef: ElementRef
) {}

ngOnInit(): void {}

findComponent(): boolean {
return this.data.sandbox.find(
({ name }) => name === this.data.getNameFromUrl()
);
getMarkdownPath(): string {
return this.router.url !== '/'
? `./assets/docs${this.router.url.split('#')[0]}/index.md`
: '';
}

handleLoad(): void {
this.elRef.nativeElement.classList.remove('loaded');
setTimeout(() => {
this.elRef.nativeElement.classList.add('loaded');
}, 0);
// wait for iframes to load and call set theme
document.querySelectorAll('iframe').forEach((el) => {
el.onload = () => this.data.setDemoTheme(el);
});
// scroll content to top
document.querySelector('app-content').scrollTo(0, 0);
// fetch new component
this.component = this.data.sandbox.find(
({ name }) => name === this.data.getNameFromUrl()
);
}
}
1 change: 0 additions & 1 deletion src/app/services/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class DataService {
if (el) {
const body = el.contentWindow.document.body;
body.setAttribute('theme', this.appTheme);
body.querySelector('.demo').style.opacity = '1';
} else {
document.querySelectorAll('iframe').forEach((frame) => {
frame.contentWindow.document.body.setAttribute('theme', this.appTheme);
Expand Down
1 change: 0 additions & 1 deletion src/assets/docs/demo-styles.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.demo {
opacity: 0;
display: flex;
align-items: center;
justify-content: center;
Expand Down

0 comments on commit e3b8cc1

Please sign in to comment.