Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit c36ea03

Browse files
fix(api, class, style): remove deprecated selectors
* all [style], [style.xxx], [class], and [class.xxx] selectors have been removed * only ngStyle and ngClass selectors support responsive suffices * now use of raw `style` attribute will NOT instantiate a StyleDirective * now use of raw `class` attribute will NOT instantiate a ClassDirective * The `ClassDirective` now simply adds responsive enhancements to the core `NgClass` directive * The `StyleDirective` now simply adds responsive enhancements to the core `NgStyle` directive * Added missing [ngStyle.md] selector * Added `isBrowser()` universal checks for `getAttribute()` and `getStyle()` queries Fixes #410, #408, #273. Closes #418. BREAKING CHANGES * **ngStyle**, **ngClass** should be used for responsive selectors and changes. Raw `style` and `class` attributes no longer support responsive suffices. ```html <div fxLayout [class.xs]="['xs-1', 'xs-2']" [style]="{'font-size': '10px', 'margin-left' : '13px'}" [style.xs]="{'font-size': '16px'}" [style.md]="{'font-size': '12px'}"> </div> ``` ```html <div fxLayout [ngClass.xs]="['xs-1', 'xs-2']" [ngStyle]="{'font-size': '10px', 'margin-left' : '13px'}" [ngStyle.xs]="{'font-size': '16px'}" [ngStyle.md]="{'font-size': '12px'}"> </div> ```
1 parent 5f198a3 commit c36ea03

File tree

12 files changed

+236
-251
lines changed

12 files changed

+236
-251
lines changed

package.json

+10-13
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@
99
"url": "git+https://github.com/angular/flex-layout.git"
1010
},
1111
"scripts": {
12-
"api": "gulp api-docs",
13-
"build": "gulp :publish:build-releases",
14-
"closure": "./scripts/closure-compiler/build-devapp-bundle.sh",
15-
"demo-app": "gulp serve:devapp",
16-
"docs": "gulp docs",
17-
"deploy": "gulp deploy:devapp",
18-
"stage": "gulp stage-deploy:devapp",
19-
"stylelint": "gulp lint",
20-
"test": "gulp test",
21-
"tslint": "gulp lint",
22-
"webdriver-manager": "webdriver-manager",
23-
"universal": "gulp universal:build",
24-
"universal:test": "gulp ci:prerender"
12+
"demo:bundle": "./scripts/closure-compiler/build-devapp-bundle.sh",
13+
"demo:serve": "gulp serve:devapp",
14+
"demo:stage": "gulp stage-deploy:devapp",
15+
"docs:build": "gulp docs",
16+
"docs:build:api": "gulp api-docs",
17+
"lib:build": "gulp :publish:build-releases",
18+
"lib:lint": "gulp lint",
19+
"lib:test": "gulp test",
20+
"universal:build": "gulp universal:build",
21+
"universal:prerender": "gulp ci:prerender"
2522
},
2623
"version": "2.0.0-beta.9",
2724
"license": "MIT",

scripts/closure-compiler/build-devapp-bundle.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Script that bundles the dev-app using the Google Closure compiler.
4-
# This is script is used to verify closure-compatibility of all Material components.
4+
# This is script is used to verify closure-compatibility of all Flex-Layout components.
55

66
set -e -o pipefail
77

