open-consul/ui/packages/consul-ui/app/helpers/dom-position.js
John Cowen eb85b858d9
ui: Improved Discovery Chain resizing (#9360)
* install on-resize modifier

* Rerrange things to use on-resize modifier for positioning
2020-12-11 09:38:33 +00:00

19 lines
523 B
JavaScript

import Helper from '@ember/component/helper';
export default class DomPosition extends Helper {
compute([target], { from }) {
if (typeof target === 'function') {
return entry => {
const $target = entry.target;
let rect = $target.getBoundingClientRect();
if (typeof from !== 'undefined') {
const fromRect = from.getBoundingClientRect();
rect.x = rect.x - fromRect.x;
rect.y = rect.y - fromRect.y;
}
return target(rect);
};
}
}
}