Added some shared components

This commit is contained in:
Erik Tiekstra
2021-03-16 16:09:02 +01:00
committed by Erik Tiekstra
parent 03ba526798
commit dfa1f1881d
21 changed files with 194 additions and 14 deletions

View File

@@ -13,6 +13,7 @@
[routerLinkActive]="['navigation__link--active']" [routerLinkActive]="['navigation__link--active']"
[routerLinkActiveOptions]="{ exact: true }" [routerLinkActiveOptions]="{ exact: true }"
> >
<dafa-icon [icon]="iconType.HOME" size="l"></dafa-icon>
<span class="navigation__text">Startsida</span> <span class="navigation__text">Startsida</span>
</a> </a>
</li> </li>

View File

@@ -1,11 +1,12 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { IconModule } from '@dafa-shared/components/icon/icon.module';
import { NavigationComponent } from './navigation.component'; import { NavigationComponent } from './navigation.component';
@NgModule({ @NgModule({
declarations: [NavigationComponent], declarations: [NavigationComponent],
imports: [CommonModule, RouterModule], imports: [CommonModule, RouterModule, IconModule],
exports: [NavigationComponent], exports: [NavigationComponent],
}) })
export class NavigationModule {} export class NavigationModule {}

View File

@@ -1,4 +1,5 @@
export enum IconType { export enum IconType {
HOME = 'home', HOME = 'home',
USER = 'user', USER = 'user',
BELL = 'bell',
} }

View File

@@ -1,10 +1,12 @@
<digi-ng-typography-base [afCompressed]="true"> <digi-ng-typography-base [afCompressed]="true">
<section class="page-not-found"> <dafa-horizontal-center>
<h1 class="heading">Oj då! Vi kan inte hitta sidan.</h1> <section class="page-not-found">
<p>Det kan bero på att länken du använder är felaktig eller att sidan inte längre finns.</p> <h1 class="heading">Oj då! Vi kan inte hitta sidan.</h1>
<a class="dafa__link dafa__link--with-icon" routerLink="/"> <p>Det kan bero på att länken du använder är felaktig eller att sidan inte längre finns.</p>
<digi-ng-icon-arrow-left class="dafa__digi-ng-icon" aria-hidden="true"></digi-ng-icon-arrow-left> <a class="dafa__link dafa__link--with-icon" routerLink="/">
Gå tillbaka till startsidan <digi-ng-icon-arrow-left class="dafa__digi-ng-icon" aria-hidden="true"></digi-ng-icon-arrow-left>
</a> Gå tillbaka till startsidan
</section> </a>
</section>
</dafa-horizontal-center>
</digi-ng-typography-base> </digi-ng-typography-base>

View File

@@ -3,6 +3,7 @@ import { DigiNgTypographyBaseModule } from '@af/digi-ng/_typography/typography-b
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { HorizontalCenterModule } from '@dafa-shared/components/horizontal-center/horizontal-center.module';
import { PageNotFoundComponent } from './page-not-found.component'; import { PageNotFoundComponent } from './page-not-found.component';
@NgModule({ @NgModule({
@@ -12,6 +13,7 @@ import { PageNotFoundComponent } from './page-not-found.component';
RouterModule.forChild([{ path: '', component: PageNotFoundComponent }]), RouterModule.forChild([{ path: '', component: PageNotFoundComponent }]),
DigiNgTypographyBaseModule, DigiNgTypographyBaseModule,
DigiNgIconArrowLeftModule, DigiNgIconArrowLeftModule,
HorizontalCenterModule,
], ],
}) })
export class PageNotFoundModule {} export class PageNotFoundModule {}

View File

@@ -1,3 +1,5 @@
<digi-ng-typography-base> <digi-ng-typography-base>
<section class="start">Start funkar!</section> <dafa-horizontal-center>
<section class="start">Start funkar!</section>
</dafa-horizontal-center>
</digi-ng-typography-base> </digi-ng-typography-base>

View File

@@ -6,6 +6,4 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
styleUrls: ['./start.component.scss'], styleUrls: ['./start.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class StartComponent { export class StartComponent {}
constructor() {}
}

View File

@@ -2,10 +2,16 @@ import { DigiNgTypographyBaseModule } from '@af/digi-ng/_typography/typography-b
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { HorizontalCenterModule } from '@dafa-shared/components/horizontal-center/horizontal-center.module';
import { StartComponent } from './start.component'; import { StartComponent } from './start.component';
@NgModule({ @NgModule({
declarations: [StartComponent], declarations: [StartComponent],
imports: [CommonModule, RouterModule.forChild([{ path: '', component: StartComponent }]), DigiNgTypographyBaseModule], imports: [
CommonModule,
RouterModule.forChild([{ path: '', component: StartComponent }]),
DigiNgTypographyBaseModule,
HorizontalCenterModule,
],
}) })
export class StartModule {} export class StartModule {}

