adapter.d.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. */
  23. import { MDCChipActionFocusBehavior, MDCChipActionType } from '../action/constants';
  24. import { MDCChipAttributes, MDCChipCssClasses, MDCChipEvents } from './constants';
  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 MDCChipAdapter {
  33. /** Adds the given class to the root element. */
  34. addClass(className: MDCChipCssClasses): void;
  35. /** Emits the given event with the given detail. */
  36. emitEvent<D extends object>(eventName: MDCChipEvents, eventDetail: D): void;
  37. /** Returns the child actions provided by the chip. */
  38. getActions(): MDCChipActionType[];
  39. /** Returns the value for the given attribute, if it exists. */
  40. getAttribute(attrName: MDCChipAttributes): string | null;
  41. /** Returns the ID of the root element. */
  42. getElementID(): string;
  43. /** Returns the offset width of the root element. */
  44. getOffsetWidth(): number;
  45. /** Returns true if the root element has the given class. */
  46. hasClass(className: MDCChipCssClasses): boolean;
  47. /** Proxies to the MDCChipAction#isSelectable method. */
  48. isActionSelectable(action: MDCChipActionType): boolean;
  49. /** Proxies to the MDCChipAction#isSelected method. */
  50. isActionSelected(action: MDCChipActionType): boolean;
  51. /** Proxies to the MDCChipAction#isFocusable method. */
  52. isActionFocusable(action: MDCChipActionType): boolean;
  53. /** Proxies to the MDCChipAction#isDisabled method. */
  54. isActionDisabled(action: MDCChipActionType): boolean;
  55. /** Returns true if the text direction is right-to-left. */
  56. isRTL(): boolean;
  57. /** Removes the given class from the root element. */
  58. removeClass(className: MDCChipCssClasses): void;
  59. /** Proxies to the MDCChipAction#setDisabled method. */
  60. setActionDisabled(action: MDCChipActionType, isDisabled: boolean): void;
  61. /** Proxies to the MDCChipAction#setFocus method. */
  62. setActionFocus(action: MDCChipActionType, behavior: MDCChipActionFocusBehavior): void;
  63. /** Proxies to the MDCChipAction#setSelected method. */
  64. setActionSelected(action: MDCChipActionType, isSelected: boolean): void;
  65. /** Sets the style property to the given value. */
  66. setStyleProperty(property: string, value: string): void;
  67. }