forked from material-components/material-components-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.ts
160 lines (137 loc) · 4.94 KB
/
adapter.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
/**
* @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.
*/
import {EventType, SpecificEventListener} from '@material/base/types';
import {MDCTextFieldNativeInputElement} from './types';
/**
* Defines the shape of the adapter expected by the foundation.
* Implement this adapter for your framework of choice to delegate updates to
* the component in your framework of choice. See architecture documentation
* for more details.
* https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
*/
export interface MDCTextFieldAdapter extends MDCTextFieldRootAdapter,
MDCTextFieldInputAdapter,
MDCTextFieldLabelAdapter,
MDCTextFieldLineRippleAdapter,
MDCTextFieldOutlineAdapter {
}
export interface MDCTextFieldRootAdapter {
/**
* Adds a class to the root Element.
*/
addClass(className: string): void;
/**
* Removes a class from the root Element.
*/
removeClass(className: string): void;
/**
* @return true if the root element contains the given class name.
*/
hasClass(className: string): boolean;
/**
* Registers an event handler on the root element for a given event.
*/
registerTextFieldInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
/**
* Deregisters an event handler on the root element for a given event.
*/
deregisterTextFieldInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
/**
* Registers a validation attribute change listener on the input element.
* Handler accepts list of attribute names.
*/
registerValidationAttributeChangeHandler(handler: (attributeNames: string[]) => void): MutationObserver;
/**
* Disconnects a validation attribute observer on the input element.
*/
deregisterValidationAttributeChangeHandler(observer: MutationObserver): void;
}
export interface MDCTextFieldInputAdapter {
/**
* @return The native `<input>` element, or an object with the same shape.
* Note that this method can return null, which the foundation will handle gracefully.
*/
getNativeInput(): MDCTextFieldNativeInputElement | null;
/**
* @return true if the textfield is focused. We achieve this via `document.activeElement === this.root_`.
*/
isFocused(): boolean;
/**
* Registers an event listener on the native input element for a given event.
*/
registerInputInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
/**
* Deregisters an event listener on the native input element for a given event.
*/
deregisterInputInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
}
export interface MDCTextFieldLabelAdapter {
/**
* Only implement if label exists.
* Shakes label if shouldShake is true.
*/
shakeLabel(shouldShake: boolean): void;
/**
* Only implement if label exists.
* Floats the label above the input element if shouldFloat is true.
*/
floatLabel(shouldFloat: boolean): void;
/**
* @return true if label element exists, false if it doesn't.
*/
hasLabel(): boolean;
/**
* Only implement if label exists.
* @return width of label in pixels.
*/
getLabelWidth(): number;
}
export interface MDCTextFieldLineRippleAdapter {
/**
* Activates the line ripple.
*/
activateLineRipple(): void;
/**
* Deactivates the line ripple.
*/
deactivateLineRipple(): void;
/**
* Sets the transform origin of the line ripple.
*/
setLineRippleTransformOrigin(normalizedX: number): void;
}
export interface MDCTextFieldOutlineAdapter {
/**
* @return true if outline element exists, false if it doesn't.
*/
hasOutline(): boolean;
/**
* Only implement if outline element exists.
*/
notchOutline(labelWidth: number): void;
/**
* Only implement if outline element exists.
* Closes notch in outline element.
*/
closeOutline(): void;
}