src/demo-app/app/docs-layout-responsive/responsiveStyle.demo.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {Component} from '@angular/core';
1717
<div
1818
fxFlex
1919
class="fxClass-all"
20-
class.xs="fxClass-xs"
21-
[class.sm]="{'fxClass-sm': hasStyle}"
22-
[class.md]="{'fxClass-md': hasStyle, 'fxClass-md2': hasStyle}"
23-
[class.lg]="['fxClass-lg', 'fxClass-lg2']">
20+
ngClass.xs="fxClass-xs"
21+
[ngClass.sm]="{'fxClass-sm': hasStyle}"
22+
[ngClass.md]="{'fxClass-md': hasStyle, 'fxClass-md2': hasStyle}"
23+
[ngClass.lg]="['fxClass-lg', 'fxClass-lg2']">
2424
Sample Text #1
2525
<br/>
2626
<md-checkbox
@@ -39,10 +39,10 @@ import {Component} from '@angular/core';
3939
&lt;div
4040
fxFlex
4141
class="fxClass-all"
42-
class.xs="fxClass-xs"
43-
[class.sm]="&#123;'fxClass-sm': hasStyle&#125;"
44-
[class.md]="&#123;'fxClass-md': hasStyle, 'fxClass-md2': hasStyle&#125;"
45-
[class.lg]="['fxClass-lg', 'fxClass-lg2']"&gt;
42+
ngClass.xs="fxClass-xs"
43+
[ngClass.sm]="&#123;'fxClass-sm': hasStyle&#125;"
44+
[ngClass.md]="&#123;'fxClass-md': hasStyle, 'fxClass-md2': hasStyle&#125;"
45+
[ngClass.lg]="['fxClass-lg', 'fxClass-lg2']"&gt;
4646
&lt;/div&gt;
4747
</pre>
4848
</md-card-content>
@@ -54,10 +54,10 @@ import {Component} from '@angular/core';
5454
class="coloredContainerX box">
5555
<div fxFlex
5656
style="font-style: italic"
57-
[style.xs]="{'font-size.px': 10, 'background-color': '#ddd', color: 'blue'}"
58-
[style.sm]="{'font-size.px': 20, 'background-color': 'grey', color: '#482b00'}"
59-
[style.md]="{'font-size.px': 30, 'background-color': 'black', color: 'orange'}"
60-
[style.lg]="styleLgExp">
57+
[ngStyle.xs]="{'font-size.px': 10, 'background-color': '#ddd', color: 'blue'}"
58+
[ngStyle.sm]="{'font-size.px': 20, 'background-color': 'grey', color: '#482b00'}"
59+
[ngStyle.md]="{'font-size.px': 30, 'background-color': 'black', color: 'orange'}"
60+
[ngStyle.lg]="styleLgExp">
6161
Sample Text #2
6262
</div>
6363
</div>
@@ -67,10 +67,10 @@ import {Component} from '@angular/core';
6767
<pre>
6868
&lt;div
6969
style="font-style: italic"
70-
[style.xs]="&#123;'font-size.px': 10, color: 'blue'&#125;"
71-
[style.sm]="&#123;'font-size.px': 20, color: 'lightblue'&#125;"
72-
[style.md]="&#123;'font-size.px': 30, color: 'orange'&#125;"
73-
[style.lg]="styleLgExp"&gt;
70+
[ngStyle.xs]="&#123;'font-size.px': 10, color: 'blue'&#125;"
71+
[ngStyle.sm]="&#123;'font-size.px': 20, color: 'lightblue'&#125;"
72+
[ngStyle.md]="&#123;'font-size.px': 30, color: 'orange'&#125;"
73+
[ngStyle.lg]="styleLgExp"&gt;
7474
&lt;/div&gt;
7575
</pre>
7676
</md-card-content>

src/demo-app/app/github-issues/issue.197.demo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import {Component} from '@angular/core';
1818
<div class="box1"
1919
fxFlexFill
2020
style="font-size:12px; color:black; text-align:left;"
21-
[style.sm]="{'font-size': '16px', color: '#a63db8', 'text-align': 'center'}"
21+
[ngStyle.sm]="{'font-size': '16px', color: '#a63db8', 'text-align': 'center'}"
2222
ngStyle.md="font-size: 24px; color : #0000ff; text-align: right;">
2323
&lt;div fxFlexFill <br/>
2424
&nbsp;&nbsp;&nbsp;&nbsp;style="font-size:10px; color:black; text-align:'left';"<br/>
25-
&nbsp;&nbsp;&nbsp;&nbsp;[style.sm]="&#123;'font-size':'16px', color:#a63db8,
25+
&nbsp;&nbsp;&nbsp;&nbsp;[ngStyle.sm]="&#123;'font-size':'16px', color:#a63db8,
2626
text-align:'center' &#125;"<br/>
2727
&nbsp;&nbsp;&nbsp;&nbsp;ngStyle.md="font-size:24px; color:#00f;"
2828
text-align:'right'&gt;<br/>

src/demo-app/app/shared/media-query-status.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnDestroy} from '@angular/core';
1+
import {Component, OnDestroy, OnInit} from '@angular/core';
22
import {Subscription} from 'rxjs/Subscription';
33

