File

src/app/component/message/message.component.ts

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
host {
}
selector stbui-message
styleUrls ./message.component.scss
templateUrl ./message.component.html

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(changeDetectorRef: ChangeDetectorRef)
Parameters :
Name Type Optional
changeDetectorRef ChangeDetectorRef No

Inputs

color
Type : "primary" | "accent" | "warn"
icon
Type : string
Default value : 'info_outline'
label
Type : string
opened
Type : boolean
sublabel
Type : string

Methods

close
close()
Returns : void
ngOnInit
ngOnInit()
Returns : void
open
open()
Returns : void
toggle
toggle()
Returns : void

Properties

Private _opened
Type : boolean
Default value : true

Accessors

opened
getopened()
setopened(opened: boolean)
Parameters :
Name Type Optional
opened boolean No
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;
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""