adapter.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 { EventType, SpecificEventListener } from '@material/base/types';
  24. import { MDCMenuDimensions, MDCMenuDistance, MDCMenuPoint } from './types';
  25. /**
  26. * Defines the shape of the adapter expected by the foundation.
  27. * Implement this adapter for your framework of choice to delegate updates to
  28. * the component in your framework of choice. See architecture documentation
  29. * for more details.
  30. * https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
  31. */
  32. export interface MDCMenuSurfaceAdapter {
  33. addClass(className: string): void;
  34. removeClass(className: string): void;
  35. hasClass(className: string): boolean;
  36. hasAnchor(): boolean;
  37. isElementInContainer(el: Element): boolean;
  38. isFocused(): boolean;
  39. isRtl(): boolean;
  40. getInnerDimensions(): MDCMenuDimensions;
  41. getAnchorDimensions(): DOMRect | null;
  42. getViewportDimensions(): MDCMenuDimensions;
  43. getBodyDimensions(): MDCMenuDimensions;
  44. getWindowScroll(): MDCMenuPoint;
  45. setPosition(position: Partial<MDCMenuDistance>): void;
  46. setMaxHeight(height: string): void;
  47. setTransformOrigin(origin: string): void;
  48. getOwnerDocument?(): Document;
  49. /** Saves the element that was focused before the menu surface was opened. */
  50. saveFocus(): void;
  51. /**
  52. * Restores focus to the element that was focused before the menu surface was
  53. * opened.
  54. */
  55. restoreFocus(): void;
  56. /** Emits an event when the menu surface is closed. */
  57. notifyClose(): void;
  58. /** Emits an event when the menu surface is closing. */
  59. notifyClosing(): void;
  60. /** Emits an event when the menu surface is opened. */
  61. notifyOpen(): void;
  62. /** Emits an event when the menu surface is opening. */
  63. notifyOpening(): void;
  64. /** Registers an event listener on the window. */
  65. registerWindowEventHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
  66. /** Deregisters an event listener on the window. */
  67. deregisterWindowEventHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
  68. }