Skip to content

Commit e7af98b

Browse files
committed
wip no-conflict
1 parent dfc580d commit e7af98b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+380
-215
lines changed

src/lib/button-toggle/button-toggle.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
} from '@angular/core';
2020
import {NG_VALUE_ACCESSOR, ControlValueAccessor, FormsModule} from '@angular/forms';
2121
import {Observable} from 'rxjs/Observable';
22-
import {MdUniqueSelectionDispatcher, coerceBooleanProperty} from '../core';
22+
import {
23+
MdUniqueSelectionDispatcher,
24+
coerceBooleanProperty,
25+
DefaultStyleCompatibilityModeModule,
26+
} from '../core';
27+
2328

2429
export type ToggleType = 'checkbox' | 'radio';
2530

@@ -436,7 +441,7 @@ export class MdButtonToggle implements OnInit {
436441

437442

438443
@NgModule({
439-
imports: [FormsModule],
444+
imports: [FormsModule, DefaultStyleCompatibilityModeModule],
440445
exports: [MdButtonToggleGroup, MdButtonToggleGroupMultiple, MdButtonToggle],
441446
declarations: [MdButtonToggleGroup, MdButtonToggleGroupMultiple, MdButtonToggle],
442447
})

src/lib/button/button.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
ModuleWithProviders,
1111
} from '@angular/core';
1212
import {CommonModule} from '@angular/common';
13-
import {MdRippleModule, coerceBooleanProperty} from '../core';
13+
import {MdRippleModule, coerceBooleanProperty, DefaultStyleCompatibilityModeModule} from '../core';
14+
1415

