Skip to content

Commit

Permalink
✨ ngIfLoaded directive
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-gn committed Dec 28, 2021
1 parent fd62a79 commit 9f36fdc
Show file tree
Hide file tree
Showing 13 changed files with 957 additions and 91 deletions.
578 changes: 488 additions & 90 deletions design-system/documentation.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion design-system/projects/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mprisma/components",
"version": "0.0.73",
"version": "0.0.74",
"repository": {
"type": "git",
"url": "https://github.com/gabriel-gn/prisma-components.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {InjectionToken} from '@angular/core';
import {SpinnerComponent} from './spinner/spinner.component';
import {ComponentType} from '@angular/cdk/overlay';

export const defaultSpinner: ComponentType<any> = SpinnerComponent;

export const IF_LOADED_SPINNER = new InjectionToken<ComponentType<any>>('defaultSpinner');
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgIfLoadedDirective } from './ng-if-loaded.directive';

describe('NgIfLoadedDirective', () => {
it('should create an instance', () => {
const directive = new NgIfLoadedDirective();
expect(directive).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
ComponentFactoryResolver,
Directive,
Inject,
Input,
TemplateRef,
ViewContainerRef
} from '@angular/core';
import {IF_LOADED_SPINNER} from './injection';
import {ComponentType} from '@angular/cdk/overlay';

@Directive({
// tslint:disable-next-line:directive-selector
selector: '[ngIfLoaded]'
})
export class NgIfLoadedDirective {

spinner: ComponentType<any>;

constructor(
@Inject(IF_LOADED_SPINNER) spinnerComponent: ComponentType<any>,
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private resolver: ComponentFactoryResolver
) {
this.spinner = spinnerComponent;
}


@Input()
set ngIfLoaded(value) {
if (value) {
this.viewContainer.clear();
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
const factory = this.resolver.resolveComponentFactory(this.spinner);
this.viewContainer.createComponent(factory);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {ModuleWithProviders, NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {NgIfLoadedDirective} from './ng-if-loaded.directive';
import {SpinnerComponent} from './spinner/spinner.component';
import {IF_LOADED_SPINNER} from './injection';
import {CommandPaletteService} from '../../services/command-palette/command-palette.service';
import {CommandPaletteEntriesService} from '../../services/command-palette/command-palette-entries.service';
import {ComponentInjectorService} from '../../services/command-palette/component-injector.service';
import {ComponentType} from '@angular/cdk/overlay';

const directives = [
NgIfLoadedDirective,
SpinnerComponent
];

@NgModule({
declarations: directives,
exports: directives,
imports: [
CommonModule
],
})
export class NgIfLoadedModule {
public static forRoot(spinnerComponent: ComponentType<any> = undefined): ModuleWithProviders<NgIfLoadedModule> {
return {
ngModule: NgIfLoadedModule,
providers: [
CommandPaletteService,
CommandPaletteEntriesService,
ComponentInjectorService,
{provide: IF_LOADED_SPINNER, useValue: spinnerComponent || SpinnerComponent},
]
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="pm-spinner">
<div class="d-flex justify-content-center w-100 h-100" style="min-height: 50px;">
<div class="spinner-wrap">
<div class="spinner-cube">
<div class="spinner-front"></div>
<div class="spinner-left"></div>
<div class="spinner-top"></div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
.pm-spinner {
// Cube parameters
$colorBorder: #f5f5f5;
$colorMin: #dddddd;
//$colorMax: #505050;
$colorMax: #dddddd;
$size: 30px;
// Time parameters
$duration: 1s;
$wait: 20%;
$borderSize: $size * 0.1;

.spinner-wrap {
perspective: 2 * $size;
perspective-origin: 50% 0px;
min-height: 50px;
padding-top: 3px;
align-self: center;
}

.spinner-cube {
position: relative;
width: $size;
transform-style: preserve-3d;
}

.spinner-cube div {
position: absolute;
width: $size;
height: $size;
}

.spinner-front {
background: $colorMin;
border: $borderSize solid $colorBorder;
transform: translateZ($size * 0.5);
animation: colorsf $duration ease-in-out infinite;
-moz-animation: colorsf $duration ease-in-out infinite;
-webkit-animation: colorsf $duration ease-in-out infinite;
-o-animation: colorsf $duration ease-in-out infinite;
-ms-animation: colorsf $duration ease-in-out infinite;
}

.spinner-left {
background: $colorMax;
border: $borderSize solid $colorBorder;
transform: rotateY(270deg) translateX(-$size * 0.5);
transform-origin: center left;
animation: colorsl $duration ease-in-out infinite;
-moz-animation: colorsl $duration ease-in-out infinite;
-webkit-animation: colorsl $duration ease-in-out infinite;
-o-animation: colorsl $duration ease-in-out infinite;
-ms-animation: colorsl $duration ease-in-out infinite;
}

.spinner-top {
background: $colorMax;
border: $borderSize solid $colorBorder;
transform: rotateX(90deg) translateZ($size * 0.5);
animation: colorsl $duration ease-in-out infinite;
-moz-animation: colorsl $duration ease-in-out infinite;
-webkit-animation: colorsl $duration ease-in-out infinite;
-o-animation: colorsl $duration ease-in-out infinite;
-ms-animation: colorsl $duration ease-in-out infinite;
}

@keyframes colorsf {
#{$wait} {
background: $colorMin;
}
100% {
background: $colorMax;
}
}

@keyframes colorsl {
#{$wait} {
background: $colorMax;
}
100% {
background: $colorMin;
}
}

@keyframes cube {
#{$wait} {
transform: rotateY(0deg);
}
100% {
transform: rotateY(90deg);
}
}

@-webkit-keyframes colorsf {
#{$wait} {
background: $colorMin;
}
100% {
background: $colorMax;
}
}

@-webkit-keyframes colorsl {
#{$wait} {
background: $colorMax;
}
100% {
background: $colorMin;
}
}

@-webkit-keyframes cube {
#{$wait} {
transform: rotateY(0deg);
}
100% {
transform: rotateY(90deg);
}
}


@-o-keyframes colorsf {
#{$wait} {
background: $colorMin;
}
100% {
background: $colorMax;
}
}

@-o-keyframes colorsl {
#{$wait} {
background: $colorMax;
}
100% {
background: $colorMin;
}
}

@-o-keyframes cube {
#{$wait} {
transform: rotateY(0deg);
}
100% {
transform: rotateY(90deg);
}
}

@-ms-keyframes colorsf {
#{$wait} {
background: $colorMin;
}
100% {
background: $colorMax;
}
}

@-ms-keyframes colorsl {
#{$wait} {
background: $colorMax;
}
100% {
background: $colorMin;
}
}

