File tree Expand file tree Collapse file tree
apps/angular/13-highly-customizable-css/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ import { TextComponent } from './text.component';
88 imports : [ TextStaticComponent , TextComponent ] ,
99 template : `
1010 <static-text></static-text>
11- <static-text type ="error"></static-text>
12- <static-text type ="warning"></static-text>
13- <text [font]="15" color="blue ">This is a blue text</text>
11+ <static-text class ="error"></static-text>
12+ <static-text class ="warning"></static-text>
13+ <text class="font color">This is a blue text</text>
1414 ` ,
1515} )
1616export class PageComponent { }
Original file line number Diff line number Diff line change 11/* eslint-disable @angular-eslint/component-selector */
2- import { Component , computed , input } from '@angular/core' ;
2+ import { Component } from '@angular/core' ;
33import { TextComponent } from './text.component' ;
44
55export type StaticTextType = 'normal' | 'warning' | 'error' ;
@@ -8,31 +8,25 @@ export type StaticTextType = 'normal' | 'warning' | 'error';
88 selector : 'static-text' ,
99 imports : [ TextComponent ] ,
1010 template : `
11- <text [font]="font()" [color]="color()" >This is a static text</text>
11+ <text>This is a static text</text>
1212 ` ,
13- } )
14- export class TextStaticComponent {
15- type = input < StaticTextType > ( 'normal' ) ;
13+ styles : [
14+ `
15+ :host-context(.error) {
16+ --font: 30px;
17+ --color: red;
18+ }
1619
17- font = computed ( ( ) => {
18- switch ( this . type ( ) ) {
19- case 'error' :
20- return 30 ;
21- case 'warning' :
22- return 25 ;
23- default :
24- return 10 ;
25- }
26- } ) ;
20+ :host-context(.warning) {
21+ --font: 25px;
22+ --color: orange;
23+ }
2724
28- color = computed ( ( ) => {
29- switch ( this . type ( ) ) {
30- case 'error' :
31- return 'red' ;
32- case 'warning' :
33- return 'orange' ;
34- default :
35- return 'black' ;
36- }
37- } ) ;
38- }
25+ :host-context(.normal) {
26+ --font: 10px;
27+ --color: black;
28+ }
29+ ` ,
30+ ] ,
31+ } )
32+ export class TextStaticComponent { }
Original file line number Diff line number Diff line change 11/* eslint-disable @angular-eslint/component-selector */
2- import { Component , input } from '@angular/core' ;
2+ import { Component } from '@angular/core' ;
33
44@Component ( {
55 selector : 'text' ,
66 template : `
7- <p style="font-size: {{ font() }}px; color: {{ color() }}" >
7+ <p>
88 <ng-content />
99 </p>
1010 ` ,
11+ styles : [
12+ `
13+ p {
14+ font-size: var(--font, 10px);
15+ color: var(--color, black);
16+ }
17+
18+ :host-context(.font) {
19+ --font: 15px;
20+ }
21+
22+ :host-context(.color) {
23+ --color: blue;
24+ }
25+ ` ,
26+ ] ,
1127} )
12- export class TextComponent {
13- font = input ( 10 ) ;
14- color = input ( 'black' ) ;
15- }
28+ export class TextComponent { }
You can’t perform that action at this time.
0 commit comments