-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: theme styles scoping example, unified theme mixing naming
- Loading branch information
1 parent
c4fda4b
commit ec971ae
Showing
22 changed files
with
196 additions
and
15 deletions.
There are no files selected for viewing
Empty file.
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
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
2 changes: 1 addition & 1 deletion
2
src/app/examples/stock-market/stock-market.component.sccs-theme.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
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,4 @@ | ||
<div> | ||
<h1>child's h1<br>should be without style</h1> | ||
<h2>child works!</h2> | ||
</div> |
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,4 @@ | ||
div { | ||
border: 1px solid; | ||
padding: 20px; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/app/examples/theming/child/child.component.scss-theme.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,15 @@ | ||
@import '~@angular/material/theming'; | ||
|
||
@mixin anms-child-component-theme($theme) { | ||
$warn: map-get($theme, warn); | ||
|
||
anms-child { | ||
>div { | ||
border-color: mat-color($warn); | ||
|
||
>h2 { | ||
color: mat-color($warn) | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ChildComponent } from './child.component'; | ||
|
||
describe('ChildComponent', () => { | ||
let component: ChildComponent; | ||
let fixture: ComponentFixture<ChildComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ChildComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ChildComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,15 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'anms-child', | ||
templateUrl: './child.component.html', | ||
styleUrls: ['./child.component.scss'] | ||
}) | ||
export class ChildComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
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,32 @@ | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<h1>Theme scoping with nested components</h1> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<p> | ||
Theme styles are not imported in component's <code>stylesUrls</code> | ||
property of <code>@Component</code> decorator but in the main | ||
<code>styles.scss</code> file. Because of this, theme styles are | ||
<strong>NOT</strong> scoped to the component automatically. | ||
</p> | ||
<p> | ||
We have to use <strong>specific</strong> selectors to prevent styles | ||
from leaking into child components. This can be achieved by using | ||
<code>> (child selectors)</code> in css rules to enhance their | ||
specificity. For example checkout theme file of this component: | ||
</p> | ||
<pre> | ||
{{themeSrc}} | ||
</pre> | ||
</div> | ||
<div class="col-md-6"> | ||
<div class="example"> | ||
<h1>parent works!</h1> | ||
<anms-child></anms-child> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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,9 @@ | ||
pre { | ||
margin: 0; | ||
} | ||
|
||
.example { | ||
border: 1px solid; | ||
padding: 20px; | ||
margin: 0 0 20px 0; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/app/examples/theming/parent/parent.component.scss-theme.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,21 @@ | ||
@import '~@angular/material/theming'; | ||
|
||
@mixin anms-parent-component-theme($theme) { | ||
$accent: map-get($theme, accent); | ||
|
||
anms-parent { | ||
>.container { | ||
>.row { | ||
>.col-md-6 { | ||
>.example { | ||
border-color: mat-color($accent); | ||
|
||
>h1 { | ||
color: mat-color($accent) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ParentComponent } from './parent.component'; | ||
import { ChildComponent } from '../child/child.component'; | ||
|
||
describe('ParentComponent', () => { | ||
let component: ParentComponent; | ||
let fixture: ComponentFixture<ParentComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ParentComponent, ChildComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ParentComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'anms-parent', | ||
templateUrl: './parent.component.html', | ||
styleUrls: ['./parent.component.scss'] | ||
}) | ||
export class ParentComponent implements OnInit { | ||
|
||
themeSrc: string = require('!raw-loader!./parent.component.scss-theme.scss'); | ||
|
||
constructor() {} | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
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
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