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

Commit dd7bb62

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 dd7bb62

File tree

11 files changed

+222
-237
lines changed

11 files changed

+222
-237
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/_module.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { Component } from '@angular/core';
44
selector: 'demos-docs-layout',
55
template: `
66
<demo-responsive-layout-direction class='small-demo'> </demo-responsive-layout-direction>
7-
<demo-responsive-row-column class='small-demo'> </demo-responsive-row-column>
8-
<demo-responsive-flex-directive class='small-demo'> </demo-responsive-flex-directive>
9-
<demo-responsive-flex-order class='small-demo'> </demo-responsive-flex-order>
10-
<demo-responsive-show-hide class='small-demo'> </demo-responsive-show-hide>
7+
<!--<demo-responsive-row-column class='small-demo'> </demo-responsive-row-column>-->
8+
<!--<demo-responsive-flex-directive class='small-demo'> </demo-responsive-flex-directive>-->
9+
<!--<demo-responsive-flex-order class='small-demo'> </demo-responsive-flex-order>-->
10+
<!--<demo-responsive-show-hide class='small-demo'> </demo-responsive-show-hide>-->
1111
<demo-responsive-style class='small-demo'> </demo-responsive-style>
1212
`
1313
})

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)