1516
// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener.
1617
// TODO(kara): Convert attribute selectors to classes when attr maps become available
@@ -157,7 +158,7 @@ export class MdAnchor extends MdButton {
157158

158159

159160
@NgModule({
160-
imports: [CommonModule, MdRippleModule],
161+
imports: [CommonModule, MdRippleModule, DefaultStyleCompatibilityModeModule],
161162
exports: [MdButton, MdAnchor],
162163
declarations: [MdButton, MdAnchor],
163164
})

src/lib/card/card-header.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
<ng-content select="[md-card-avatar]"></ng-content>
1+
<ng-content select="[md-card-avatar], [mat-card-avatar]"></ng-content>
22
<div class="md-card-header-text">
3-
<ng-content select="md-card-title, md-card-subtitle"></ng-content>
3+
<ng-content
4+
select="md-card-title, mat-card-title, md-card-subtitle, mat-card-subtitle"></ng-content>
45
</div>
56
<ng-content></ng-content>

src/lib/card/card-title-group.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div>
2-
<ng-content select="md-card-title, md-card-subtitle"></ng-content>
2+
<ng-content
3+
select="md-card-title, mat-card-title, md-card-subtitle, mat-card-subtitle"></ng-content>
34
</div>
45
<ng-content select="img"></ng-content>
56
<ng-content></ng-content>

src/lib/card/card.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,46 @@ import {
66
ChangeDetectionStrategy,
77
Directive
88
} from '@angular/core';
9+
import {DefaultStyleCompatibilityModeModule} from '../core';
910

1011

1112
/**
1213
* Content of a card, needed as it's used as a selector in the API.
1314
*/
1415
@Directive({
15-
selector: 'md-card-content'
16+
selector: 'md-card-content, mat-card-content'
1617
})
1718
export class MdCardContent {}
1819

1920
/**
2021
* Title of a card, needed as it's used as a selector in the API.
2122
*/
2223
@Directive({
23-
selector: 'md-card-title'
24+
selector: 'md-card-title, mat-card-title'
2425
})
2526
export class MdCardTitle {}
2627

2728
/**
2829
* Sub-title of a card, needed as it's used as a selector in the API.
2930
*/
3031
@Directive({
31-
selector: 'md-card-subtitle'
32+
selector: 'md-card-subtitle, mat-card-subtitle'
3233
})
3334
export class MdCardSubtitle {}
3435

3536
/**
3637
* Action section of a card, needed as it's used as a selector in the API.
3738
*/
3839
@Directive({
39-
selector: 'md-card-actions'
40+
selector: 'md-card-actions, mat-card-actions'
4041
})
4142
export class MdCardActions {}
4243

4344
/**
4445
* Footer of a card, needed as it's used as a selector in the API.
4546
*/
4647
@Directive({
47-
selector: 'md-card-footer'
48+
selector: 'md-card-footer, mat-card-footer'
4849
})
4950
export class MdCardFooter {}
5051

@@ -70,7 +71,7 @@ it also provides a number of preset styles for common card sections, including:
7071

7172
@Component({
7273
moduleId: module.id,
73-
selector: 'md-card',
74+
selector: 'md-card, mat-card',
7475
templateUrl: 'card.html',
7576
styleUrls: ['card.css'],
7677
encapsulation: ViewEncapsulation.None,
@@ -95,7 +96,7 @@ TODO(kara): update link to demo site when it exists
9596

9697
@Component({
9798
moduleId: module.id,
98-
selector: 'md-card-header',
99+
selector: 'md-card-header, mat-card-header',
99100
templateUrl: 'card-header.html',
100101
encapsulation: ViewEncapsulation.None,
101102
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -115,7 +116,7 @@ TODO(kara): update link to demo site when it exists
115116

116117
@Component({
117118
moduleId: module.id,
118-
selector: 'md-card-title-group',
119+
selector: 'md-card-title-group, mat-card-title-group',
119120
templateUrl: 'card-title-group.html',
120121
encapsulation: ViewEncapsulation.None,
121122
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -124,6 +125,7 @@ export class MdCardTitleGroup {}
124125

125126

126127
@NgModule({
128+
imports: [DefaultStyleCompatibilityModeModule],
127129
exports: [
128130
MdCard, MdCardHeader, MdCardTitleGroup, MdCardContent, MdCardTitle, MdCardSubtitle,
129131
MdCardActions, MdCardFooter

src/lib/checkbox/checkbox.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
import {CommonModule} from '@angular/common';
1616
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
1717
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
18-
import {MdRippleModule} from '../core';
18+
import {MdRippleModule, DefaultStyleCompatibilityModeModule} from '../core';
19+
1920

2021
/**
2122
* Monotonically increasing integer used to auto-generate unique ids for checkbox components.
@@ -62,7 +63,7 @@ export class MdCheckboxChange {
6263
*/
6364
@Component({
6465
moduleId: module.id,
65-
selector: 'md-checkbox',
66+
selector: 'md-checkbox, mat-checkbox',
6667
templateUrl: 'checkbox.html',
6768
styleUrls: ['checkbox.css'],
6869
host: {
@@ -378,7 +379,7 @@ export class MdCheckbox implements ControlValueAccessor {
378379

379380

380381
@NgModule({
381-
imports: [CommonModule, MdRippleModule],
382+
imports: [CommonModule, MdRippleModule, DefaultStyleCompatibilityModeModule],
382383
exports: [MdCheckbox],
383384
declarations: [MdCheckbox],
384385
})
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {Component} from '@angular/core';
2+
import {async, TestBed} from '@angular/core/testing';
3+
import {MdCheckboxModule} from '../../checkbox/checkbox';
4+
import {NoConflictStyleCompatibilityMode} from './no-conflict-mode';
5+
6+
7+
fdescribe('Style compatibility', () => {
8+
9+
describe('in default mode', () => {
10+
beforeEach(async(() => {
11+
TestBed.configureTestingModule({
12+
imports: [MdCheckboxModule.forRoot()],
13+
declarations: [ComponentWithMdCheckbox, ComponentWithMatCheckbox],
14+
});
15+
16+
TestBed.compileComponents();
17+
}));
18+
19+
20+
it('should throw an error when trying to use the "mat-" prefix', () => {
21+
expect(() => {
22+
TestBed.createComponent(ComponentWithMatCheckbox);
23+
}).toThrowError(/The "mat-" prefix cannot be used out of ng-material v1 compatibility mode/);
24+
});
25+
});
26+
27+
describe('in no-conflict mode', () => {
28+
beforeEach(async(() => {
29+
TestBed.configureTestingModule({
30+
imports: [MdCheckboxModule.forRoot(), NoConflictStyleCompatibilityMode],
31+
declarations: [ComponentWithMdCheckbox, ComponentWithMatCheckbox],
32+
});
33+
34+
TestBed.compileComponents();
35+
}));
36+
37+
it('should not throw an error when trying to use the "mat-" prefix', () => {
38+
TestBed.createComponent(ComponentWithMatCheckbox);
39+
});
40+
41+
it('should throw an error when trying to use the "md-" prefix', () => {
42+
expect(() => {
43+
TestBed.createComponent(ComponentWithMdCheckbox);
44+
}).toThrowError(/The "md-" prefix cannot be used in ng-material v1 compatibility mode/);
45+
});
46+
});
47+
});
48+
49+
50+
@Component({ template: `<md-checkbox>Hungry</md-checkbox>` })
51+
class ComponentWithMdCheckbox { }
52+
53+
@Component({ template: `<mat-checkbox>Hungry</mat-checkbox>` })
54+
class ComponentWithMatCheckbox { }
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {NgModule, ModuleWithProviders, Directive, OpaqueToken, Inject} from '@angular/core';
2+
3+
4+
export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken('md-compatibiility-mode');
5+
6+
/** Selector that matches all elements that may have style collisions with material1. */
7+
export const MAT_ELEMENTS_SELECTOR = `
8+
mat-card,
9+
mat-card-actions,
10+
mat-card-content,
11+
mat-card-footer,
12+
mat-card-header,
13+
mat-card-subtitle,
14+
mat-card-title,
15+
mat-card-title-group,
16+
mat-checkbox,
17+
mat-chip,
18+
mat-dialog-container,
19+
mat-divider,
20+
mat-grid-list,
21+
mat-grid-tile,
22+
mat-grid-tile-footer,
23+
mat-grid-tile-header,
24+
mat-hint,
25+
mat-icon,
26+
mat-ink-bar,
27+
mat-input,
28+
mat-list,
29+
mat-list-item,
30+
mat-menu,
31+
mat-nav-list,
32+
mat-option,
33+
mat-placeholder,
34+
mat-progress-bar,
35+
mat-progress-circle,
36+
mat-radio-button,
37+
mat-radio-group,
38+
mat-select,
39+
mat-sidenav,
40+
mat-slider,
41+
mat-spinner,
42+
mat-tab,
43+
mat-toolbar
44+
`;
45+
46+
/** Directive that enforces that the `mat-` prefix cannot be used. */
47+
@Directive({selector: MAT_ELEMENTS_SELECTOR})
48+
export class MatPrefixEnforcer {
49+
constructor(@Inject(MATERIAL_COMPATIBILITY_MODE) isCompatibilityMode: boolean) {
50+
if (!isCompatibilityMode) {
51+
throw Error('The "mat-" prefix cannot be used out of ng-material v1 compatibility mode.');
52+
}
53+
}
54+
}
55+
56+
57+
@NgModule({
58+
declarations: [MatPrefixEnforcer],
59+
exports: [MatPrefixEnforcer],
60+
providers: [{
61+
provide: MATERIAL_COMPATIBILITY_MODE, useValue: false,
62+
}]
63+
})
64+
export class DefaultStyleCompatibilityModeModule {
65+
static forRoot(): ModuleWithProviders {
66+
return {
67+
ngModule: DefaultStyleCompatibilityModeModule,
68+
providers: [],
69+
};
70+
}
71+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {NgModule, ModuleWithProviders, Directive} from '@angular/core';
2+
import {MATERIAL_COMPATIBILITY_MODE} from './default-mode';
3+
4+
5+
/** Selector that matches all elements that may have style collisions with material1. */
6+
export const MD_ELEMENTS_SELECTOR = `
7+
md-card,
8+
md-card-actions,
9+
md-card-content,
10+
md-card-footer,
11+
md-card-header,
12+
md-card-subtitle,
13+
md-card-title,
14+
md-card-title-group,
15+
md-checkbox,
16+
md-chip,
17+
md-dialog-container,
18+
md-divider,
19+
md-grid-list,
20+
md-grid-tile,
21+
md-grid-tile-footer,
22+
md-grid-tile-header,
23+
md-hint,
24+
md-icon,
25+
md-ink-bar,
26+
md-input,
27+
md-list,
28+
md-list-item,
29+
md-menu,
30+
md-nav-list,
31+
md-option,
32+
md-placeholder,
33+
md-progress-bar,
34+
md-progress-circle,
35+
md-radio-button,
36+
md-radio-group,
37+
md-select,
38+
md-sidenav,
39+
md-slider,
40+
md-spinner,
41+
md-tab,
42+
md-toolbar
43+
`;
44+
45+
/** Directive that enforces that the `md-` prefix cannot be used. */
46+
@Directive({selector: MD_ELEMENTS_SELECTOR})
47+
export class MdPrefixEnforcer {
48+
constructor() {
49+
throw Error('The "md-" prefix cannot be used in ng-material v1 compatibility mode.');
50+
}
51+
}
52+
53+
54+
@NgModule({
55+
declarations: [MdPrefixEnforcer],
56+
exports: [MdPrefixEnforcer],
57+
providers: [{
58+
provide: MATERIAL_COMPATIBILITY_MODE, useValue: true,
59+
}],
60+
})
61+
export class NoConflictStyleCompatibilityMode {
62+
static forRoot(): ModuleWithProviders {
63+
return {
64+
ngModule: NoConflictStyleCompatibilityMode,
65+
providers: [],
66+
};
67+
}
68+
}

0 commit comments

Comments
 (0)