all files / addon/components/polaris-popover/ content.js

88.24% Statements 15/17
75% Branches 6/8
100% Functions 1/1
88.24% Lines 15/17
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                                                                                                                  11×     11× 11×       11× 11×   11×       11× 11× 11×     11× 11×          
import Ember$ from 'jquery';
import Component from '@ember/component';
import { isNone } from '@ember/utils';
import layout from '../../templates/components/polaris-popover/content';
 
export default Component.extend({
  tagName: '',
 
  layout,
 
  /*
   * Public attributes.
   */
  /**
   * Automatically add wrap content in a section
   *
   * @property sectioned
   * @type {boolean}
   * @default false
   */
  sectioned: false,
 
  /**
   * Content wrapper component.
   *
   * @property contentComponent
   * @type {component}
   * @default: null
   */
  contentComponent: null,
 
  /**
   * Simple text for quick popovers.
   *
   * This component can be used in block form,
   * in which case the block content will be used
   * instead of `text`
   *
   * @property text
   * @type {string}
   * @default: null
   */
  text: null,
 
  /**
   * `ember-basic-dropdown`'s generated ID, used to look up
   *
   * @property uniqueId
   * @type {string}
   * @default: null
   */
  uniqueId: null,
 
  /*
   * Lifecycle hooks.
   */
  didRender() {
    this._super(...arguments);
 
    // Position the tip div correctly.
    const uniqueId = this.get('uniqueId');
    Iif (isNone(uniqueId)) {
      return;
    }
 
    const trigger = Ember$(`div.ember-basic-dropdown-trigger[data-ebd-id="${ uniqueId }-trigger"]`)[0];
    const content = Ember$(`div#ember-basic-dropdown-content-${ uniqueId }`)[0];
 
    Iif (isNone(trigger) || isNone(content)) {
      return;
    }
 
    const triggerRect = trigger.getBoundingClientRect();
    const left = (triggerRect.width / 2) + (triggerRect.left - content.getBoundingClientRect().left);
    Ember$('div.Polaris-Popover__Tip', content).css({ left });
 
    // Set the height explicitly so the popover displays on Safari.
    const pane = Ember$('div.Polaris-Popover__Pane', content)[0];
    if (isNone(pane)) {
      return;
    }
    const paneContent = pane.firstElementChild;
    const paneContentRect = paneContent.getBoundingClientRect();
    Ember$('div.Polaris-Popover__Content', content).css({ height: paneContentRect.height });
  },
});