-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
list.ts
174 lines (154 loc) · 4.65 KB
/
list.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {
AfterContentInit,
Component,
ContentChild,
ContentChildren,
Directive,
ElementRef,
Optional,
QueryList,
Renderer2,
ViewEncapsulation,
ChangeDetectionStrategy,
} from '@angular/core';
import {MdLine, MdLineSetter} from '../core';
import {CanDisableRipple, mixinDisableRipple} from '../core/common-behaviors/disable-ripple';
// Boilerplate for applying mixins to MdList.
/** @docs-private */
export class MdListBase {}
export const _MdListMixinBase = mixinDisableRipple(MdListBase);
// Boilerplate for applying mixins to MdListItem.
/** @docs-private */
export class MdListItemBase {}
export const _MdListItemMixinBase = mixinDisableRipple(MdListItemBase);
@Directive({
selector: 'md-divider, mat-divider',
host: {
'role': 'separator',
'aria-orientation': 'horizontal'
}
})
export class MdListDivider {}
@Component({
moduleId: module.id,
selector: 'md-list, mat-list, md-nav-list, mat-nav-list',
host: {'role': 'list'},
template: '<ng-content></ng-content>',
styleUrls: ['list.css'],
inputs: ['disableRipple'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MdList extends _MdListMixinBase implements CanDisableRipple {}
/**
* Directive whose purpose is to add the mat- CSS styling to this selector.
* @docs-private
*/
@Directive({
selector: 'md-list, mat-list',
host: {'class': 'mat-list'}
})
export class MdListCssMatStyler {}
/**
* Directive whose purpose is to add the mat- CSS styling to this selector.
* @docs-private
*/
@Directive({
selector: 'md-nav-list, mat-nav-list',
host: {'class': 'mat-nav-list'}
})
export class MdNavListCssMatStyler {}
/**
* Directive whose purpose is to add the mat- CSS styling to this selector.
* @docs-private
*/
@Directive({
selector: 'md-divider, mat-divider',
host: {'class': 'mat-divider'}
})
export class MdDividerCssMatStyler {}
/**
* Directive whose purpose is to add the mat- CSS styling to this selector.
* @docs-private
*/
@Directive({
selector: '[md-list-avatar], [mat-list-avatar], [mdListAvatar], [matListAvatar]',
host: {'class': 'mat-list-avatar'}
})
export class MdListAvatarCssMatStyler {}
/**
* Directive whose purpose is to add the mat- CSS styling to this selector.
* @docs-private
*/
@Directive({
selector: '[md-list-icon], [mat-list-icon], [mdListIcon], [matListIcon]',
host: {'class': 'mat-list-icon'}
})
export class MdListIconCssMatStyler {}
/**
* Directive whose purpose is to add the mat- CSS styling to this selector.
* @docs-private
*/
@Directive({
selector: '[md-subheader], [mat-subheader]',
host: {'class': 'mat-subheader'}
})
export class MdListSubheaderCssMatStyler {}
@Component({
moduleId: module.id,
selector: 'md-list-item, mat-list-item, a[md-list-item], a[mat-list-item]',
host: {
'role': 'listitem',
'class': 'mat-list-item',
'(focus)': '_handleFocus()',
'(blur)': '_handleBlur()',
},
inputs: ['disableRipple'],
templateUrl: 'list-item.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MdListItem extends _MdListItemMixinBase implements AfterContentInit, CanDisableRipple {
private _lineSetter: MdLineSetter;
private _isNavList: boolean = false;
@ContentChildren(MdLine) _lines: QueryList<MdLine>;
@ContentChild(MdListAvatarCssMatStyler)
set _hasAvatar(avatar: MdListAvatarCssMatStyler) {
if (avatar != null) {
this._renderer.addClass(this._element.nativeElement, 'mat-list-item-avatar');
} else {
this._renderer.removeClass(this._element.nativeElement, 'mat-list-item-avatar');
}
}
constructor(private _renderer: Renderer2,
private _element: ElementRef,
@Optional() private _list: MdList,
@Optional() navList: MdNavListCssMatStyler) {
super();
this._isNavList = !!navList;
}
ngAfterContentInit() {
this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);
}
/** Whether this list item should show a ripple effect when clicked. */
isRippleEnabled() {
return !this.disableRipple && this._isNavList && !this._list.disableRipple;
}
_handleFocus() {
this._renderer.addClass(this._element.nativeElement, 'mat-list-item-focus');
}
_handleBlur() {
this._renderer.removeClass(this._element.nativeElement, 'mat-list-item-focus');
}
/** Retrieves the DOM element of the component host. */
_getHostElement(): HTMLElement {
return this._element.nativeElement;
}
}