Skip to content

Commit f59cf59

Browse files
rafaelss95tinayuangao
authored andcommitted
chore: enforce consistency in material-examples (#11539)
1 parent 83631fc commit f59cf59

File tree

110 files changed

+840
-871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+840
-871
lines changed

src/lib/tree/data-source/flat-data-source.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {FlatTreeControl, TreeControl} from '@angular/cdk/tree';
1111
import {BehaviorSubject, merge, Observable} from 'rxjs';
1212
import {map, take} from 'rxjs/operators';
1313

14-
1514
/**
1615
* Tree flattener to convert a normal type of node to node with children & level information.
1716
* Transform nested nodes of type `T` to flattened nodes of type `F`.
@@ -90,7 +89,7 @@ export class MatTreeFlattener<T, F> {
9089
let currentExpand: boolean[] = [];
9190
currentExpand[0] = true;
9291

93-
nodes.forEach((node) => {
92+
nodes.forEach(node => {
9493
let expand = true;
9594
for (let i = 0; i <= this.getLevel(node); i++) {
9695
expand = expand && currentExpand[i];
@@ -151,4 +150,3 @@ export class MatTreeFlatDataSource<T, F> extends DataSource<F> {
151150
// no op
152151
}
153152
}
154-

src/material-examples/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
55
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
6-
{{ option }}
6+
{{option}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ import {map, startWith} from 'rxjs/operators';
99
@Component({
1010
selector: 'autocomplete-auto-active-first-option-example',
1111
templateUrl: 'autocomplete-auto-active-first-option-example.html',
12-
styleUrls: ['autocomplete-auto-active-first-option-example.css']
12+
styleUrls: ['autocomplete-auto-active-first-option-example.css'],
1313
})
1414
export class AutocompleteAutoActiveFirstOptionExample implements OnInit {
15-
myControl: FormControl = new FormControl();
16-
options = ['One', 'Two', 'Three'];
15+
myControl = new FormControl();
16+
options: string[] = ['One', 'Two', 'Three'];
1717
filteredOptions: Observable<string[]>;
1818

1919
ngOnInit() {
2020
this.filteredOptions = this.myControl.valueChanges.pipe(
2121
startWith(''),
22-
map(val => this.filter(val))
22+
map(value => this._filter(value))
2323
);
2424
}
2525

26-
filter(val: string): string[] {
27-
return this.options.filter(option => option.toLowerCase().indexOf(val.toLowerCase()) === 0);
28-
}
26+
private _filter(value: string): string[] {
27+
const filterValue = value.toLowerCase();
2928

29+
return this.options.filter(option => option.toLowerCase().indexOf(filterValue) === 0);
30+
}
3031
}

src/material-examples/autocomplete-display/autocomplete-display-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
55
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
6-
{{ option.name }}
6+
{{option.name}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-display/autocomplete-display-example.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

6-
export class User {
7-
constructor(public name: string) { }
6+
export interface User {
7+
name: string;
88
}
99

1010
/**
@@ -13,36 +13,33 @@ export class User {
1313
@Component({
1414
selector: 'autocomplete-display-example',
1515
templateUrl: 'autocomplete-display-example.html',
16-
styleUrls: ['autocomplete-display-example.css']
16+
styleUrls: ['autocomplete-display-example.css'],
1717
})
1818
export class AutocompleteDisplayExample implements OnInit {
19-
2019
myControl = new FormControl();
21-
22-
options = [
23-
new User('Mary'),
24-
new User('Shelley'),
25-
new User('Igor')
20+
options: User[] = [
21+
{name: 'Mary'},
22+
{name: 'Shelley'},
23+
{name: 'Igor'}
2624
];
27-
2825
filteredOptions: Observable<User[]>;
2926

3027
ngOnInit() {
3128
this.filteredOptions = this.myControl.valueChanges
3229
.pipe(
3330
startWith<string | User>(''),
3431
map(value => typeof value === 'string' ? value : value.name),
35-
map(name => name ? this.filter(name) : this.options.slice())
32+
map(name => name ? this._filter(name) : this.options.slice())
3633
);
3734
}
3835

39-
filter(name: string): User[] {
40-
return this.options.filter(option =>
41-
option.name.toLowerCase().indexOf(name.toLowerCase()) === 0);
42-
}
43-
4436
displayFn(user?: User): string | undefined {
4537
return user ? user.name : undefined;
4638
}
4739

40+
private _filter(name: string): User[] {
41+
const filterValue = name.toLowerCase();
42+
43+
return this.options.filter(option => option.name.toLowerCase().indexOf(filterValue) === 0);
44+
}
4845
}

src/material-examples/autocomplete-filter/autocomplete-filter-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete">
55
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
6-
{{ option }}
6+
{{option}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-filter/autocomplete-filter-example.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,24 @@ import {map, startWith} from 'rxjs/operators';
99
@Component({
1010
selector: 'autocomplete-filter-example',
1111
templateUrl: 'autocomplete-filter-example.html',
12-
styleUrls: ['autocomplete-filter-example.css']
12+
styleUrls: ['autocomplete-filter-example.css'],
1313
})
1414
export class AutocompleteFilterExample implements OnInit {
15-
16-
myControl: FormControl = new FormControl();
17-
18-
options = [
19-
'One',
20-
'Two',
21-
'Three'
22-
];
23-
15+
myControl = new FormControl();
16+
options: string[] = ['One', 'Two', 'Three'];
2417
filteredOptions: Observable<string[]>;
2518

2619
ngOnInit() {
2720
this.filteredOptions = this.myControl.valueChanges
2821
.pipe(
2922
startWith(''),
30-
map(val => this.filter(val))
23+
map(value => this._filter(value))
3124
);
3225
}
3326

34-
filter(val: string): string[] {
35-
return this.options.filter(option =>
36-
option.toLowerCase().includes(val.toLowerCase()));
37-
}
27+
private _filter(value: string): string[] {
28+
const filterValue = value.toLowerCase();
3829

30+
return this.options.filter(option => option.toLowerCase().includes(filterValue));
31+
}
3932
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<form [formGroup]="stateForm">
22
<mat-form-field>
3-
<input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup"/>
3+
<input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup">
44
<mat-autocomplete #autoGroup="matAutocomplete">
55
<mat-optgroup *ngFor="let group of stateGroupOptions | async" [label]="group.letter">
66
<mat-option *ngFor="let name of group.names" [value]="name">
7-
{{ name }}
7+
{{name}}
88
</mat-option>
99
</mat-optgroup>
1010
</mat-autocomplete>
11-
</mat-form-field>
12-
</form>
11+
</mat-form-field>
12+
</form>

src/material-examples/autocomplete-optgroup/autocomplete-optgroup-example.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormGroup, FormBuilder} from '@angular/forms';
2+
import {FormBuilder, FormGroup} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {startWith, map} from 'rxjs/operators';
55

@@ -8,6 +8,12 @@ export interface StateGroup {
88
names: string[];
99
}
1010

11+
export const _filter = (opt: string[], value: string): string[] => {
12+
const filterValue = value.toLowerCase();
13+
14+
return opt.filter(item => item.toLowerCase().indexOf(filterValue) === 0);
15+
};
16+
1117
/**
1218
* @title Option groups autocomplete
1319
*/
@@ -84,28 +90,23 @@ export class AutocompleteOptgroupExample implements OnInit {
8490

8591
stateGroupOptions: Observable<StateGroup[]>;
8692

87-
constructor(private fb: FormBuilder) { }
93+
constructor(private fb: FormBuilder) {}
8894

8995
ngOnInit() {
9096
this.stateGroupOptions = this.stateForm.get('stateGroup')!.valueChanges
9197
.pipe(
9298
startWith(''),
93-
map(val => this.filterGroup(val))
99+
map(value => this._filterGroup(value))
94100
);
95101
}
96102

97-
filterGroup(val: string): StateGroup[] {
98-
if (val) {
103+
private _filterGroup(value: string): StateGroup[] {
104+
if (value) {
99105
return this.stateGroups
100-
.map(group => ({ letter: group.letter, names: this._filter(group.names, val) }))
106+
.map(group => ({letter: group.letter, names: _filter(group.names, value)}))
101107
.filter(group => group.names.length > 0);
102108
}
103109

104110
return this.stateGroups;
105111
}
106-
107-
private _filter(opt: string[], val: string) {
108-
const filterValue = val.toLowerCase();
109-
return opt.filter(item => item.toLowerCase().startsWith(filterValue));
110-
}
111112
}

src/material-examples/autocomplete-overview/autocomplete-overview-example.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
.example-full-width {
88
width: 100%;
99
}
10+
11+
.example-option-img {
12+
vertical-align: middle;
13+
}

src/material-examples/autocomplete-overview/autocomplete-overview-example.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<input matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
44
<mat-autocomplete #auto="matAutocomplete">
55
<mat-option *ngFor="let state of filteredStates | async" [value]="state.name">
6-
<img style="vertical-align:middle;" aria-hidden src="{{state.flag}}" height="25" />
7-
<span>{{ state.name }}</span> |
6+
<img class="example-option-img" aria-hidden [src]="state.flag" height="25">
7+
<span>{{state.name}}</span> |
88
<small>Population: {{state.population}}</small>
99
</mat-option>
1010
</mat-autocomplete>
1111
</mat-form-field>
1212

13-
<br />
13+
<br>
1414

1515
<mat-slide-toggle
1616
[checked]="stateCtrl.disabled"

src/material-examples/autocomplete-overview/autocomplete-overview-example.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {Component} from '@angular/core';
22
import {FormControl} from '@angular/forms';
3-
43
import {Observable} from 'rxjs';
54
import {map, startWith} from 'rxjs/operators';
65

7-
export class State {
8-
constructor(public name: string, public population: string, public flag: string) { }
6+
export interface State {
7+
flag: string;
8+
name: string;
9+
population: string;
910
}
1011

1112
/**
@@ -14,11 +15,11 @@ export class State {
1415
@Component({
1516
selector: 'autocomplete-overview-example',
1617
templateUrl: 'autocomplete-overview-example.html',
17-
styleUrls: ['autocomplete-overview-example.css']
18+
styleUrls: ['autocomplete-overview-example.css'],
1819
})
1920
export class AutocompleteOverviewExample {
20-
stateCtrl: FormControl;
21-
filteredStates: Observable<any[]>;
21+
stateCtrl = new FormControl();
22+
filteredStates: Observable<State[]>;
2223

2324
states: State[] = [
2425
{
@@ -48,17 +49,16 @@ export class AutocompleteOverviewExample {
4849
];
4950

5051
constructor() {
51-
this.stateCtrl = new FormControl();
5252
this.filteredStates = this.stateCtrl.valueChanges
5353
.pipe(
5454
startWith(''),
55-
map(state => state ? this.filterStates(state) : this.states.slice())
55+
map(state => state ? this._filterStates(state) : this.states.slice())
5656
);
5757
}
5858

59-
filterStates(name: string) {
60-
return this.states.filter(state =>
61-
state.name.toLowerCase().indexOf(name.toLowerCase()) === 0);
62-
}
59+
private _filterStates(value: string): State[] {
60+
const filterValue = value.toLowerCase();
6361

62+
return this.states.filter(state => state.name.toLowerCase().indexOf(filterValue) === 0);
63+
}
6464
}

src/material-examples/autocomplete-simple/autocomplete-simple-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete">
55
<mat-option *ngFor="let option of options" [value]="option">
6-
{{ option }}
6+
{{option}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-simple/autocomplete-simple-example.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ import {FormControl} from '@angular/forms';
77
@Component({
88
selector: 'autocomplete-simple-example',
99
templateUrl: 'autocomplete-simple-example.html',
10-
styleUrls: ['autocomplete-simple-example.css']
10+
styleUrls: ['autocomplete-simple-example.css'],
1111
})
1212
export class AutocompleteSimpleExample {
13-
14-
myControl: FormControl = new FormControl();
15-
16-
options = [
17-
'One',
18-
'Two',
19-
'Three'
20-
];
21-
13+
myControl = new FormControl();
14+
options: string[] = ['One', 'Two', 'Three'];
2215
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {Component} from '@angular/core';
22

3-
43
/**
54
* @title Badge overview
65
*/
76
@Component({
87
selector: 'badge-overview-example',
98
templateUrl: 'badge-overview-example.html',
10-
styleUrls: ['badge-overview-example.css']
9+
styleUrls: ['badge-overview-example.css'],
1110
})
12-
export class BadgeOverviewExample { }
11+
export class BadgeOverviewExample {}

0 commit comments

Comments
 (0)