Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/angular/styling/src/app/page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import { TextComponent } from './text.component';
selector: 'page',
standalone: true,
imports: [TextStaticComponent, TextComponent],
styles: [
`
text {
--text-font-size: 15px;
--text-color: blue;
}
`,
],
template: `
<static-text></static-text>
<static-text type="error"></static-text>
<static-text type="warning"></static-text>
<text [font]="15" color="blue">This a a blue text</text>
<text>This is a blue text</text>
`,
})
export class PageComponent {}
41 changes: 20 additions & 21 deletions apps/angular/styling/src/app/static-text.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, Input } from '@angular/core';
import { Component, HostBinding, Input } from '@angular/core';
import { TextComponent } from './text.component';

export type StaticTextType = 'normal' | 'warning' | 'error';
Expand All @@ -8,26 +8,25 @@ export type StaticTextType = 'normal' | 'warning' | 'error';
selector: 'static-text',
standalone: true,
imports: [TextComponent],
template: `
<text [font]="font" [color]="color">This is a static text</text>
`,
styles: [
`
:host {
&.warning text {
--text-font-size: 25px;
--text-color: orange;
}

&.error text {
--text-font-size: 30px;
--text-color: red;
}
}
`,
],
template: `<text>This is a static text</text>`,
})
export class TextStaticComponent {
@Input() set type(type: StaticTextType) {
switch (type) {
case 'error': {
this.font = 30;
this.color = 'red';
break;
}
case 'warning': {
this.font = 25;
this.color = 'orange';
break;
}
}
}

font = 10;
color = 'black';
@HostBinding('class')
@Input()
type: StaticTextType = 'normal';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice. Really like it. Never thought of doing hostBinding on class 😍

}
17 changes: 11 additions & 6 deletions apps/angular/styling/src/app/text.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, Input } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'text',
standalone: true,
styles: [
`
:host {
font-size: var(--text-font-size, 10px);
color: var(--text-color, black);
}
`,
],
template: `
<p style="font-size: {{ font }}px; color: {{ color }}">
<p>
<ng-content></ng-content>
</p>
`,
})
export class TextComponent {
@Input() font = 10;
@Input() color = 'black';
}
export class TextComponent {}