UNPKG

4.91 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23import { EventSource } from './constants';
24/**
25 * Defines the shape of the adapter expected by the foundation.
26 * Implement this adapter for your framework of choice to delegate updates to
27 * the component in your framework of choice. See architecture documentation
28 * for more details.
29 * https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
30 */
31export interface MDCChipAdapter {
32 /**
33 * Adds a class to the root element.
34 */
35 addClass(className: string): void;
36 /**
37 * Removes a class from the root element.
38 */
39 removeClass(className: string): void;
40 /**
41 * @return true if the root element contains the given class.
42 */
43 hasClass(className: string): boolean;
44 /**
45 * Adds a class to the leading icon element.
46 */
47 addClassToLeadingIcon(className: string): void;
48 /**
49 * Removes a class from the leading icon element.
50 */
51 removeClassFromLeadingIcon(className: string): void;
52 /**
53 * @return true if target has className, false otherwise.
54 */
55 eventTargetHasClass(target: EventTarget | null, className: string): boolean;
56 /**
57 * @return the attribute string value if present, otherwise null
58 */
59 getAttribute(attr: string): string | null;
60 /**
61 * Emits a custom "MDCChip:interaction" event denoting the chip has been
62 * interacted with (typically on click or keydown).
63 */
64 notifyInteraction(): void;
65 /**
66 * Emits a custom "MDCChip:selection" event denoting the chip has been selected or deselected.
67 */
68 notifySelection(selected: boolean, chipSetShouldIgnore: boolean): void;
69 /**
70 * Emits a custom "MDCChip:trailingIconInteraction" event denoting the trailing icon has been
71 * interacted with (typically on click or keydown).
72 */
73 notifyTrailingIconInteraction(): void;
74 /**
75 * Emits a custom event "MDCChip:removal" denoting the chip will be removed.
76 */
77 notifyRemoval(removedAnnouncement: string | null): void;
78 /**
79 * Emits a custom event "MDCChip:navigation" denoting a focus navigation event.
80 */
81 notifyNavigation(key: string, source: EventSource): void;
82 /**
83 * Emits when editing starts.
84 */
85 notifyEditStart(): void;
86 /**
87 * Emits when editing finishes.
88 */
89 notifyEditFinish(): void;
90 /**
91 * @return The computed property value of the given style property on the root element.
92 */
93 getComputedStyleValue(propertyName: string): string;
94 /**
95 * Sets the property value of the given style property on the root element.
96 */
97 setStyleProperty(propertyName: string, value: string): void;
98 /**
99 * @return Whether the chip has a leading icon.
100 */
101 hasLeadingIcon(): boolean;
102 /**
103 * @return The bounding client rect of the root element.
104 */
105 getRootBoundingClientRect(): DOMRect;
106 /**
107 * @return The bounding client rect of the checkmark element or null if it doesn't exist.
108 */
109 getCheckmarkBoundingClientRect(): DOMRect | null;
110 /**
111 * Sets the value of the attribute on the primary action content.
112 */
113 setPrimaryActionAttr(attr: string, value: string): void;
114 /**
115 * Gives focus to the primary action.
116 */
117 focusPrimaryAction(): void;
118 /**
119 * Sets focus to the trailing action.
120 */
121 focusTrailingAction(): void;
122 /**
123 * Removes focus from the trailing action.
124 */
125 removeTrailingActionFocus(): void;
126 /**
127 * Returns true if the trailing action is navigable.
128 * Should return the value of MDCChipTrailingAction#isNavigable() or false.
129 */
130 isTrailingActionNavigable(): boolean;
131 /**
132 * @return true if the text direction is right-to-left.
133 */
134 isRTL(): boolean;
135}