View File

@@ -0,0 +1,3 @@
<div class="horizontal-center">
<ng-content></ng-content>
</div>

View File

@@ -0,0 +1,10 @@
@import 'variables/breakpoints';
@import 'variables/containers';
@import 'variables/gutters';
.horizontal-center {
width: 100%;
max-width: $af__breakpoint-xl;
padding: 0 $af__gutter-m;
margin: 0 auto;
}

View File

@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HorizontalCenterComponent } from './horizontal-center.component';
describe('HorizontalCenterComponent', () => {
let component: HorizontalCenterComponent;
let fixture: ComponentFixture<HorizontalCenterComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [HorizontalCenterComponent],
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(HorizontalCenterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,9 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
@Component({
selector: 'dafa-horizontal-center',
templateUrl: './horizontal-center.component.html',
styleUrls: ['./horizontal-center.component.scss', './horizontal-center.print.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HorizontalCenterComponent {}

View File

@@ -0,0 +1,11 @@
import { DigiNgLayoutContainerModule } from '@af/digi-ng/_layout/layout-container';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { HorizontalCenterComponent } from './horizontal-center.component';
@NgModule({
declarations: [HorizontalCenterComponent],
imports: [CommonModule, DigiNgLayoutContainerModule],
exports: [HorizontalCenterComponent],
})
export class HorizontalCenterModule {}

View File

@@ -0,0 +1,5 @@
@media print {
.horizontal-center {
padding: 0;
}
}

View File

@@ -0,0 +1,18 @@
<digi-ng-icon-custom *ngIf="isCustomIcon; else DigiNgIcon" aria-hidden="true" class="icon" [ngClass]="[iconClass]">
<svg *ngIf="icon === iconType.HOME" xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 576 512">
<path
d="M472.847,226.846l-34.116-34.116L250.998,4.997c-6.664-6.663-17.468-6.663-24.132,0L39.132,192.73L4.999,226.864
c-6.548,6.78-6.361,17.584,0.419,24.132c6.614,6.388,17.099,6.388,23.713,0l4.983-5.018v214.801
c0,9.426,7.641,17.067,17.067,17.067h375.467c9.426,0,17.067-7.641,17.067-17.067V245.978l5,5.001
c6.78,6.548,17.584,6.36,24.132-0.419C479.235,243.946,479.235,233.46,472.847,226.846z M290.115,443.713h-102.4V307.179h102.4
V443.713z M409.581,443.713h-85.333v-153.6c0-9.426-7.641-17.067-17.067-17.067H170.648c-9.426,0-17.067,7.641-17.067,17.067
v153.6H68.248V211.845L238.914,41.178l170.667,170.667V443.713z"
fill="currentColor"
></path>
</svg>
</digi-ng-icon-custom>
<ng-template #DigiNgIcon>
<digi-ng-icon-user-alt *ngIf="icon === iconType.USER" [ngClass]="iconClass"></digi-ng-icon-user-alt>
<digi-ng-icon-bell *ngIf="icon === iconType.BELL" [ngClass]="iconClass"></digi-ng-icon-bell>
</ng-template>

View File

@@ -0,0 +1,20 @@
@import 'mixins/icon';
:host {
display: inline-flex;
}
.icon {
&--s {
@include dafa__digi-ng-icon(0.875em);
}
&--m {
@include dafa__digi-ng-icon(1em);
}
&--l {
@include dafa__digi-ng-icon(1.5em);
}
&--xl {
@include dafa__digi-ng-icon(2em);
}
}

View File

@@ -0,0 +1,28 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { IconComponent } from './icon.component';
describe('IconComponent', () => {
let component: IconComponent;
let fixture: ComponentFixture<IconComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ IconComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(IconComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,27 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { IconSize } from '@dafa-enums/icon-size.enum';
import { IconType } from '@dafa-enums/icon-type.enum';
const CUSTOM_ICONS: IconType[] = [IconType.HOME];
@Component({
selector: 'dafa-icon',
templateUrl: './icon.component.html',
styleUrls: ['./icon.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class IconComponent implements OnChanges {
@Input() icon: IconType;
@Input() size: IconSize = IconSize.M;
iconClass: string;
iconType = IconType;
ngOnChanges(): void {
this.iconClass = `icon--${this.size}`;
}
get isCustomIcon(): boolean {
return CUSTOM_ICONS.includes(this.icon);
}
}

View File

@@ -0,0 +1,10 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { IconComponent } from './icon.component';
@NgModule({
declarations: [IconComponent],
imports: [CommonModule],
exports: [IconComponent],
})
export class IconModule {}

View File

@@ -51,6 +51,7 @@ strong {
&__link { &__link {
display: inline-flex; display: inline-flex;
align-items: center;
&--with-icon { &--with-icon {
gap: $af__gutter-xs; gap: $af__gutter-xs;