-
Notifications
You must be signed in to change notification settings - Fork 332
/
paper-tooltip-inner.js
40 lines (37 loc) · 1.47 KB
/
paper-tooltip-inner.js
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
import { bool } from '@ember/object/computed';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { run } from '@ember/runloop';
import { htmlSafe } from '@ember/string';
import layout from '../templates/components/paper-tooltip-inner';
import TransitionMixin, { nextTick } from 'ember-css-transitions/mixins/transition-mixin';
import calculateTooltipPosition from 'ember-paper/utils/calculate-tooltip-position';
export default Component.extend(TransitionMixin, {
layout,
tagName: 'md-tooltip',
attributeBindings: ['style'],
classNames: ['md-tooltip', 'md-panel'],
classNameBindings: ['positionClass'],
// eslint-disable-next-line ember/avoid-leaking-state-in-ember-objects
transitionClassNameBindings: ['show:md-show', 'hide:md-hide'],
show: bool('style'),
positionClass: computed('position', function() {
return `md-origin-${this.get('position')}`;
}),
didInsertElement() {
this._super(...arguments);
run.schedule('afterRender', () => {
if (!this.isDestroyed) {
let anchorElement = this.get('anchorElement');
let pos = calculateTooltipPosition(this.element, anchorElement, this.get('position'));
this.set('style', htmlSafe(`top: ${pos.top}px; left: ${pos.left}px`));
this.set('hide', true);
nextTick().then(nextTick).then(nextTick).then(nextTick).then(() => {
if (!this.isDestroyed) {
this.set('hide', false);
}
});
}
});
}
});