UNPKG

19.6 kBTypeScriptView Raw
1// Generated by dts-bundle v0.7.3
2// Dependencies for this module:
3// ../../@material/menu-surface/constants
4// ../../@material/base/component
5// ../../@material/list/component
6// ../../@material/list/types
7// ../../@material/menu-surface/component
8// ../../@material/menu-surface/types
9// ../../@material/base/foundation
10
11declare module '@material/menu' {
12 /**
13 * @license
14 * Copyright 2019 Google Inc.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a copy
17 * of this software and associated documentation files (the "Software"), to deal
18 * in the Software without restriction, including without limitation the rights
19 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 * copies of the Software, and to permit persons to whom the Software is
21 * furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 * THE SOFTWARE.
33 */
34 export { Corner } from '@material/menu-surface/constants';
35 export * from '@material/menu/adapter';
36 export * from '@material/menu/component';
37 export * from '@material/menu/constants';
38 export * from '@material/menu/foundation';
39 export * from '@material/menu/types';
40}
41
42declare module '@material/menu/adapter' {
43 /**
44 * @license
45 * Copyright 2018 Google Inc.
46 *
47 * Permission is hereby granted, free of charge, to any person obtaining a copy
48 * of this software and associated documentation files (the "Software"), to deal
49 * in the Software without restriction, including without limitation the rights
50 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51 * copies of the Software, and to permit persons to whom the Software is
52 * furnished to do so, subject to the following conditions:
53 *
54 * The above copyright notice and this permission notice shall be included in
55 * all copies or substantial portions of the Software.
56 *
57 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
63 * THE SOFTWARE.
64 */
65 import { MDCMenuItemEventDetail } from '@material/menu/types';
66 /**
67 * Implement this adapter for your framework of choice to delegate updates to
68 * the component in your framework of choice. See architecture documentation
69 * for more details.
70 * https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
71 */
72 export interface MDCMenuAdapter {
73 /**
74 * Adds a class to the element at the index provided.
75 */
76 addClassToElementAtIndex(index: number, className: string): void;
77 /**
78 * Removes a class from the element at the index provided
79 */
80 removeClassFromElementAtIndex(index: number, className: string): void;
81 /**
82 * Adds an attribute, with value, to the element at the index provided.
83 */
84 addAttributeToElementAtIndex(index: number, attr: string, value: string): void;
85 /**
86 * Removes an attribute from an element at the index provided.
87 */
88 removeAttributeFromElementAtIndex(index: number, attr: string): void;
89 /**
90 * @return true if the element contains the className.
91 */
92 elementContainsClass(element: Element, className: string): boolean;
93 /**
94 * Closes the menu-surface.
95 * @param skipRestoreFocus Whether to skip restoring focus to the previously
96 * focused element after the surface has been closed.
97 */
98 closeSurface(skipRestoreFocus?: boolean): void;
99 /**
100 * @return Index of the element in the list or -1 if it is not in the list.
101 */
102 getElementIndex(element: Element): number;
103 /**
104 * Emit an event when a menu item is selected.
105 */
106 notifySelected(evtData: MDCMenuItemEventDetail): void;
107 /** @return Returns the menu item count. */
108 getMenuItemCount(): number;
109 /**
110 * Focuses the menu item at given index.
111 * @param index Index of the menu item that will be focused every time the menu opens.
112 */
113 focusItemAtIndex(index: number): void;
114 /** Focuses the list root element. */
115 focusListRoot(): void;
116 /**
117 * @return Returns selected list item index within the same selection group which is
118 * a sibling of item at given `index`.
119 * @param index Index of the menu item with possible selected sibling.
120 */
121 getSelectedSiblingOfItemAtIndex(index: number): number;
122 /**
123 * @return Returns true if item at specified index is contained within an `.mdc-menu__selection-group` element.
124 * @param index Index of the selectable menu item.
125 */
126 isSelectableItemAtIndex(index: number): boolean;
127 }
128}
129
130declare module '@material/menu/component' {
131 /**
132 * @license
133 * Copyright 2018 Google Inc.
134 *
135 * Permission is hereby granted, free of charge, to any person obtaining a copy
136 * of this software and associated documentation files (the "Software"), to deal
137 * in the Software without restriction, including without limitation the rights
138 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
139 * copies of the Software, and to permit persons to whom the Software is
140 * furnished to do so, subject to the following conditions:
141 *
142 * The above copyright notice and this permission notice shall be included in
143 * all copies or substantial portions of the Software.
144 *
145 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
146 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
147 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
148 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
149 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
150 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
151 * THE SOFTWARE.
152 */
153 import { MDCComponent } from '@material/base/component';
154 import { MDCListFactory } from '@material/list/component';
155 import { MDCListIndex } from '@material/list/types';
156 import { MDCMenuSurfaceFactory } from '@material/menu-surface/component';
157 import { Corner } from '@material/menu-surface/constants';
158 import { MDCMenuDistance } from '@material/menu-surface/types';
159 import { DefaultFocusState } from '@material/menu/constants';
160 import { MDCMenuFoundation } from '@material/menu/foundation';
161 export type MDCMenuFactory = (el: Element, foundation?: MDCMenuFoundation) => MDCMenu;
162 export class MDCMenu extends MDCComponent<MDCMenuFoundation> {
163 static attachTo(root: Element): MDCMenu;
164 initialize(menuSurfaceFactory?: MDCMenuSurfaceFactory, listFactory?: MDCListFactory): void;
165 initialSyncWithDOM(): void;
166 destroy(): void;
167 get open(): boolean;
168 set open(value: boolean);
169 get wrapFocus(): boolean;
170 set wrapFocus(value: boolean);
171 /**
172 * Sets whether the menu has typeahead functionality.
173 * @param value Whether typeahead is enabled.
174 */
175 set hasTypeahead(value: boolean);
176 /**
177 * @return Whether typeahead logic is currently matching some user prefix.
178 */
179 get typeaheadInProgress(): boolean;
180 /**
181 * Given the next desired character from the user, adds it to the typeahead
182 * buffer. Then, attempts to find the next option matching the buffer. Wraps
183 * around if at the end of options.
184 *
185 * @param nextChar The next character to add to the prefix buffer.
186 * @param startingIndex The index from which to start matching. Only relevant
187 * when starting a new match sequence. To start a new match sequence,
188 * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
189 * to clear after a set interval defined in list foundation. Defaults to
190 * the currently focused index.
191 * @return The index of the matched item, or -1 if no match.
192 */
193 typeaheadMatchItem(nextChar: string, startingIndex?: number): number;
194 /**
195 * Layout the underlying list element in the case of any dynamic updates
196 * to its structure.
197 */
198 layout(): void;
199 /**
200 * Return the items within the menu. Note that this only contains the set of elements within
201 * the items container that are proper list items, and not supplemental / presentational DOM
202 * elements.
203 */
204 get items(): Element[];
205 /**
206 * Turns on/off the underlying list's single selection mode. Used mainly
207 * by select menu.
208 *
209 * @param singleSelection Whether to enable single selection mode.
210 */
211 set singleSelection(singleSelection: boolean);
212 /**
213 * Retrieves the selected index. Only applicable to select menus.
214 * @return The selected index, which is a number for single selection and
215 * radio lists, and an array of numbers for checkbox lists.
216 */
217 get selectedIndex(): MDCListIndex;
218 /**
219 * Sets the selected index of the list. Only applicable to select menus.
220 * @param index The selected index, which is a number for single selection and
221 * radio lists, and an array of numbers for checkbox lists.
222 */
223 set selectedIndex(index: MDCListIndex);
224 set quickOpen(quickOpen: boolean);
225 /**
226 * Sets default focus state where the menu should focus every time when menu
227 * is opened. Focuses the list root (`DefaultFocusState.LIST_ROOT`) element by
228 * default.
229 * @param focusState Default focus state.
230 */
231 setDefaultFocusState(focusState: DefaultFocusState): void;
232 /**
233 * @param corner Default anchor corner alignment of top-left menu corner.
234 */
235 setAnchorCorner(corner: Corner): void;
236 setAnchorMargin(margin: Partial<MDCMenuDistance>): void;
237 /**
238 * Sets the list item as the selected row at the specified index.
239 * @param index Index of list item within menu.
240 */
241 setSelectedIndex(index: number): void;
242 /**
243 * Sets the enabled state to isEnabled for the menu item at the given index.
244 * @param index Index of the menu item
245 * @param isEnabled The desired enabled state of the menu item.
246 */
247 setEnabled(index: number, isEnabled: boolean): void;
248 /**
249 * @return The item within the menu at the index specified.
250 */
251 getOptionByIndex(index: number): Element | null;
252 /**
253 * @param index A menu item's index.
254 * @return The primary text within the menu at the index specified.
255 */
256 getPrimaryTextAtIndex(index: number): string;
257 setFixedPosition(isFixed: boolean): void;
258 setIsHoisted(isHoisted: boolean): void;
259 setAbsolutePosition(x: number, y: number): void;
260 /**
261 * Sets the element that the menu-surface is anchored to.
262 */
263 setAnchorElement(element: Element): void;
264 getDefaultFoundation(): MDCMenuFoundation;
265 }
266}
267
268declare module '@material/menu/constants' {
269 /**
270 * @license
271 * Copyright 2018 Google Inc.
272 *
273 * Permission is hereby granted, free of charge, to any person obtaining a copy
274 * of this software and associated documentation files (the "Software"), to deal
275 * in the Software without restriction, including without limitation the rights
276 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
277 * copies of the Software, and to permit persons to whom the Software is
278 * furnished to do so, subject to the following conditions:
279 *
280 * The above copyright notice and this permission notice shall be included in
281 * all copies or substantial portions of the Software.
282 *
283 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
284 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
285 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
286 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
287 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
288 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
289 * THE SOFTWARE.
290 */
291 const cssClasses: {
292 MENU_SELECTED_LIST_ITEM: string;
293 MENU_SELECTION_GROUP: string;
294 ROOT: string;
295 };
296 const strings: {
297 ARIA_CHECKED_ATTR: string;
298 ARIA_DISABLED_ATTR: string;
299 CHECKBOX_SELECTOR: string;
300 LIST_SELECTOR: string;
301 SELECTED_EVENT: string;
302 };
303 const numbers: {
304 FOCUS_ROOT_INDEX: number;
305 };
306 enum DefaultFocusState {
307 NONE = 0,
308 LIST_ROOT = 1,
309 FIRST_ITEM = 2,
310 LAST_ITEM = 3
311 }
312 export { cssClasses, strings, numbers, DefaultFocusState };
313}
314
315declare module '@material/menu/foundation' {
316 /**
317 * @license
318 * Copyright 2018 Google Inc.
319 *
320 * Permission is hereby granted, free of charge, to any person obtaining a copy
321 * of this software and associated documentation files (the "Software"), to deal
322 * in the Software without restriction, including without limitation the rights
323 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
324 * copies of the Software, and to permit persons to whom the Software is
325 * furnished to do so, subject to the following conditions:
326 *
327 * The above copyright notice and this permission notice shall be included in
328 * all copies or substantial portions of the Software.
329 *
330 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
331 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
332 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
333 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
334 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
335 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
336 * THE SOFTWARE.
337 */
338 import { MDCFoundation } from '@material/base/foundation';
339 import { MDCMenuAdapter } from '@material/menu/adapter';
340 import { DefaultFocusState } from '@material/menu/constants';
341 export class MDCMenuFoundation extends MDCFoundation<MDCMenuAdapter> {
342 static get cssClasses(): {
343 MENU_SELECTED_LIST_ITEM: string;
344 MENU_SELECTION_GROUP: string;
345 ROOT: string;
346 };
347 static get strings(): {
348 ARIA_CHECKED_ATTR: string;
349 ARIA_DISABLED_ATTR: string;
350 CHECKBOX_SELECTOR: string;
351 LIST_SELECTOR: string;
352 SELECTED_EVENT: string;
353 };
354 static get numbers(): {
355 FOCUS_ROOT_INDEX: number;
356 };
357 /**
358 * @see {@link MDCMenuAdapter} for typing information on parameters and return types.
359 */
360 static get defaultAdapter(): MDCMenuAdapter;
361 constructor(adapter?: Partial<MDCMenuAdapter>);
362 destroy(): void;
363 handleKeydown(evt: KeyboardEvent): void;
364 handleItemAction(listItem: Element): void;
365 handleMenuSurfaceOpened(): void;
366 /**
367 * Sets default focus state where the menu should focus every time when menu
368 * is opened. Focuses the list root (`DefaultFocusState.LIST_ROOT`) element by
369 * default.
370 */
371 setDefaultFocusState(focusState: DefaultFocusState): void;
372 /**
373 * Selects the list item at `index` within the menu.
374 * @param index Index of list item within the menu.
375 */
376 setSelectedIndex(index: number): void;
377 /**
378 * Sets the enabled state to isEnabled for the menu item at the given index.
379 * @param index Index of the menu item
380 * @param isEnabled The desired enabled state of the menu item.
381 */
382 setEnabled(index: number, isEnabled: boolean): void;
383 }
384 export default MDCMenuFoundation;
385}
386
387declare module '@material/menu/types' {
388 /**
389 * Event properties used by the adapter and foundation.
390 */
391 export interface MDCMenuItemEventDetail {
392 index: number;
393 }
394 /**
395 * Event properties specific to the default component implementation.
396 */
397 export interface MDCMenuItemComponentEventDetail extends MDCMenuItemEventDetail {
398 item: Element;
399 }
400 export interface MDCMenuItemEvent extends Event {
401 readonly detail: MDCMenuItemEventDetail;
402 }
403 export interface MDCMenuItemComponentEvent extends Event {
404 readonly detail: MDCMenuItemComponentEventDetail;
405 }
406}
407