Skip to content
Snippets Groups Projects
canvas-element-component.directive.ts 919 B
Newer Older
  • Learn to ignore specific revisions
  • jojohoch's avatar
    jojohoch committed
      Directive, OnInit
    
    } from '@angular/core';
    
    rhenck's avatar
    rhenck committed
    import { UnitUIElement } from './unit';
    
    rhenck's avatar
    rhenck committed
    export abstract class CanvasElementComponent implements OnInit {
    
    jojohoch's avatar
    jojohoch committed
      elementModel!: UnitUIElement;
      style!: Record<string, string>;
    
    rhenck's avatar
    rhenck committed
    
      ngOnInit(): void {
        this.updateStyle();
      }
    
      updateStyle(newProperties: Record<string, string> = {}): void {
    
        this.style = {
    
          width: `${this.elementModel.width}px`,
          height: `${this.elementModel.height}px`,
    
          'background-color': this.elementModel.backgroundColor,
          color: this.elementModel.fontColor,
          'font-family': this.elementModel.font,
          'font-size': `${this.elementModel.fontSize}px`,
          'font-weight': this.elementModel.bold ? 'bold' : '',
          'font-style': this.elementModel.italic ? 'italic' : '',
    
          'text-decoration': this.elementModel.underline ? 'underline' : '',
          ...this.style,
          ...newProperties