@@ -2,17 +2,18 @@ import { AfterContentInit, ContentChild, Directive, ElementRef, forwardRef, Host
2
2
Input , OnDestroy , OnInit , Optional , Renderer2 , Self } from '@angular/core' ;
3
3
import { NgControl } from '@angular/forms' ;
4
4
import { MDCSelectFoundation } from '@material/select' ;
5
- import { MDCSelectLabelFoundation } from '@material/select/label' ;
6
- import { MDCSelectBottomLineFoundation } from '@material/select/bottom-line' ;
7
- import { MdcSelectAdapter , MdcSelectLabelAdapter , MdcSelectBottomLineAdapter } from './mdc.select.adapter' ;
5
+ import { MDCFloatingLabelFoundation } from '@material/floating-label' ;
6
+ import { MDCLineRippleFoundation } from '@material/line-ripple' ;
7
+ import { MdcSelectAdapter } from './mdc.select.adapter' ;
8
+ import { MdcFloatingLabelDirective } from '../floating-label/mdc.floating-label.directive' ;
9
+ import { MdcLineRippleAdapter } from '../line-ripple/mdc.line-ripple.adapter' ;
8
10
import { AbstractMdcInput } from '../abstract/abstract.mdc.input' ;
9
11
import { asBoolean } from '../../utils/value.utils' ;
10
12
import { MdcEventRegistry } from '../../utils/mdc.event.registry' ;
11
13
12
14
const CLASS_SELECT = 'mdc-select' ;
13
15
const CLASS_SELECT_CONTROL = 'mdc-select__native-control' ;
14
- const CLASS_SELECT_LABEL = 'mdc-select__label' ;
15
- const CLASS_SELECT_LINE = 'mdc-select__bottom-line' ;
16
+ const CLASS_LINE_RIPPLE = 'mdc-line-ripple' ;
16
17
17
18
let nextId = 1 ;
18
19
@@ -52,8 +53,8 @@ export class MdcSelectControlDirective extends AbstractMdcInput implements OnIni
52
53
53
54
/**
54
55
* Mirrors the <code>id</code> attribute. If no id is assigned, this directive will
55
- * assign a unique id by itself. If an <code>mdcSelectLabel </code> for this text-field
56
- * is available, the <code>mdcSelectLabel </code> will automatically set its <code>for</code>
56
+ * assign a unique id by itself. If an <code>mdcFloatingLabel </code> for this select control
57
+ * is available, the <code>mdcFloatingLabel </code> will automatically set its <code>for</code>
57
58
* attribute to this <code>id</code> value.
58
59
*/
59
60
@HostBinding ( )
@@ -83,70 +84,43 @@ export class MdcSelectControlDirective extends AbstractMdcInput implements OnIni
83
84
}
84
85
}
85
86
86
- /**
87
- * Directive for the label of an <code>mdcSelect</code> selection control.
88
- * Should be used as a child element of the <code>mdcSelect</code>,
89
- * immediately after the <code>mdcSelectControl</code>.
90
- */
91
- @Directive ( {
92
- selector : '[mdcSelectLabel]'
93
- } )
94
- export class MdcSelectLabelDirective implements AfterContentInit {
95
- @HostBinding ( 'class.' + CLASS_SELECT_LABEL ) _cls = true ;
96
- _initialized = false ;
97
- _adapter : MdcSelectLabelAdapter = {
98
- addClass : ( className : string ) => { this . _rndr . addClass ( this . _elm . nativeElement , className ) ; } ,
99
- removeClass : ( className : string ) => { this . _rndr . removeClass ( this . _elm . nativeElement , className ) ; }
100
- } ;
101
- _foundation : {
102
- init ( ) ,
103
- destroy ( ) ,
104
- styleFloat ( value : boolean )
105
- } = < any > new MDCSelectLabelFoundation ( this . _adapter ) ;
106
-
107
- constructor ( public _elm : ElementRef , private _rndr : Renderer2 ) {
108
- }
109
-
110
- ngAfterContentInit ( ) {
111
- this . _foundation . init ( ) ;
112
- this . _initialized = true ;
113
- }
114
-
115
- ngOnDestroy ( ) {
116
- this . _foundation . destroy ( ) ;
117
- this . _initialized = false ;
118
- }
119
- }
120
-
121
87
/**
122
88
* Directive for a spec aligned material design 'Select Control'.
123
89
* This directive should wrap an <code>mdcSelectControl</code>, and an
124
- * <code>mdcSelectLabel </code> directive.
90
+ * <code>mdcFloatingLabel </code> directive.
125
91
*/
126
92
@Directive ( {
127
93
selector : '[mdcSelect]'
128
94
} )
129
95
export class MdcSelectDirective implements AfterContentInit , OnDestroy {
130
96
@HostBinding ( 'class.' + CLASS_SELECT ) _cls = true ;
131
97
@ContentChild ( MdcSelectControlDirective ) _control : MdcSelectControlDirective ;
132
- @ContentChild ( MdcSelectLabelDirective ) _label : MdcSelectLabelDirective ;
98
+ @ContentChild ( MdcFloatingLabelDirective ) _label : MdcFloatingLabelDirective ;
133
99
private _initialized = false ;
134
100
private _bottomLineElm : HTMLElement = null ;
135
- private _bottomLineAdapter : MdcSelectBottomLineAdapter ;
136
- private _bottomLineFoundation : {
137
- init ( ) ,
138
- destroy ( ) ,
139
- activate ( ) ,
140
- deactivate ( )
141
- } = < any > new MDCSelectBottomLineFoundation ( this . _bottomLineAdapter ) ;
101
+ private _lineRippleAdapter : MdcLineRippleAdapter = {
102
+ addClass : ( className : string ) => this . _rndr . addClass ( this . _bottomLineElm , className ) ,
103
+ removeClass : ( className : string ) => this . _rndr . removeClass ( this . _bottomLineElm , className ) ,
104
+ hasClass : ( className ) => this . _bottomLineElm . classList . contains ( className ) ,
105
+ setStyle : ( name : string , value : string ) => this . _rndr . setStyle ( this . _bottomLineElm , name , value ) ,
106
+ registerEventHandler : ( evtType : string , handler : EventListener ) => this . _registry . listenElm ( this . _rndr , evtType , handler , this . _bottomLineElm ) ,
107
+ deregisterEventHandler : ( evtType : string , handler : EventListener ) => this . _registry . unlisten ( evtType , handler )
108
+ } ;
109
+ private _lineRippleFoundation : {
110
+ init : Function ,
111
+ destroy : Function ,
112
+ activate : Function ,
113
+ deactivate : Function ,
114
+ setRippleCenter : ( x : number ) => void
115
+ } = new MDCLineRippleFoundation ( this . _lineRippleAdapter ) ;
142
116
private adapter : MdcSelectAdapter = {
143
117
addClass : ( className : string ) => { this . _rndr . addClass ( this . _elm . nativeElement , className ) ; } ,
144
118
removeClass : ( className : string ) => { this . _rndr . removeClass ( this . _elm . nativeElement , className ) ; } ,
145
119
floatLabel : ( value : boolean ) => {
146
- if ( this . _label ) this . _label . _foundation . styleFloat ( value ) ;
120
+ if ( this . _label ) this . _label . _foundation . float ( value ) ;
147
121
} ,
148
- activateBottomLine : ( ) => this . _bottomLineFoundation . activate ( ) ,
149
- deactivateBottomLine : ( ) => this . _bottomLineFoundation . deactivate ( ) ,
122
+ activateBottomLine : ( ) => this . _lineRippleFoundation . activate ( ) ,
123
+ deactivateBottomLine : ( ) => this . _lineRippleFoundation . deactivate ( ) ,
150
124
setDisabled : ( disabled : boolean ) => this . _control . _elm . nativeElement . disabled = disabled ,
151
125
registerInteractionHandler : ( type , handler ) => this . _control . _registry . listen ( this . _rndr , type , handler , this . _control . _elm ) ,
152
126
deregisterInteractionHandler : ( type , handler ) => this . _control . _registry . unlisten ( type , handler ) ,
@@ -163,19 +137,19 @@ export class MdcSelectDirective implements AfterContentInit, OnDestroy {
163
137
setSelectedIndex ( index : number )
164
138
} = new MDCSelectFoundation ( this . adapter ) ;
165
139
166
- constructor ( private _elm : ElementRef , private _rndr : Renderer2 ) {
140
+ constructor ( private _elm : ElementRef , private _rndr : Renderer2 , private _registry : MdcEventRegistry ) {
167
141
}
168
142
169
143
ngAfterContentInit ( ) {
170
144
if ( ! this . _control || ! this . _label )
171
- throw new Error ( 'mdcSelect requires an embedded mdcSelectControl and mdcSelectLabel ' ) ;
145
+ throw new Error ( 'mdcSelect requires an embedded mdcSelectControl and mdcFloatingLabel ' ) ;
172
146
if ( ! this . _label . _initialized )
173
- throw new Error ( 'mdcSelectLabel not properly initialized' ) ;
147
+ throw new Error ( 'mdcFloatingLabel not properly initialized' ) ;
174
148
// add bottom line:
175
149
this . _bottomLineElm = this . _rndr . createElement ( 'div' ) ;
176
- this . _rndr . addClass ( this . _bottomLineElm , CLASS_SELECT_LINE ) ;
150
+ this . _rndr . addClass ( this . _bottomLineElm , CLASS_LINE_RIPPLE ) ;
177
151
this . _rndr . appendChild ( this . _elm . nativeElement , this . _bottomLineElm ) ;
178
- this . _bottomLineFoundation . init ( ) ;
152
+ this . _lineRippleFoundation . init ( ) ;
179
153
this . foundation . init ( ) ;
180
154
this . _initialized = true ;
181
155
@@ -184,7 +158,7 @@ export class MdcSelectDirective implements AfterContentInit, OnDestroy {
184
158
}
185
159
186
160
ngOnDestroy ( ) {
187
- this . _bottomLineFoundation . destroy ( ) ;
161
+ this . _lineRippleFoundation . destroy ( ) ;
188
162
this . foundation . destroy ( ) ;
189
163
this . _control . _onChange = ( value ) => { } ;
190
164
}
0 commit comments