Skip to content
Snippets Groups Projects
radio-button-group.component.ts 3.39 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Component, Input } from '@angular/core';
    
    import { RadioButtonGroupElement } from 'common/models/elements/input-elements/radio-button-group';
    
    import { FormElementComponent } from '../../directives/form-element-component.directive';
    
      selector: 'aspect-radio-button-group',
    
      template: `
    
    jojohoch's avatar
    jojohoch committed
        <div class="mat-form-field"
    
             [style.width.%]="100"
             [style.height.%]="100"
    
             [style.background-color]="elementModel.styling.backgroundColor"
             [style.color]="elementModel.styling.fontColor"
             [style.font-family]="elementModel.styling.font"
             [style.font-size.px]="elementModel.styling.fontSize"
             [style.font-weight]="elementModel.styling.bold ? 'bold' : ''"
             [style.font-style]="elementModel.styling.italic ? 'italic' : ''"
    
             [style.text-decoration]="elementModel.styling.underline ? 'underline' : ''"
             [style.line-height.%]="elementModel.styling.lineHeight">
    
          <label id="radio-group-label"
    
                 [innerHTML]="elementModel.label | safeResourceHTML">
    
          <mat-radio-group aria-labelledby="radio-group-label"
    
                           [class.fx-column-start-stretch]="elementModel.alignment === 'column'"
                           [class.fx-row-start-stretch]="elementModel.alignment === 'row'"
    
                           [formControl]="elementFormControl"
    
                           [value]="elementModel.value"
    
    rhenck's avatar
    rhenck committed
                           [style.margin-top.px]="elementModel.label !== '' ? 10 : 0">
    
            <mat-radio-button *ngFor="let option of elementModel.options; let i = index"
    
                              [ngClass]="{ 'strike' : elementModel.strikeOtherOptions &&
                                                      elementFormControl.value !== null &&
    
                                                      elementFormControl.value !== i }"
                              [value]="i"
    
                              [style.pointer-events]="elementModel.readOnly ? 'none' : 'unset'">
    
              <div class="radio-button-label" [innerHTML]="option.text | safeResourceHTML"></div>
    
            </mat-radio-button>
    
            <mat-error *ngIf="elementFormControl.errors && elementFormControl.touched"
    
                       class="error-message">
    
              {{elementFormControl.errors | errorTransform: elementModel}}
            </mat-error>
    
          </mat-radio-group>
        </div>
    
      styles: [`
        :host ::ng-deep .mat-radio-label {
          white-space: normal;
        }
        :host ::ng-deep .mat-radio-label .mat-radio-label-content {
          padding-left: 10px;
        }
        mat-radio-button {
          margin-bottom: 6px; margin-right: 15px;
        }
        .error-message {
          font-size: 75%; line-height: 100%;
        }
        :host ::ng-deep .strike .mat-radio-label {
          text-decoration: line-through;
        }
        :host ::ng-deep .mat-radio-label {
          align-items: baseline;
        }
        :host ::ng-deep mat-radio-button .mat-radio-label .mat-radio-container {
          top: 4px;
        }
        .radio-button-label {
          pointer-events: none;
        }
        .fx-row-start-stretch {
          box-sizing: border-box;
          display: flex;
          flex-direction: row;
          justify-content: start;
          align-items: stretch;
        }
        .fx-column-start-stretch {
          box-sizing: border-box;
          display: flex;
          flex-direction: column;
          justify-content: start;
          align-items: stretch;
        }
      `]
    
    export class RadioButtonGroupComponent extends FormElementComponent {
    
      @Input() elementModel!: RadioButtonGroupElement;