All files / coral-component-table/src/scripts TableHeaderCell.js

100% Statements 24/24
100% Branches 4/4
100% Functions 8/8
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                          2x                   2x 2x   2x           564x   564x   564x       564x   564x         564x                 2x         647x             560x   560x   560x   560x   540x 528x         560x                     3559x  
/**
 * Copyright 2019 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
 
import {BaseComponent} from '../../../coral-base-component';
import {Decorator} from '../../../coral-decorator';
 
const CLASSNAME = '_coral-Table-headerCell';
 
/**
 @class Coral.Table.HeaderCell
 @classdesc A Table header cell component
 @htmltag coral-table-headercell
 @htmlbasetag th
 @extends {HTMLTableCellElement}
 @extends {BaseComponent}
 */
const TableHeaderCell = Decorator(class extends BaseComponent(HTMLTableCellElement) {
  /** @ignore */
  constructor() {
    super();
 
    // Templates
    this._elements = {
      content: this.querySelector('coral-table-headercell-content') || document.createElement('coral-table-headercell-content')
    };
 
    // Watch for content changes in sticky header cell
    this._stickyCellObserver = new MutationObserver(this._handleMutations.bind(this));
    this._stickyCellObserver.observe(this._elements.content, {
      childList: true,
      subtree: true
    });
  }
 
  /**
   The header cell's content.
 
   @type {TableHeaderCellContent}
   @contentzone
   */
  get content() {
    return this._getContentZone(this._elements.content);
  }
 
  set content(value) {
    this._setContentZone('content', value, {
      handle: 'content',
      tagName: 'coral-table-headercell-content',
      insert: function (content) {
        this.appendChild(content);
      }
    });
  }
 
  /** @private */
  _handleMutations() {
    this.trigger('coral-table-headercell:_contentchanged');
  }
 
  get _contentZones() {
    return {'coral-table-headercell-content': 'content'};
  }
 
  /** @ignore */
  render() {
    super.render();
 
    this.classList.add(CLASSNAME);
 
    // Fetch or create the content zone element
    const content = this._elements.content;
 
    if (!content.parentNode) {
      // Move component children into the content
      while (this.firstChild) {
        content.appendChild(this.firstChild);
      }
    }
 
    // Assign the content zone so the insert function will be called
    this.content = content;
  }
 
  /**
   Triggered when the {@link TableHeaderCell} content changed.
 
   @typedef {CustomEvent} coral-table-headercell:_contentchanged
 
   @private
   */
});
 
export default TableHeaderCell;