adapter.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @license
  3. * Copyright 2018 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. */
  23. import { Corner } from '@material/menu-surface/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. */
  31. export interface MDCSelectAdapter {
  32. /**
  33. * Adds class to select anchor element.
  34. */
  35. addClass(className: string): void;
  36. /**
  37. * Removes a class from the select anchor element.
  38. */
  39. removeClass(className: string): void;
  40. /**
  41. * Returns true if the select anchor element contains the given class name.
  42. */
  43. hasClass(className: string): boolean;
  44. /**
  45. * Activates the bottom line, showing a focused state.
  46. */
  47. activateBottomLine(): void;
  48. /**
  49. * Deactivates the bottom line.
  50. */
  51. deactivateBottomLine(): void;
  52. /**
  53. * Returns true if label exists, false if it doesn't.
  54. */
  55. hasLabel(): boolean;
  56. /**
  57. * Floats label determined based off of the shouldFloat argument.
  58. */
  59. floatLabel(shouldFloat: boolean): void;
  60. /**
  61. * Returns width of label in pixels, if the label exists.
  62. */
  63. getLabelWidth(): number;
  64. /**
  65. * Styles the label as required, if the label exists.
  66. */
  67. setLabelRequired(isRequired: boolean): void;
  68. /**
  69. * Returns true if outline element exists, false if it doesn't.
  70. */
  71. hasOutline(): boolean;
  72. /**
  73. * Only implement if outline element exists.
  74. */
  75. notchOutline(labelWidth: number): void;
  76. /**
  77. * Closes notch in outline element, if the outline exists.
  78. */
  79. closeOutline(): void;
  80. /**
  81. * Sets the line ripple transform origin center.
  82. */
  83. setRippleCenter(normalizedX: number): void;
  84. /**
  85. * Emits a change event when an element is selected.
  86. */
  87. notifyChange(value: string): void;
  88. /**
  89. * Sets the text content of the selectedText element to the given string.
  90. */
  91. setSelectedText(text: string): void;
  92. /**
  93. * Returns whether the select anchor is focused.
  94. */
  95. isSelectAnchorFocused(): boolean;
  96. /**
  97. * Gets the given attribute on the select anchor element.
  98. */
  99. getSelectAnchorAttr(attr: string): string | null;
  100. /**
  101. * Sets the given attribute on the select anchor element.
  102. */
  103. setSelectAnchorAttr(attr: string, value: string): void;
  104. /**
  105. * Removes the given attribute on the select anchor element.
  106. */
  107. removeSelectAnchorAttr(attr: string): void;
  108. /**
  109. * Adds class to the menu element.
  110. */
  111. addMenuClass(className: string): void;
  112. /**
  113. * Removes a class from the menu element.
  114. */
  115. removeMenuClass(className: string): void;
  116. /**
  117. * Opens the menu.
  118. */
  119. openMenu(): void;
  120. /**
  121. * Closes the menu.
  122. */
  123. closeMenu(): void;
  124. /**
  125. * Returns the select anchor element.
  126. */
  127. getAnchorElement(): Element | null;
  128. /**
  129. * Sets the menu anchor element.
  130. */
  131. setMenuAnchorElement(anchorEl: Element): void;
  132. /**
  133. * Sets the menu anchor corner.
  134. */
  135. setMenuAnchorCorner(anchorCorner: Corner): void;
  136. /**
  137. * Sets whether the menu should wrap focus.
  138. */
  139. setMenuWrapFocus(wrapFocus: boolean): void;
  140. /**
  141. * Focuses the menu item element at the given index.
  142. */
  143. focusMenuItemAtIndex(index: number): void;
  144. /**
  145. * Returns the number of menu items.
  146. */
  147. getMenuItemCount(): number;
  148. /**
  149. * Returns an array representing the VALUE_ATTR attributes of each menu item.
  150. */
  151. getMenuItemValues(): string[];
  152. /**
  153. * Gets the text content of the menu item element at the given index.
  154. */
  155. getMenuItemTextAtIndex(index: number): string;
  156. /**
  157. * Returns the selected index.
  158. */
  159. getSelectedIndex(): number;
  160. /**
  161. * Sets the selected index in the menu.
  162. */
  163. setSelectedIndex(index: number): void;
  164. /**
  165. * Returns whether typeahead is in progress in the menu.
  166. */
  167. isTypeaheadInProgress(): boolean;
  168. /**
  169. * Adds a character to the list typeahead buffer and returns index of the
  170. * next item in the list matching the buffer.
  171. */
  172. typeaheadMatchItem(nextChar: string, startingIndex: number): number;
  173. }