Skip to content
Snippets Groups Projects
toggle-button.component.ts 2.64 KiB
Newer Older
rhenck's avatar
rhenck committed
import { Component, Input } from '@angular/core';
import { FormElementComponent } from '../../directives/form-element-component.directive';
import { ToggleButtonElement } from '../../interfaces/elements';
rhenck's avatar
rhenck committed

@Component({
  selector: 'aspect-toggle-button',
rhenck's avatar
rhenck committed
  template: `
    <div class="mat-form-field">
      <mat-button-toggle-group [formControl]="elementFormControl"
                               [value]="elementModel.value"
rhenck's avatar
rhenck committed
                               [style.height.px]="elementModel.height"
                               [style.width]="elementModel.dynamicWidth ? 'unset' : elementModel.width+'px'"
                               [vertical]="elementModel.verticalOrientation">
rhenck's avatar
rhenck committed
        <mat-button-toggle *ngFor="let option of elementModel.options; let i = index"
rhenck's avatar
rhenck committed
                           [ngClass]="{ 'strike' : elementModel.strikeOtherOptions &&
                                                   elementFormControl.value !== null &&
                                                   elementFormControl.value !== i }"
rhenck's avatar
rhenck committed
                           [style.color]="elementModel.styles.fontColor"
                           [style.font-size.px]="elementModel.styles.fontSize"
                           [style.font-weight]="elementModel.styles.bold ? 'bold' : ''"
                           [style.font-style]="elementModel.styles.italic ? 'italic' : ''"
                           [style.text-decoration]="elementModel.styles.underline ? 'underline' : ''"
                           [style.font-family]="elementModel.styles.font"
                           [style.background-color]="elementFormControl.value !== null &&
                                                   elementFormControl.value === i ?
                                                   elementModel.selectionColor :
rhenck's avatar
rhenck committed
                                                   elementModel.styles.backgroundColor"
                           [style.line-height.%]="elementModel.styles.lineHeight">
rhenck's avatar
rhenck committed
                           <!--Background color does not show in editor-->
rhenck's avatar
rhenck committed
          {{option}}
        </mat-button-toggle>
      </mat-button-toggle-group>
    </div>
  `,
  styles: [
    'mat-button-toggle-group {min-width: 70px; min-height: 20px; display: inline-flex;}',
rhenck's avatar
rhenck committed
    ':host ::ng-deep mat-button-toggle {width: 100%; height: 100%}',
rhenck's avatar
rhenck committed
    ':host ::ng-deep .mat-button-toggle-button {height: 100%}',
rhenck's avatar
rhenck committed
    ':host ::ng-deep .mat-button-toggle-label-content {line-height: unset}',
    ':host ::ng-deep .strike .mat-button-toggle-label-content {text-decoration: line-through}'
rhenck's avatar
rhenck committed
  ]
})
export class ToggleButtonComponent extends FormElementComponent {
  @Input() elementModel!: ToggleButtonElement;
}