All files / src/app/shared/formly/wrappers/description-wrapper description-wrapper.component.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x 1x                               1x   3x           3x      
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FieldWrapper } from '@ngx-formly/core';
 
/**
 * Wrapper that adds a small description underneath the field.
 *
 * @props **customDescription** - used to define the description text. Can be one of two types:
 * * ``string`` : a simple string that will be translated and displayed
 * * ``{ key: string, args: any, class: string}`` : a more complex object containing a translation key
 *    and arguments to be translated as well as a class that will be applied to the description.
 *
 */
@Component({
  selector: 'ish-description-wrapper',
  templateUrl: './description-wrapper.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DescriptionWrapperComponent extends FieldWrapper {
  get description() {
    return typeof this.props.customDescription === 'string'
      ? this.props.customDescription
      : this.props.customDescription?.key;
  }
 
  get args() {
    return typeof this.props.customDescription === 'string' ? {} : this.props.customDescription?.args;
  }
}