Skip to content
Snippets Groups Projects
element-style-properties.component.ts 9.16 KiB
Newer Older
import {
  Component, EventEmitter, Input, Output
} from '@angular/core';
import { ElementStyling } from 'common/interfaces/elements';

@Component({
  selector: 'aspect-element-style-properties',
  template: `
    <div fxLayout="column">
rhenck's avatar
rhenck committed
      <mat-checkbox *ngIf="styles.lineColoring !== undefined"
                    [checked]="$any(styles.lineColoring)"
                    (change)="updateModel.emit({ property: 'lineColoring', value: $event.checked })">
        {{'propertiesPanel.lineColoring' | translate }}
      </mat-checkbox>

      <mat-form-field *ngIf="styles.lineColoring && styles.lineColoringColor !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.lineColoringColor' | translate }}</mat-label>
        <input matInput type="text" [value]="styles.lineColoringColor"
               (input)="updateModel.emit({ property: 'lineColoringColor', value: $any($event.target).value })">
        <button mat-icon-button matSuffix (click)="lineColorInput.click()">
          <mat-icon>edit</mat-icon>
        </button>
      </mat-form-field>
      <input matInput type="color" hidden #lineColorInput
             [value]="styles.lineColoringColor"
             (input)="updateModel.emit({ property: 'lineColoringColor', value: $any($event.target).value })">

rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.selectionColor !== undefined" appearance="fill">
        <mat-label>{{'propertiesPanel.selectionColor' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="text" [value]="styles.selectionColor"
               (input)="updateModel.emit({ property: 'selectionColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
        <button mat-icon-button matSuffix (click)="selectionColorInput.click()">
          <mat-icon>edit</mat-icon>
        </button>
      </mat-form-field>
rhenck's avatar
rhenck committed
      <input matInput type="color" hidden #selectionColorInput
rhenck's avatar
rhenck committed
             [value]="styles.selectionColor"
rhenck's avatar
rhenck committed
             (input)="updateModel.emit({ property: 'selectionColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.borderRadius !== undefined" appearance="fill">
        <mat-label>{{'propertiesPanel.borderRadius' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="number" [ngModel]="styles.borderRadius"
               (input)="updateModel.emit({ property: 'borderRadius', value: $any($event.target).value })">
      </mat-form-field>

rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.itemBackgroundColor !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.itemBackgroundColor' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="text" [value]="styles.itemBackgroundColor"
               (input)="updateModel.emit({ property: 'itemBackgroundColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
        <button mat-icon-button matSuffix (click)="itembackgroundColorInput.click()">
          <mat-icon>edit</mat-icon>
        </button>
rhenck's avatar
rhenck committed
      <input matInput type="color" hidden #itembackgroundColorInput
rhenck's avatar
rhenck committed
             [value]="styles.itemBackgroundColor"
rhenck's avatar
rhenck committed
             (input)="updateModel.emit({ property: 'itemBackgroundColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.backgroundColor !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.backgroundColor' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="text" [value]="styles.backgroundColor"
               (input)="updateModel.emit({ property: 'backgroundColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
        <button mat-icon-button matSuffix (click)="backgroundColorInput.click()">
          <mat-icon>edit</mat-icon>
        </button>
rhenck's avatar
rhenck committed
      <input matInput type="color" hidden #backgroundColorInput
rhenck's avatar
rhenck committed
             [value]="styles.backgroundColor"
rhenck's avatar
rhenck committed
             (input)="updateModel.emit({ property: 'backgroundColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.borderColor !== undefined"
                      appearance="fill" class="mdInput textsingleline">
rhenck's avatar
rhenck committed
        <mat-label>{{'propertiesPanel.borderColor' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="text" [value]="styles.borderColor"
rhenck's avatar
rhenck committed
               (input)="updateModel.emit({ property: 'borderColor', value: $any($event.target).value })">
        <button mat-icon-button matSuffix (click)="borderColorInput.click()">
          <mat-icon>edit</mat-icon>
        </button>
      </mat-form-field>
rhenck's avatar
rhenck committed
      <input matInput type="color" hidden #borderColorInput
rhenck's avatar
rhenck committed
             [value]="styles.borderColor"
rhenck's avatar
rhenck committed
             (input)="updateModel.emit({ property: 'borderColor', value: $any($event.target).value })">

rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.fontColor !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.fontColor' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="text" [value]="styles.fontColor"
               (input)="updateModel.emit({ property: 'fontColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
        <button mat-icon-button matSuffix (click)="fontColorInput.click()">
          <mat-icon>edit</mat-icon>
        </button>
rhenck's avatar
rhenck committed
      <input matInput type="color" hidden #fontColorInput
rhenck's avatar
rhenck committed
             [value]="styles.fontColor"
rhenck's avatar
rhenck committed
             (input)="updateModel.emit({ property: 'fontColor', value: $any($event.target).value })">
rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.font !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.font' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="text" [value]="styles.font" disabled
               (input)="updateModel.emit({ property: 'font', value: $any($event.target).value })">
      </mat-form-field>
rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.fontSize !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.fontSize' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="number" #fontSize="ngModel" min="0"
rhenck's avatar
rhenck committed
               [ngModel]="styles.fontSize"
rhenck's avatar
rhenck committed
               (ngModelChange)="updateModel.emit({ property: 'fontSize',
                                                   value: $event,
                                                   isInputValid: fontSize.valid && $event !== null})">
      </mat-form-field>
rhenck's avatar
rhenck committed
      <mat-form-field *ngIf="styles.lineHeight !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.lineHeight' | translate }}</mat-label>
rhenck's avatar
rhenck committed
        <input matInput type="number" #lineHeight="ngModel" min="0"
rhenck's avatar
rhenck committed
               [ngModel]="styles.lineHeight"
rhenck's avatar
rhenck committed
               (ngModelChange)="updateModel.emit({ property: 'lineHeight',
                                                   value: $event,
                                                   isInputValid: lineHeight.valid && $event !== null })">
      </mat-form-field>
rhenck's avatar
rhenck committed
      <mat-checkbox *ngIf="styles.bold !== undefined"
                    [checked]="$any(styles.bold)"
                    (change)="updateModel.emit({ property: 'bold', value: $event.checked })">
        {{'propertiesPanel.bold' | translate }}
      </mat-checkbox>
rhenck's avatar
rhenck committed
      <mat-checkbox *ngIf="styles.italic !== undefined"
                    [checked]="$any(styles.italic)"
                    (change)="updateModel.emit({ property: 'italic', value: $event.checked })">
        {{'propertiesPanel.italic' | translate }}
      </mat-checkbox>
rhenck's avatar
rhenck committed
      <mat-checkbox *ngIf="styles.underline !== undefined"
                    [checked]="$any(styles.underline)"
                    (change)="updateModel.emit({ property: 'underline', value: $event.checked })">
        {{'propertiesPanel.underline' | translate }}
      </mat-checkbox>

      <mat-form-field *ngIf="styles.borderStyle !== undefined"
                      appearance="fill">
        <mat-label>{{'propertiesPanel.borderStyle' | translate }}</mat-label>
        <mat-select [value]="styles.borderStyle"
                    (selectionChange)="updateModel.emit({ property: 'borderStyle', value: $event.value })">
          <mat-option *ngFor="let option of ['solid', 'dotted', 'dashed',
                                         'double', 'groove', 'ridge', 'inset', 'outset']"
                      [value]="option">
            {{option}}
          </mat-option>
        </mat-select>
      </mat-form-field>

      <mat-form-field *ngIf="styles.borderWidth !== undefined"
                      appearance="fill" class="mdInput textsingleline">
        <mat-label>{{'propertiesPanel.borderWidth' | translate }}</mat-label>
        <input matInput type="number" #borderWidth="ngModel" min="0"
               [ngModel]="styles.borderWidth"
               (ngModelChange)="updateModel.emit({ property: 'borderWidth',
                                                     value: $event,
                                                     isInputValid: borderWidth.valid && $event !== null })">
      </mat-form-field>
    </div>
  `
})
export class ElementStylePropertiesComponent {
  @Input() styles: ElementStyling = {};
  @Output() updateModel = new EventEmitter<{
    property: string;
    value: string | boolean,
    isInputValid?: boolean | null
  }>();