@-ms-keyframes cube {
#{$wait} {
transform: rotateY(0deg);
}
100% {
transform: rotateY(90deg);
}
}

@-ms-keyframes colorsf {
#{$wait} {
background: $colorMin;
}
100% {
background: $colorMax;
}
}

@-moz-keyframes colorsl {
#{$wait} {
background: $colorMax;
}
100% {
background: $colorMin;
}
}

@-moz-keyframes cube {
#{$wait} {
transform: rotateY(0deg);
}
100% {
transform: rotateY(90deg);
}
}

.spinner-cube {
z-index: 999;
animation: cube $duration ease-in-out infinite;
-moz-animation: cube $duration ease-in-out infinite;
-webkit-animation: cube $duration ease-in-out infinite;
-o-animation: cube $duration ease-in-out infinite;
-ms-animation: cube $duration ease-in-out infinite;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';

import {SpinnerComponent} from './spinner.component';

describe('SpinnerComponent', () => {
let component: SpinnerComponent;
let fixture: ComponentFixture<SpinnerComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SpinnerComponent]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SpinnerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Component, OnInit} from '@angular/core';

@Component({
selector: 'pm-spinner',
templateUrl: './spinner.component.html',
styleUrls: ['./spinner.component.scss']
})
export class SpinnerComponent implements OnInit {

constructor() {
}

ngOnInit(): void {
}

}
Loading

1 comment on commit 9f36fdc

@vercel
Copy link

@vercel vercel bot commented on 9f36fdc Dec 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.