|
| 1 | +import { Component, OnInit, Inject, OnDestroy } from '@angular/core'; |
| 2 | +import { Subscription } from "rxjs/Subscription"; |
| 3 | +import 'rxjs/add/operator/filter'; |
| 4 | + |
| 5 | +import { MediaChange } from "../../../lib/media-query/media-change"; |
| 6 | +import { ObservableMedia } from "../../../lib/media-query/observable-media-service"; |
| 7 | + |
| 8 | +@Component({ |
| 9 | + selector: 'demo-responsive-style', |
| 10 | + styleUrls: [ |
| 11 | + '../demo-app/material2.css' |
| 12 | + ], |
| 13 | + template: ` |
| 14 | +
|
| 15 | + <md-card class="card-demo" > |
| 16 | + <md-card-title>Responsive Style</md-card-title> |
| 17 | + <md-card-subtitle> |
| 18 | + Use the fxClass and fxStyle APIs to responsively apply styles to elements: |
| 19 | + </md-card-subtitle> |
| 20 | +
|
| 21 | + <md-card-content> |
| 22 | + <div class="containerX"> |
| 23 | + <div fxLayout="row" fxFlex class="coloredContainerX box"> |
| 24 | + <div |
| 25 | + fxFlex |
| 26 | + class="fxClass-all" |
| 27 | + class.xs="fxClass-xs" |
| 28 | + [class.sm]="{'fxClass-sm': hasStyle}" |
| 29 | + [class.md]="{'fxClass-md': hasStyle, 'fxClass-md2': hasStyle}" |
| 30 | + [class.lg]="['fxClass-lg', 'fxClass-lg2']"> |
| 31 | + {{ activeMediaQueryAlias }} |
| 32 | + <md-checkbox |
| 33 | + [(ngModel)]="hasStyle" |
| 34 | + fxShow="false" |
| 35 | + [fxShow.sm]="true" |
| 36 | + [fxShow.md]="true"> |
| 37 | + Activate styles |
| 38 | + </md-checkbox> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + </md-card-content> |
| 43 | + <md-card-content> |
| 44 | + <pre> |
| 45 | + <div |
| 46 | + fxFlex |
| 47 | + class="fxClass-all" |
| 48 | + class.xs="fxClass-xs" |
| 49 | + [class.sm]="{'fxClass-sm': hasStyle}" |
| 50 | + [class.md]="{'fxClass-md': hasStyle, 'fxClass-md2': hasStyle}" |
| 51 | + [class.lg]="['fxClass-lg', 'fxClass-lg2']"> |
| 52 | + </div> |
| 53 | + </pre> |
| 54 | + </md-card-content> |
| 55 | +
|
| 56 | + <md-card-content> |
| 57 | + <div class="containerX"> |
| 58 | + <div fxLayout="row" fxFlex class="coloredContainerX box"> |
| 59 | + <div |
| 60 | + fxFlex |
| 61 | + style="font-style: italic" |
| 62 | + [style.xs]="{'font-size.px': 10, color: 'blue'}" |
| 63 | + [style.sm]="{'font-size.px': 20, color: 'lightblue'}" |
| 64 | + [style.md]="{'font-size.px': 30, color: 'orange'}" |
| 65 | + [style.lg]="styleLgExp"> |
| 66 | + {{ activeMediaQueryAlias }} |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </md-card-content> |
| 71 | + <md-card-content> |
| 72 | + <pre> |
| 73 | + <div |
| 74 | + style="font-style: italic" |
| 75 | + [style.xs]="{'font-size.px': 10, color: 'blue'}" |
| 76 | + [style.sm]="{'font-size.px': 20, color: 'lightblue'}" |
| 77 | + [style.md]="{'font-size.px': 30, color: 'orange'}" |
| 78 | + [style.lg]="styleLgExp"> |
| 79 | + </div> |
| 80 | + </pre> |
| 81 | + </md-card-content> |
| 82 | +
|
| 83 | +
|
| 84 | + <md-card-footer style="width:95%"> |
| 85 | + <div class="hint" >Active mediaQuery: <span style="padding-left: 20px; color: rgba(0, 0, 0, 0.54)">{{ activeMediaQuery }}</span></div> |
| 86 | + </md-card-footer> |
| 87 | + </md-card> |
| 88 | + ` |
| 89 | +}) |
| 90 | +export class DemoResponsiveStyle implements OnDestroy { |
| 91 | + private _watcher: Subscription; |
| 92 | + public activeMediaQuery = ""; |
| 93 | + public activeMediaQueryAlias = ""; |
| 94 | + public hasStyle: boolean = false; |
| 95 | + public styleLgExp = { |
| 96 | + 'font-size': '40px', |
| 97 | + color: 'lightgreen' |
| 98 | + }; |
| 99 | + |
| 100 | + constructor( private _media$:ObservableMedia ) { |
| 101 | + this._watcher = this._media$.subscribe((change: MediaChange) => { |
| 102 | + this.activeMediaQuery = change ? `'${change.mqAlias}' = ${change.mediaQuery} )` : ""; |
| 103 | + this.activeMediaQueryAlias = change.mqAlias; |
| 104 | + }); |
| 105 | + } |
| 106 | + |
| 107 | + ngOnDestroy() { |
| 108 | + this._watcher.unsubscribe(); |
| 109 | + } |
| 110 | +} |
0 commit comments