foundation.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 { MDCFoundation } from '@material/base/foundation';
  24. import { MDCMenuSurfaceAdapter } from './adapter';
  25. import { Corner } from './constants';
  26. import { MDCMenuDistance } from './types';
  27. /** MDC Menu Surface Foundation */
  28. export declare class MDCMenuSurfaceFoundation extends MDCFoundation<MDCMenuSurfaceAdapter> {
  29. static get cssClasses(): {
  30. ANCHOR: string;
  31. ANIMATING_CLOSED: string;
  32. ANIMATING_OPEN: string;
  33. FIXED: string;
  34. IS_OPEN_BELOW: string;
  35. OPEN: string;
  36. ROOT: string;
  37. };
  38. static get strings(): {
  39. CLOSED_EVENT: string;
  40. CLOSING_EVENT: string;
  41. OPENED_EVENT: string;
  42. OPENING_EVENT: string;
  43. FOCUSABLE_ELEMENTS: string;
  44. };
  45. static get numbers(): {
  46. TRANSITION_OPEN_DURATION: number;
  47. TRANSITION_CLOSE_DURATION: number;
  48. MARGIN_TO_EDGE: number;
  49. ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO: number;
  50. TOUCH_EVENT_WAIT_MS: number;
  51. };
  52. static get Corner(): typeof Corner;
  53. /**
  54. * @see {@link MDCMenuSurfaceAdapter} for typing information on parameters and return types.
  55. */
  56. static get defaultAdapter(): MDCMenuSurfaceAdapter;
  57. private isSurfaceOpen;
  58. private isQuickOpen;
  59. private isHoistedElement;
  60. private isFixedPosition;
  61. private isHorizontallyCenteredOnViewport;
  62. private maxHeight;
  63. private openBottomBias;
  64. private openAnimationEndTimerId;
  65. private closeAnimationEndTimerId;
  66. private animationRequestId;
  67. private anchorCorner;
  68. private resizeListener;
  69. /**
  70. * Corner of the menu surface to which menu surface is attached to anchor.
  71. *
  72. * Anchor corner --->+----------+
  73. * | ANCHOR |
  74. * +----------+
  75. * Origin corner --->+--------------+
  76. * | |
  77. * | |
  78. * | MENU SURFACE |
  79. * | |
  80. * | |
  81. * +--------------+
  82. */
  83. private originCorner;
  84. private readonly anchorMargin;
  85. private readonly position;
  86. private dimensions;
  87. private measurements;
  88. constructor(adapter?: Partial<MDCMenuSurfaceAdapter>);
  89. init(): void;
  90. destroy(): void;
  91. /**
  92. * @param corner Default anchor corner alignment of top-left menu surface
  93. * corner.
  94. */
  95. setAnchorCorner(corner: Corner): void;
  96. /**
  97. * Flip menu corner horizontally.
  98. */
  99. flipCornerHorizontally(): void;
  100. /**
  101. * @param margin Set of margin values from anchor.
  102. */
  103. setAnchorMargin(margin: Partial<MDCMenuDistance>): void;
  104. /** Used to indicate if the menu-surface is hoisted to the body. */
  105. setIsHoisted(isHoisted: boolean): void;
  106. /**
  107. * Used to set the menu-surface calculations based on a fixed position menu.
  108. */
  109. setFixedPosition(isFixedPosition: boolean): void;
  110. /**
  111. * @return Returns true if menu is in fixed (`position: fixed`) position.
  112. */
  113. isFixed(): boolean;
  114. /** Sets the menu-surface position on the page. */
  115. setAbsolutePosition(x: number, y: number): void;
  116. /** Sets whether menu-surface should be horizontally centered to viewport. */
  117. setIsHorizontallyCenteredOnViewport(isCentered: boolean): void;
  118. setQuickOpen(quickOpen: boolean): void;
  119. /**
  120. * Sets maximum menu-surface height on open.
  121. * @param maxHeight The desired max-height. Set to 0 (default) to
  122. * automatically calculate max height based on available viewport space.
  123. */
  124. setMaxHeight(maxHeight: number): void;
  125. /**
  126. * Set to a positive integer to influence the menu to preferentially open
  127. * below the anchor instead of above.
  128. * @param bias A value of `x` simulates an extra `x` pixels of available space
  129. * below the menu during positioning calculations.
  130. */
  131. setOpenBottomBias(bias: number): void;
  132. isOpen(): boolean;
  133. /**
  134. * Open the menu surface.
  135. */
  136. open(): void;
  137. /**
  138. * Closes the menu surface.
  139. */
  140. close(skipRestoreFocus?: boolean): void;
  141. /** Handle clicks and close if not within menu-surface element. */
  142. handleBodyClick(evt: MouseEvent): void;
  143. /** Handle keys that close the surface. */
  144. handleKeydown(evt: KeyboardEvent): void;
  145. /** Handles resize events on the window. */
  146. private handleResize;
  147. private autoposition;
  148. /**
  149. * @return Measurements used to position menu surface popup.
  150. */
  151. private getAutoLayoutmeasurements;
  152. /**
  153. * Computes the corner of the anchor from which to animate and position the
  154. * menu surface.
  155. *
  156. * Only LEFT or RIGHT bit is used to position the menu surface ignoring RTL
  157. * context. E.g., menu surface will be positioned from right side on TOP_END.
  158. */
  159. private getoriginCorner;
  160. /**
  161. * @param corner Origin corner of the menu surface.
  162. * @return Maximum height of the menu surface, based on available space. 0
  163. * indicates should not be set.
  164. */
  165. private getMenuSurfaceMaxHeight;
  166. /**
  167. * @param corner Origin corner of the menu surface.
  168. * @return Horizontal offset of menu surface origin corner from corresponding
  169. * anchor corner.
  170. */
  171. private getHorizontalOriginOffset;
  172. /**
  173. * @param corner Origin corner of the menu surface.
  174. * @return Vertical offset of menu surface origin corner from corresponding
  175. * anchor corner.
  176. */
  177. private getVerticalOriginOffset;
  178. /**
  179. * Calculates the offsets for positioning the menu-surface when the
  180. * menu-surface has been hoisted to the body.
  181. */
  182. private adjustPositionForHoistedElement;
  183. /**
  184. * The last focused element when the menu surface was opened should regain
  185. * focus, if the user is focused on or within the menu surface when it is
  186. * closed.
  187. */
  188. private maybeRestoreFocus;
  189. private hasBit;
  190. private setBit;
  191. private unsetBit;
  192. /**
  193. * isFinite that doesn't force conversion to number type.
  194. * Equivalent to Number.isFinite in ES2015, which is not supported in IE.
  195. */
  196. private isFinite;
  197. }
  198. export default MDCMenuSurfaceFoundation;