forked from material-components/material-components-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.js
208 lines (182 loc) · 6.02 KB
/
adapter.js
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* @license
* Copyright 2017 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* eslint-disable no-unused-vars */
import MDCTextFieldHelperTextFoundation from './helper-text/foundation';
/* eslint-disable no-unused-vars */
import MDCTextFieldCharacterCounterFoundation from './character-counter/foundation';
import MDCTextFieldIconFoundation from './icon/foundation';
/* eslint no-unused-vars: [2, {"args": "none"}] */
/**
* @typedef {{
* value: string,
* disabled: boolean,
* badInput: boolean,
* validity: {
* badInput: boolean,
* valid: boolean,
* },
* }}
*/
let NativeInputType;
/**
* @typedef {{
* helperText: (!MDCTextFieldHelperTextFoundation|undefined),
* characterCounter: (!MDCTextFieldCharacterCounterFoundation|undefined),
* leadingIcon: (!MDCTextFieldIconFoundation|undefined),
* trailingIcon: (!MDCTextFieldIconFoundation|undefined),
* }}
*/
let FoundationMapType;
/**
* Adapter for MDC Text Field.
*
* Defines the shape of the adapter expected by the foundation. Implement this
* adapter to integrate the Text Field into your framework. See
* https://github.com/material-components/material-components-web/blob/master/docs/authoring-components.md
* for more information.
*
* @record
*/
class MDCTextFieldAdapter {
/**
* Adds a class to the root Element.
* @param {string} className
*/
addClass(className) {}
/**
* Removes a class from the root Element.
* @param {string} className
*/
removeClass(className) {}
/**
* Returns true if the root element contains the given class name.
* @param {string} className
* @return {boolean}
*/
hasClass(className) {}
/**
* Registers an event handler on the root element for a given event.
* @param {string} type
* @param {function(!Event): undefined} handler
*/
registerTextFieldInteractionHandler(type, handler) {}
/**
* Deregisters an event handler on the root element for a given event.
* @param {string} type
* @param {function(!Event): undefined} handler
*/
deregisterTextFieldInteractionHandler(type, handler) {}
/**
* Registers an event listener on the native input element for a given event.
* @param {string} evtType
* @param {function(!Event): undefined} handler
*/
registerInputInteractionHandler(evtType, handler) {}
/**
* Deregisters an event listener on the native input element for a given event.
* @param {string} evtType
* @param {function(!Event): undefined} handler
*/
deregisterInputInteractionHandler(evtType, handler) {}
/**
* Registers a validation attribute change listener on the input element.
* Handler accepts list of attribute names.
* @param {function(!Array<string>): undefined} handler
* @return {!MutationObserver}
*/
registerValidationAttributeChangeHandler(handler) {}
/**
* Disconnects a validation attribute observer on the input element.
* @param {!MutationObserver} observer
*/
deregisterValidationAttributeChangeHandler(observer) {}
/**
* Returns an object representing the native text input element, with a
* similar API shape. The object returned should include the value, disabled
* and badInput properties, as well as the checkValidity() function. We never
* alter the value within our code, however we do update the disabled
* property, so if you choose to duck-type the return value for this method
* in your implementation it's important to keep this in mind. Also note that
* this method can return null, which the foundation will handle gracefully.
* @return {?Element|?NativeInputType}
*/
getNativeInput() {}
/**
* Returns true if the textfield is focused.
* We achieve this via `document.activeElement === this.root_`.
* @return {boolean}
*/
isFocused() {}
/**
* Activates the line ripple.
*/
activateLineRipple() {}
/**
* Deactivates the line ripple.
*/
deactivateLineRipple() {}
/**
* Sets the transform origin of the line ripple.
* @param {number} normalizedX
*/
setLineRippleTransformOrigin(normalizedX) {}
/**
* Only implement if label exists.
* Shakes label if shouldShake is true.
* @param {boolean} shouldShake
*/
shakeLabel(shouldShake) {}
/**
* Only implement if label exists.
* Floats the label above the input element if shouldFloat is true.
* @param {boolean} shouldFloat
*/
floatLabel(shouldFloat) {}
/**
* Returns true if label element exists, false if it doesn't.
* @return {boolean}
*/
hasLabel() {}
/**
* Only implement if label exists.
* Returns width of label in pixels.
* @return {number}
*/
getLabelWidth() {}
/**
* Returns true if outline element exists, false if it doesn't.
* @return {boolean}
*/
hasOutline() {}
/**
* Only implement if outline element exists.
* @param {number} labelWidth
*/
notchOutline(labelWidth) {}
/**
* Only implement if outline element exists.
* Closes notch in outline element.
*/
closeOutline() {}
}
export {MDCTextFieldAdapter, NativeInputType, FoundationMapType};