-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(cdk/layout): add BreakpointObserver example (#22828)
Also adds a layout page to the dev-app since it didn't have one
- Loading branch information
Showing
16 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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,25 @@ | ||
load("//tools:defaults.bzl", "ng_module") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ng_module( | ||
name = "layout", | ||
srcs = glob(["**/*.ts"]), | ||
assets = glob([ | ||
"**/*.html", | ||
"**/*.css", | ||
]), | ||
module_name = "@angular/components-examples/cdk/layout", | ||
deps = [ | ||
"//src/cdk/layout", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "source-files", | ||
srcs = glob([ | ||
"**/*.html", | ||
"**/*.css", | ||
"**/*.ts", | ||
]), | ||
) |
1 change: 1 addition & 0 deletions
1
...examples/cdk/layout/breakpoint-observer-overview/breakpoint-observer-overview-example.css
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 @@ | ||
/** No CSS for this example */ |
6 changes: 6 additions & 0 deletions
6
...xamples/cdk/layout/breakpoint-observer-overview/breakpoint-observer-overview-example.html
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,6 @@ | ||
<p> | ||
Resize your browser window to see the current screen size change. | ||
</p> | ||
<p> | ||
The current screen size is <strong>{{currentScreenSize}}</strong> | ||
</p> |
45 changes: 45 additions & 0 deletions
45
...-examples/cdk/layout/breakpoint-observer-overview/breakpoint-observer-overview-example.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,45 @@ | ||
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout'; | ||
import {Component, OnDestroy} from '@angular/core'; | ||
import {Subject} from 'rxjs'; | ||
import {takeUntil} from 'rxjs/operators'; | ||
|
||
/** @title Respond to viewport changes with BreakpointObserver */ | ||
@Component({ | ||
selector: 'breakpoint-observer-overview-example', | ||
templateUrl: 'breakpoint-observer-overview-example.html', | ||
styleUrls: ['breakpoint-observer-overview-example.css'] | ||
}) | ||
export class BreakpointObserverOverviewExample implements OnDestroy { | ||
destroyed = new Subject<void>(); | ||
currentScreenSize: string; | ||
|
||
// Create a map to display breakpoint names for demonstration purposes. | ||
displayNameMap = new Map([ | ||
[Breakpoints.XSmall, 'XSmall'], | ||
[Breakpoints.Small, 'Small'], | ||
[Breakpoints.Medium, 'Medium'], | ||
[Breakpoints.Large, 'Large'], | ||
[Breakpoints.XLarge, 'XLarge'], | ||
]); | ||
|
||
constructor(breakpointObserver: BreakpointObserver) { | ||
breakpointObserver.observe([ | ||
Breakpoints.XSmall, | ||
Breakpoints.Small, | ||
Breakpoints.Medium, | ||
Breakpoints.Large, | ||
Breakpoints.XLarge, | ||
]).pipe(takeUntil(this.destroyed)).subscribe(result => { | ||
for (const query of Object.keys(result.breakpoints)) { | ||
if (result.breakpoints[query]) { | ||
this.currentScreenSize = this.displayNameMap.get(query) ?? 'Unknown'; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.destroyed.next(); | ||
this.destroyed.complete(); | ||
} | ||
} |
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,23 @@ | ||
import {LayoutModule} from '@angular/cdk/layout'; | ||
import {NgModule} from '@angular/core'; | ||
import { | ||
BreakpointObserverOverviewExample, | ||
} from './breakpoint-observer-overview/breakpoint-observer-overview-example'; | ||
|
||
export {BreakpointObserverOverviewExample}; | ||
|
||
const EXAMPLES = [ | ||
BreakpointObserverOverviewExample, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ | ||
LayoutModule, | ||
], | ||
declarations: EXAMPLES, | ||
exports: EXAMPLES, | ||
entryComponents: EXAMPLES, | ||
}) | ||
export class CdkLayoutExamplesModule { | ||
} | ||
|
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
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,22 @@ | ||
load("//tools:defaults.bzl", "ng_module", "sass_binary") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ng_module( | ||
name = "layout", | ||
srcs = glob(["**/*.ts"]), | ||
assets = [ | ||
"layout-demo.html", | ||
":layout_demo_scss", | ||
], | ||
deps = [ | ||
"//src/cdk/layout", | ||
"//src/components-examples/cdk/layout", | ||
"@npm//@angular/router", | ||
], | ||
) | ||
|
||
sass_binary( | ||
name = "layout_demo_scss", | ||
src = "layout-demo.scss", | ||
) |
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,23 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
import {LayoutDemo} from './layout-demo'; | ||
import {CdkLayoutExamplesModule} from '@angular/components-examples/cdk/layout'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
CdkLayoutExamplesModule, | ||
RouterModule.forChild([{path: '', component: LayoutDemo}]), | ||
], | ||
declarations: [LayoutDemo], | ||
}) | ||
export class LayoutDemoModule { } |
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,2 @@ | ||
<h2>Respond to viewport changes with BreakpointObserver</h2> | ||
<breakpoint-observer-overview-example></breakpoint-observer-overview-example> |
Empty file.
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,17 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
|
||
|
||
@Component({ | ||
selector: 'layout-demo', | ||
templateUrl: 'layout-demo.html', | ||
styleUrls: ['layout-demo.css'], | ||
}) | ||
export class LayoutDemo { } |