foundation.d.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @license
  3. * Copyright 2020 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 { MDCChipActionType } from '../action/constants';
  25. import { MDCChipSetAdapter } from './adapter';
  26. import { ChipAnimationEvent, ChipInteractionEvent, ChipNavigationEvent } from './types';
  27. /**
  28. * MDCChipSetFoundation provides a foundation for all chips.
  29. */
  30. export declare class MDCChipSetFoundation extends MDCFoundation<MDCChipSetAdapter> {
  31. static get defaultAdapter(): MDCChipSetAdapter;
  32. constructor(adapter?: Partial<MDCChipSetAdapter>);
  33. handleChipAnimation({ detail }: ChipAnimationEvent): void;
  34. handleChipInteraction({ detail }: ChipInteractionEvent): void;
  35. handleChipNavigation({ detail }: ChipNavigationEvent): void;
  36. /** Returns the unique selected indexes of the chips. */
  37. getSelectedChipIndexes(): ReadonlySet<number>;
  38. /** Sets the selected state of the chip at the given index and action. */
  39. setChipSelected(index: number, action: MDCChipActionType, isSelected: boolean): void;
  40. /** Returns the selected state of the chip at the given index and action. */
  41. isChipSelected(index: number, action: MDCChipActionType): boolean;
  42. /** Removes the chip at the given index. */
  43. removeChip(index: number): void;
  44. addChip(index: number): void;
  45. /**
  46. * Increments to find the first focusable chip.
  47. */
  48. private focusNextChipFrom;
  49. /**
  50. * Decrements to find the first focusable chip. Takes an optional target
  51. * action that can be used to focus the first matching focusable action.
  52. */
  53. private focusPrevChipFrom;
  54. /** Returns the appropriate focusable action, or null if none exist. */
  55. private getFocusableAction;
  56. /**
  57. * Returs the first focusable action, regardless of type, or null if no
  58. * focusable actions exist.
  59. */
  60. private getFirstFocusableAction;
  61. /**
  62. * If the actions contain a focusable action that matches the target action,
  63. * return that. Otherwise, return the first focusable action, or null if no
  64. * focusable action exists.
  65. */
  66. private getMatchingFocusableAction;
  67. private focusChip;
  68. private supportsMultiSelect;
  69. private setSelection;
  70. private removeAfterAnimation;
  71. /**
  72. * Find the first focusable action by moving bidirectionally horizontally
  73. * from the start index.
  74. *
  75. * Given chip set [A, B, C, D, E, F, G]...
  76. * Let's say we remove chip "F". We don't know where the nearest focusable
  77. * action is since any of them could be disabled. The nearest focusable
  78. * action could be E, it could be G, it could even be A. To find it, we
  79. * start from the source index (5 for "F" in this case) and move out
  80. * horizontally, checking each chip at each index.
  81. *
  82. */
  83. private focusNearestFocusableAction;
  84. private getNearestFocusableAction;
  85. }
  86. export default MDCChipSetFoundation;