2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2022-10-06 14:11:39 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import { ref } from 'ember-ref-bucket';
|
|
|
|
import { htmlSafe } from '@ember/template';
|
|
|
|
|
|
|
|
export default class DimensionsProvider extends Component {
|
|
|
|
@ref('element') element;
|
|
|
|
|
|
|
|
@tracked height;
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
const { height, fillRemainingHeightStyle } = this;
|
|
|
|
|
|
|
|
return {
|
|
|
|
height,
|
|
|
|
fillRemainingHeightStyle,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get fillRemainingHeightStyle() {
|
|
|
|
return htmlSafe(`height: ${this.height}px;`);
|
|
|
|
}
|
|
|
|
|
|
|
|
get bottomBoundary() {
|
2022-10-12 10:23:15 +00:00
|
|
|
return document.querySelector(this.args.bottomBoundary) || this.footer;
|
2022-10-06 14:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get footer() {
|
|
|
|
return document.querySelector('footer[role="contentinfo"]');
|
|
|
|
}
|
|
|
|
|
|
|
|
@action measureDimensions(element) {
|
2022-10-12 10:23:15 +00:00
|
|
|
const bb = this.bottomBoundary.getBoundingClientRect();
|
|
|
|
const e = element.getBoundingClientRect();
|
|
|
|
this.height = bb.top + bb.height - e.top;
|
2022-10-06 14:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action handleWindowResize() {
|
|
|
|
const { element } = this;
|
|
|
|
|
|
|
|
this.measureDimensions(element);
|
|
|
|
}
|
|
|
|
}
|