44
import {MediaChange} from '@angular/flex-layout';
@@ -28,20 +28,24 @@ import {ObservableMedia} from '@angular/flex-layout';
2828
}`
2929
]
3030
})
31-
export class MediaQueryStatus implements OnDestroy {
31+
export class MediaQueryStatus implements OnDestroy, OnInit {
3232
private _watcher: Subscription;
3333
activeMediaQuery: string;
3434

35-
constructor(media$: ObservableMedia) {
36-
this.watchMediaQueries(media$);
35+
constructor(private media$: ObservableMedia) {
36+
37+
}
38+
39+
ngOnInit() {
40+
this.watchMediaQueries();
3741
}
3842

3943
ngOnDestroy() {
4044
this._watcher.unsubscribe();
4145
}
4246

43-
private watchMediaQueries(media$: ObservableMedia) {
44-
this._watcher = media$.subscribe((change: MediaChange) => {
47+
private watchMediaQueries() {
48+
this._watcher = this.media$.subscribe((change: MediaChange) => {
4549
if (change.mediaQuery.indexOf('orientation') > -1) { return; }
4650
let value = change ? `'${change.mqAlias}' = (${change.mediaQuery})` : '';
4751
this.activeMediaQuery = value;

src/lib/api/core/base-adapter.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ import {MediaMonitor} from '../../media-query/media-monitor';
1919
*/
2020
export class BaseFxDirectiveAdapter extends BaseFxDirective {
2121

22+
/**
23+
* Does this directive have 1 or more responsive keys defined
24+
* Note: we exclude the 'baseKey' key (which is NOT considered responsive)
25+
*/
26+
public hasResponsiveAPI() {
27+
const totalKeys = Object.keys(this._inputMap).length;
28+
const baseValue = this._inputMap[this._baseKey];
29+
return (totalKeys - (!!baseValue ? 1 : 0)) > 0;
30+
}
31+
2232
/**
2333
* Accessor to determine which @Input property is "active"
2434
* e.g. which property value will be used.
@@ -127,13 +137,4 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective {
127137
this._inputMap[key] = source;
128138
}
129139

130-
/**
131-
* Does this directive have 1 or more responsive keys defined
132-
* Note: we exclude the 'baseKey' key (which is NOT considered responsive)
133-
*/
134-
public get usesResponsiveAPI() {
135-
const totalKeys = Object.keys(this._inputMap).length;
136-
const baseValue = this._inputMap[this._baseKey];
137-
return (totalKeys - (!!baseValue ? 1 : 0)) > 0;
138-
}
139140
}

src/lib/api/core/base.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
lookupStyle,
1717
lookupInlineStyle,
1818
applyStyleToElement,
19-
applyStyleToElements
19+
applyStyleToElements, lookupAttributeValue
2020
} from '../../utils/style-utils';
2121

2222
import {ResponsiveActivation, KeyOptions} from '../core/responsive-activation';
@@ -25,7 +25,6 @@ import {MediaQuerySubscriber} from '../../media-query/media-change';
2525

2626
/** Abstract base class for the Layout API styling directives. */
2727
export abstract class BaseFxDirective implements OnDestroy, OnChanges {
28-
2928
get hasMediaQueryListener() {
3029
return !!this._mqActivation;
3130
}
@@ -137,6 +136,14 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
137136
return lookupStyle(source || this.nativeElement, 'display');
138137
}
139138

139+
/**
140+
* Quick accessor to raw attribute value on the target DOM element
141+
*/
142+
protected _getAttributeValue(attribute: string,
143+
source: HTMLElement = this.nativeElement): string {
144+
return lookupAttributeValue(source || this.nativeElement, attribute);
145+
}
146+
140147
/**
141148
* Determine the DOM element's Flexbox flow (flex-direction).
142149
*
@@ -222,6 +229,17 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
222229
return buffer;
223230
}
224231

232+
/**
233+
* Does this directive have 1 or more responsive keys defined
234+
* Note: we exclude the 'baseKey' key (which is NOT considered responsive)
235+
*/
236+
public hasResponsiveAPI(baseKey: string) {
237+
const totalKeys = Object.keys(this._inputMap).length;
238+
const baseValue = this._inputMap[baseKey];
239+
return (totalKeys - (!!baseValue ? 1 : 0)) > 0;
240+
}
241+
242+
225243
/**
226244
* Fast validator for presence of attribute on the host element
227245
*/

src/lib/api/ext/class.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('class directive', () => {
4747
});
4848

4949
['xs', 'sm', 'md', 'lg'].forEach(mq => {
50-
const selector = `class-${mq}`;
50+
const selector = `ngClass-${mq}`;
5151

5252
it(`should apply '${selector}' with '${mq}' media query`, () => {
5353
createTestComponent(`<div ngClass.${mq}="${selector}"></div>`);
@@ -64,7 +64,7 @@ describe('class directive', () => {
6464
expectNativeEl(fixture).toHaveCssClass('class2');
6565
});
6666

67-
it('should override base `class` values with responsive values', () => {
67+
it('should override base `class` values with responsive ngClass string', () => {
6868
createTestComponent(`<div class="class0" ngClass.xs="what class2"></div>`);
6969

7070
expectNativeEl(fixture).toHaveCssClass('class0');
@@ -73,7 +73,7 @@ describe('class directive', () => {
7373

7474
// the CSS classes listed in the string (space delimited) are added,
7575
matchMedia.activate('xs');
76-
expectNativeEl(fixture).toHaveCssClass('class0');
76+
expectNativeEl(fixture).not.toHaveCssClass('class0');
7777
expectNativeEl(fixture).toHaveCssClass('what');
7878
expectNativeEl(fixture).toHaveCssClass('class2');
7979

@@ -83,7 +83,7 @@ describe('class directive', () => {
8383
expectNativeEl(fixture).not.toHaveCssClass('class2');
8484
});
8585

86-
it('should override base `class` values with responsive values', () => {
86+
it('should override base `class` values with responsive ngClass map', () => {
8787
createTestComponent(`
8888
<div class="class0" [ngClass.xs]="{'what':true, 'class2':true, 'class0':false}"></div>
8989
`);
@@ -527,7 +527,7 @@ describe('binding to CSS class list', () => {
527527
detectChangesAndExpectClassName(`init foo`);
528528
}));
529529

530-
it('should co-operate with the class attribute and class.name binding', async(() => {
530+
it('should co-operate with the class attribute and ngClass.name binding', async(() => {
531531
const template =
532532
'<div class="init foo" [ngClass]="objExpr" [class.baz]="condition"></div>';
533533
fixture = createTestComponent(template);

0 commit comments

Comments
 (0)