ExamplesPlaygroundReference Source

coral-spectrum/coral-component-table/src/scripts/TableBody.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 {BaseComponent} from '../../../coral-base-component';
  14. import BaseTableSection from './BaseTableSection';
  15. import {getRows} from './TableUtil';
  16. import {Decorator} from '../../../coral-decorator';
  17.  
  18. const CLASSNAME = '_coral-Table-body';
  19.  
  20. /**
  21. @class Coral.Table.Body
  22. @classdesc A Table body component
  23. @htmltag coral-table-body
  24. @htmlbasetag tbody
  25. @extends {HTMLTableSectionElement}
  26. @extends {BaseComponent}
  27. @extends {BaseTableSection}
  28. */
  29. const TableBody = Decorator(class extends BaseTableSection(BaseComponent(HTMLTableSectionElement)) {
  30. /** @ignore */
  31. constructor() {
  32. super();
  33.  
  34. this._toggleObserver(true);
  35. }
  36.  
  37. /** @ignore */
  38. render() {
  39. super.render();
  40.  
  41. this.classList.add(CLASSNAME);
  42.  
  43. if (getRows([this]).length === 0) {
  44. this.trigger('coral-table-body:_empty');
  45. }
  46. }
  47.  
  48. /**
  49. Triggered when the {@link TableBody} content changed.
  50.  
  51. @typedef {CustomEvent} coral-table-body:_contentchanged
  52.  
  53. @private
  54. */
  55.  
  56. /**
  57. Triggered when the {@link TableBody} is initialized without rows.
  58.  
  59. @typedef {CustomEvent} coral-table-body:_empty
  60.  
  61. @private
  62. */
  63. });
  64.  
  65. export default TableBody;