src/app/component/message/message.component.ts
| changeDetection | ChangeDetectionStrategy.OnPush |
| host | { |
| selector | stbui-message |
| styleUrls | ./message.component.scss |
| templateUrl | ./message.component.html |
Properties |
|
Methods |
Inputs |
Accessors |
constructor(changeDetectorRef: ChangeDetectorRef)
|
||||||
|
Parameters :
|
| color | |
Type : "primary" | "accent" | "warn"
|
|
| icon | |
Type : string
|
|
Default value : 'info_outline'
|
|
| label | |
Type : string
|
|
| opened | |
Type : boolean
|
|
| sublabel | |
Type : string
|
|
| close |
close()
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| open |
open()
|
|
Returns :
void
|
| toggle |
toggle()
|
|
Returns :
void
|
| Private _opened |
Type : boolean
|
Default value : true
|
| opened | ||||||
getopened()
|
||||||
setopened(opened: boolean)
|
||||||
|
Parameters :
Returns :
void
|
import {
Component,
OnInit,
Input,
ChangeDetectionStrategy,
ChangeDetectorRef
} from '@angular/core';
@Component({
selector: 'stbui-message',
templateUrl: './message.component.html',
styleUrls: ['./message.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
class: 'stbui-message',
'[class.mat-primary]': 'color==="primary"',
'[class.mat-accent]': 'color==="accent"',
'[class.mat-warn]': 'color==="warn"'
}
})
export class MessageComponent implements OnInit {
private _opened: boolean = true;
@Input() label: string;
@Input() sublabel: string;
@Input() color: 'primary' | 'accent' | 'warn';
@Input('icon') icon: string = 'info_outline';
@Input('opened')
set opened(opened: boolean) {
if (opened) {
this.open();
} else {
this.close();
}
}
get opened(): boolean {
return this._opened;
}
constructor(private changeDetectorRef: ChangeDetectorRef) {}
ngOnInit() {}
open(): void {
if (!this._opened) {
this._opened = true;
this.changeDetectorRef.markForCheck();
}
}
close(): void {
if (this._opened) {
this._opened = false;
this.changeDetectorRef.markForCheck();
}
}
toggle(): void {
if (this._opened) {
this.close();
} else {
this.open();
}
}
}
<div class="stbui-message-wrapper" *ngIf="opened">
<mat-icon class="stbui-message-icon">{{icon}}</mat-icon>
<div class="stbui-message-labels">
<div class="stbui-message-label" *ngIf="label">{{label}}</div>
<div class="stbui-message-sublabel" *ngIf="sublabel">{{sublabel}}</div>
</div>
<ng-content select="[stbui-message-actions]"></ng-content>
</div>
./message.component.scss
:host {
display: block;
}
.stbui-message {
&-wrapper {
display: flex;
flex-direction: row;
align-items: center;
align-content: center;
justify-content: start;
padding: 8px 16px;
min-height: 52px;
max-width: 100%;
}
&-icon {
margin-right: 16px;
}
&-labels {
flex: 1;
}
&-label {
font-size: 14px;
font-weight: 600;
line-height: 24px;
}
}