|
1 | 1 | import { Component } from '@angular/core'; |
2 | 2 | import { EditComponentFieldComponent } from '../edit-component-field.component'; |
3 | | -import { MatFormFieldModule } from '@angular/material/form-field'; |
4 | | -import { MatInputModule } from '@angular/material/input'; |
5 | 3 | import { FormsModule } from '@angular/forms'; |
| 4 | +import { MatSliderModule } from '@angular/material/slider'; |
6 | 5 |
|
7 | 6 | @Component({ |
8 | | - imports: [FormsModule, MatFormFieldModule, MatInputModule], |
| 7 | + imports: [FormsModule, MatSliderModule], |
9 | 8 | 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> ` |
| 9 | + template: `<span i18n>Activity width:</span> |
| 10 | + <mat-slider |
| 11 | + min="0" |
| 12 | + [max]="possibleValues.length - 1" |
| 13 | + step="1" |
| 14 | + discrete |
| 15 | + showTickMarks |
| 16 | + [displayWith]="formatLabel" |
| 17 | + style="min-width: 300px;" |
| 18 | + > |
| 19 | + <input matSliderThumb (input)="onSliderChange($event)" [value]="selectedIndex" /> |
| 20 | + </mat-slider> |
| 21 | + <span>{{ selectedValue }}%</span> |
| 22 | + <p i18n> |
| 23 | + *Setting the activities' widths determines how they appear on the screen. For example, if two |
| 24 | + adjacent activities' widths are both set to 50%, they will appear side-by-side. |
| 25 | + </p>` |
19 | 26 | }) |
20 | | -export class EditComponentWidthComponent extends EditComponentFieldComponent {} |
| 27 | +export class EditComponentWidthComponent extends EditComponentFieldComponent { |
| 28 | + protected possibleValues = [25, 33, 50, 66, 75, 100]; |
| 29 | + protected selectedIndex = 0; |
| 30 | + protected selectedValue = this.possibleValues[0]; |
| 31 | + |
| 32 | + public override ngOnInit(): void { |
| 33 | + super.ngOnInit(); |
| 34 | + this.selectedValue = this.componentContent.componentWidth ?? 100; |
| 35 | + this.selectedIndex = this.possibleValues.indexOf(this.selectedValue); |
| 36 | + } |
| 37 | + |
| 38 | + protected formatLabel = (index: number): string => `${this.possibleValues[index]}%`; |
| 39 | + |
| 40 | + protected onSliderChange(event: any): void { |
| 41 | + this.selectedValue = this.possibleValues[event.target.value]; |
| 42 | + this.componentContent.componentWidth = this.selectedValue; |
| 43 | + this.inputChanged.next(this.selectedValue); |
| 44 | + } |
| 45 | +} |
0 commit comments