|
1 | 1 | import { Component } from '@angular/core'; |
2 | | -import { EditComponentFieldComponent } from '../edit-component-field.component'; |
3 | | -import { MatFormFieldModule } from '@angular/material/form-field'; |
4 | | -import { MatInputModule } from '@angular/material/input'; |
5 | 2 | import { FormsModule } from '@angular/forms'; |
| 3 | +import { MatIconModule } from '@angular/material/icon'; |
| 4 | +import { MatTooltipModule } from '@angular/material/tooltip'; |
| 5 | +import { MatButtonToggleModule } from '@angular/material/button-toggle'; |
| 6 | +import { EditComponentFieldComponent } from '../edit-component-field.component'; |
6 | 7 |
|
7 | 8 | @Component({ |
8 | | - imports: [FormsModule, MatFormFieldModule, MatInputModule], |
| 9 | + imports: [FormsModule, MatButtonToggleModule, MatIconModule, MatTooltipModule], |
9 | 10 | selector: 'edit-component-width', |
10 | | - template: `<mat-form-field> |
11 | | - <mat-label i18n>Activity Width</mat-label> |
12 | | - <input |
13 | | - matInput |
14 | | - type="number" |
15 | | - [(ngModel)]="componentContent.componentWidth" |
16 | | - (ngModelChange)="inputChanged.next($event)" |
17 | | - /> |
18 | | - </mat-form-field> ` |
| 11 | + template: `<div class="flex items-center gap-2 my-2"> |
| 12 | + <span i18n>Activity width</span> |
| 13 | + <mat-icon |
| 14 | + tabindex="0" |
| 15 | + matTooltip="The activity's width determines how it appears on the screen. If two adjacent |
| 16 | + activities are set to 50% each (or 67% and 33%, for example), they will appear side-by-side." |
| 17 | + matTooltipPosition="above" |
| 18 | + i18n-matTooltip |
| 19 | + >help</mat-icon |
| 20 | + > |
| 21 | + </div> |
| 22 | + <mat-button-toggle-group |
| 23 | + [(ngModel)]="selectedValue" |
| 24 | + (change)="onWidthChange()" |
| 25 | + aria-label="Activity width" |
| 26 | + hideSingleSelectionIndicator="true" |
| 27 | + > |
| 28 | + @for (value of possibleValues; track $index) { |
| 29 | + <mat-button-toggle value="{{ value }}">{{ value }}%</mat-button-toggle> |
| 30 | + } |
| 31 | + </mat-button-toggle-group>` |
19 | 32 | }) |
20 | | -export class EditComponentWidthComponent extends EditComponentFieldComponent {} |
| 33 | +export class EditComponentWidthComponent extends EditComponentFieldComponent { |
| 34 | + protected possibleValues = [25, 33, 50, 67, 75, 100]; |
| 35 | + protected selectedValue = '100'; |
| 36 | + |
| 37 | + public override ngOnInit(): void { |
| 38 | + super.ngOnInit(); |
| 39 | + this.selectedValue = String(this.componentContent.componentWidth ?? 100); |
| 40 | + } |
| 41 | + |
| 42 | + protected onWidthChange(): void { |
| 43 | + this.componentContent.componentWidth = Number(this.selectedValue); |
| 44 | + this.inputChanged.next(Number(this.selectedValue)); |
| 45 | + } |
| 46 | +} |
0 commit comments