ExamplesPlaygroundReference Source

coral-spectrum/coral-component-list/src/scripts/AnchorList.js

  1. /**
  2. * Copyright 2019 Adobe. All rights reserved.
  3. * This file is licensed to you under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License. You may obtain a copy
  5. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software distributed under
  8. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
  9. * OF ANY KIND, either express or implied. See the License for the specific language
  10. * governing permissions and limitations under the License.
  11. */
  12.  
  13. import {commons} from '../../../coral-utils';
  14. import {BaseComponent} from '../../../coral-base-component';
  15. import {BaseList} from '../../../coral-base-list';
  16. import {Decorator} from '../../../coral-decorator';
  17.  
  18. const CLASSNAME = '_coral-AnchorList';
  19.  
  20. /**
  21. @class Coral.AnchorList
  22. @classdesc An AnchorList component that supports multi-line text, icons, and text wrapping with ellipsis.
  23. @htmltag coral-anchorlist
  24. @extends {HTMLElement}
  25. @extends {BaseComponent}
  26. @extends {BaseList}
  27. */
  28. const AnchorList = Decorator(class extends BaseList(BaseComponent(HTMLElement)) {
  29. /** @ignore */
  30. constructor() {
  31. super();
  32.  
  33. // Events
  34. this._delegateEvents(commons.extend(this._events, {
  35. 'click [coral-list-item]': '_onItemClick'
  36. }));
  37. }
  38.  
  39. /** @private */
  40. get _itemTagName() {
  41. // Used for Collection
  42. return 'coral-anchorlist-item';
  43. }
  44.  
  45. /** @private */
  46. get _itemBaseTagName() {
  47. // Used for Collection
  48. return 'a';
  49. }
  50.  
  51. _onItemClick(event) {
  52. this._trackEvent('click', 'coral-anchorlist-item', event, event.matchedTarget);
  53. }
  54.  
  55. /** @ignore */
  56. render() {
  57. super.render();
  58.  
  59. this.classList.add(CLASSNAME);
  60. }
  61. });
  62.  
  63. export default AnchorList;