Skip to content

Commit 7479c3a

Browse files
feat(Authoring): Use slider to set activity width
1 parent 63b4444 commit 7479c3a

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
import { Component } from '@angular/core';
22
import { EditComponentFieldComponent } from '../edit-component-field.component';
3-
import { MatFormFieldModule } from '@angular/material/form-field';
4-
import { MatInputModule } from '@angular/material/input';
53
import { FormsModule } from '@angular/forms';
4+
import { MatSliderModule } from '@angular/material/slider';
65

76
@Component({
8-
imports: [FormsModule, MatFormFieldModule, MatInputModule],
7+
imports: [FormsModule, MatSliderModule],
98
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>`
1926
})
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+
}

src/messages.xlf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,18 @@
10961096
<context context-type="linenumber">85</context>
10971097
</context-group>
10981098
</trans-unit>
1099-
<trans-unit id="2810375050239191789" datatype="html">
1100-
<source>Activity Width</source>
1099+
<trans-unit id="7007219426980695734" datatype="html">
1100+
<source>Activity width:</source>
11011101
<context-group purpose="location">
11021102
<context context-type="sourcefile">src/app/authoring-tool/edit-component-width/edit-component-width.component.ts</context>
1103-
<context context-type="linenumber">11,15</context>
1103+
<context context-type="linenumber">9,12</context>
1104+
</context-group>
1105+
</trans-unit>
1106+
<trans-unit id="1197041381998976714" datatype="html">
1107+
<source> *Setting the activities&apos; widths determines how they appear on the screen. For example, if two adjacent activities&apos; widths are both set to 50%, they will appear side-by-side. </source>
1108+
<context-group purpose="location">
1109+
<context context-type="sourcefile">src/app/authoring-tool/edit-component-width/edit-component-width.component.ts</context>
1110+
<context context-type="linenumber">23,27</context>
11041111
</context-group>
11051112
</trans-unit>
11061113
<trans-unit id="8650499415827640724" datatype="html">

0 commit comments

Comments
 (0)