Skip to content
Snippets Groups Projects
text-area.ts 2.22 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Type } from '@angular/core';
    
    import {
    
      PositionedUIElement, UIElement, TextInputElement
    
    } from 'common/models/elements/element';
    import { ElementComponent } from 'common/directives/element-component.directive';
    import { TextAreaComponent } from 'common/components/input-elements/text-area.component';
    
    
    import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces';
    
    rhenck's avatar
    rhenck committed
    import { BasicStyles, DimensionProperties, PositionProperties } from 'common/models/elements/property-group-interfaces';
    
    export class TextAreaElement extends TextInputElement implements PositionedUIElement {
    
      appearance: 'fill' | 'outline' = 'outline';
      resizeEnabled: boolean = false;
    
      hasDynamicRowCount: boolean = false;
    
      rowCount: number = 3;
    
      expectedCharactersCount: number = 300;
    
      hasReturnKey: boolean = false;
    
      hasKeyboardIcon: boolean = false;
    
      position: PositionProperties;
      styling: BasicStyles & {
        lineHeight: number;
      };
    
    
    rhenck's avatar
    rhenck committed
      constructor(element: Partial<TextAreaElement>) {
    
    rhenck's avatar
    rhenck committed
        super({ dimensions: { width: 230, height: 132 } as DimensionProperties, ...element });
    
    rhenck's avatar
    rhenck committed
        if (element.appearance) this.appearance = element.appearance;
        if (element.resizeEnabled) this.resizeEnabled = element.resizeEnabled;
        if (element.rowCount) this.rowCount = element.rowCount;
    
        if (element.hasDynamicRowCount) this.hasDynamicRowCount = element.hasDynamicRowCount;
        if (element.expectedCharactersCount) this.expectedCharactersCount = element.expectedCharactersCount;
    
        if (element.hasReturnKey) this.hasReturnKey = element.hasReturnKey;
    
        if (element.hasKeyboardIcon) this.hasKeyboardIcon = element.hasKeyboardIcon;
    
    rhenck's avatar
    rhenck committed
        this.position = UIElement.initPositionProps(element.position);
    
        this.styling = {
    
    rhenck's avatar
    rhenck committed
          ...UIElement.initStylingProps({
    
            backgroundColor: 'transparent',
            lineHeight: 135,
            ...element.styling
          })
        };
      }
    
    
      hasAnswerScheme(): boolean {
    
        return Boolean(this.getAnswerScheme);
    
      getAnswerScheme(): AnswerScheme {
    
        return {
          id: this.id,
          type: 'string',
          format: '',
          multiple: false,
    
          nullable: !this.value && this.value !== '',
          values: [],
    
      getElementComponent(): Type<ElementComponent> {
    
        return TextAreaComponent;
      }
    }