-
Notifications
You must be signed in to change notification settings - Fork 6
/
multi-language-textarea.component.ts
86 lines (82 loc) · 2.97 KB
/
multi-language-textarea.component.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup, FormsModule, ReactiveFormsModule, ValidatorFn } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatMenuModule } from '@angular/material/menu';
import { NgxsStoreModule } from '@dasch-swiss/vre/shared/app-state';
import { HumanReadableErrorPipe } from './human-readable-error.pipe';
import { MultiLanguageFormService } from './multi-language-form.service';
@Component({
selector: 'dasch-swiss-multi-language-textarea',
standalone: true,
providers: [MultiLanguageFormService],
imports: [
CommonModule,
MatButtonModule,
MatButtonToggleModule,
MatIconModule,
MatInputModule,
MatMenuModule,
FormsModule,
ReactiveFormsModule,
NgxsStoreModule,
HumanReadableErrorPipe,
],
template: `
<div style="display: flex">
<mat-button-toggle-group matPrefix #group="matButtonToggleGroup" vertical>
<mat-button-toggle
*ngFor="let lang of formService.availableLanguages; let index = index"
(click)="formService.changeLanguage(index); textInput.focus()"
[checked]="index === formService.selectedLanguageIndex"
[class.bold]="formService.getFormControlWithLanguage(lang) !== undefined">
<span>{{ lang }}</span>
</mat-button-toggle>
</mat-button-toggle-group>
<mat-form-field style="flex: 1" subscriptSizing="dynamic" class="formfield">
<textarea
matInput
rows="9"
[placeholder]="placeholder"
#textInput
[readonly]="!editable"
[ngModel]="formService.inputValue"
(ngModelChange)="formService.onInputChange($event)"></textarea>
</mat-form-field>
</div>
<mat-error *ngIf="formService.formArray.invalid && formService.formArray.touched">
<ng-container *ngIf="formService.invalidErrors?.language"
>Language {{ formService.invalidErrors.language }}:
{{ formService.invalidErrors.error | humanReadableError }}</ng-container
>
<ng-container *ngIf="!formService.invalidErrors?.language">{{
formService.invalidErrors.error | humanReadableError
}}</ng-container>
</mat-error>
`,
styles: [
`
:host {
display: block;
padding-bottom: 22px;
}
.bold {
font-weight: bold;
}
`,
],
})
export class MultiLanguageTextareaComponent implements OnInit {
@Input() formGroup: FormGroup;
@Input() controlName: string;
@Input() editable = true;
@Input() placeholder: string;
@Input() validators: ValidatorFn[];
constructor(public formService: MultiLanguageFormService) {}
ngOnInit() {
this.formService.onInit(this.formGroup, this.controlName, this.validators);
}
}