-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aeee606
commit 31e4730
Showing
12 changed files
with
230 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
projects/elements-demo/src/app/core/layout/responsive-layout.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ResponsiveLayoutService } from './responsive-layout.service'; | ||
|
||
describe('ResponsiveLayoutService', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const service: ResponsiveLayoutService = TestBed.get( | ||
ResponsiveLayoutService | ||
); | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
projects/elements-demo/src/app/core/layout/responsive-layout.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; | ||
import { combineLatest, Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ResponsiveLayoutService { | ||
// basic | ||
isXSmallScreen: Observable<boolean>; | ||
isSmallScreen: Observable<boolean>; | ||
isMediumScreen: Observable<boolean>; | ||
isLargeScreen: Observable<boolean>; | ||
isXLargeScreen: Observable<boolean>; | ||
|
||
// derived | ||
columnCount: Observable<number>; | ||
isResponsiveLayout: Observable<boolean>; | ||
|
||
constructor(private breakpointObserver: BreakpointObserver) { | ||
this.isXSmallScreen = this.breakpointObserver | ||
.observe([Breakpoints.XSmall]) | ||
.pipe(map(result => result.matches)); | ||
this.isSmallScreen = this.breakpointObserver | ||
.observe([Breakpoints.Small]) | ||
.pipe(map(result => result.matches)); | ||
this.isMediumScreen = this.breakpointObserver | ||
.observe([Breakpoints.Medium]) | ||
.pipe(map(result => result.matches)); | ||
this.isLargeScreen = this.breakpointObserver | ||
.observe([Breakpoints.Large]) | ||
.pipe(map(result => result.matches)); | ||
this.isXLargeScreen = this.breakpointObserver | ||
.observe([Breakpoints.XLarge]) | ||
.pipe(map(result => result.matches)); | ||
|
||
this.columnCount = combineLatest([ | ||
this.isXSmallScreen, | ||
this.isSmallScreen, | ||
this.isMediumScreen, | ||
this.isLargeScreen | ||
]).pipe( | ||
map(([isXSmall, isSmall, isMedium, isLarge]) => | ||
isXSmall ? 1 : isSmall ? 2 : isMedium ? 2 : isLarge ? 3 : 4 | ||
) | ||
); | ||
|
||
this.isResponsiveLayout = this.breakpointObserver | ||
.observe([Breakpoints.XSmall, Breakpoints.Small]) | ||
.pipe(map(result => result.matches)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
import { SharedModule } from '../../shared/shared.module'; | ||
|
||
import { HomeComponent } from './home/home.component'; | ||
|
||
@NgModule({ | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
declarations: [HomeComponent], | ||
imports: [SharedModule], | ||
imports: [SharedModule, RouterModule], | ||
exports: [HomeComponent] | ||
}) | ||
export class HomeModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 56 additions & 2 deletions
58
projects/elements-demo/src/app/features/home/home/home.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,66 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { ResponsiveLayoutService } from '../../../core/layout/responsive-layout.service'; | ||
|
||
const FEATURES = [ | ||
{ | ||
title: 'Lightweight', | ||
subtitle: | ||
'The library is extremely lightweight, all in all it is less than 5kb (or 1.5kb gzipped), epic!', | ||
icon: 'cloud_queue' | ||
}, | ||
{ | ||
title: 'Simple API', | ||
subtitle: | ||
'Just grab *axLazyElement directive set the element bundle url and you are ready to go!', | ||
icon: 'sentiment_satisfied_alt' | ||
}, | ||
{ | ||
title: 'Loading indicator support', | ||
subtitle: | ||
'Define optional custom loading indicator to be displayed before the element is ready...', | ||
icon: 'hourglass_empty' | ||
}, | ||
{ | ||
title: 'Lazy loading', | ||
subtitle: | ||
'This is as lazy as it gets! The request to load a bundle will be triggered only when the element appears in the template of some component!', | ||
icon: 'schedule' | ||
}, | ||
{ | ||
title: 'Angular template binding', | ||
subtitle: | ||
'Use standard Angular template binding for both properties and events as you would for any other Angular component!', | ||
icon: 'view_compact' | ||
}, | ||
{ | ||
title: 'Performance', | ||
subtitle: | ||
'Elements are loaded just once, even if you use it on multiple pages or even multiple time on single page!', | ||
icon: 'offline_bolt' | ||
}, | ||
{ | ||
title: 'Supports everything', | ||
subtitle: | ||
'Angular elements, web components, basically any custom element you can get your hands on...', | ||
icon: 'category' | ||
} | ||
]; | ||
|
||
@Component({ | ||
selector: 'demo-home', | ||
templateUrl: './home.component.html', | ||
styleUrls: ['./home.component.scss'] | ||
}) | ||
export class HomeComponent implements OnInit { | ||
constructor() {} | ||
columnCount: Observable<number>; | ||
|
||
features = FEATURES; | ||
|
||
constructor(private responsiveLayoutService: ResponsiveLayoutService) {} | ||
|
||
ngOnInit() {} | ||
ngOnInit() { | ||
this.columnCount = this.responsiveLayoutService.columnCount; | ||
} | ||
} |
Oops, something went wrong.