From 0532dcc441a973f8c1e8d085c569cf64c232895f Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Wed, 12 Oct 2022 12:23:15 +0200 Subject: [PATCH] Update dimension provider * simplify implementation * add docs --- ui/packages/consul-ui/.docfy-config.js | 7 +++ .../components/providers/dimension/README.mdx | 43 +++++++++++++++++++ .../components/providers/dimension/index.js | 16 ++----- ui/packages/consul-ui/app/styles/debug.scss | 5 ++- 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 ui/packages/consul-ui/app/components/providers/dimension/README.mdx diff --git a/ui/packages/consul-ui/.docfy-config.js b/ui/packages/consul-ui/.docfy-config.js index bd85d31ff3..bb728972bb 100644 --- a/ui/packages/consul-ui/.docfy-config.js +++ b/ui/packages/consul-ui/.docfy-config.js @@ -96,6 +96,12 @@ module.exports = { urlSchema: 'auto', urlPrefix: 'docs/consul', }, + { + root: path.resolve(__dirname, 'app/components/providers'), + pattern: '**/README.mdx', + urlSchema: 'auto', + urlPrefix: 'docs/providers', + }, { root: `${path.dirname(require.resolve('consul-acls/package.json'))}/app/components`, pattern: '**/README.mdx', @@ -129,6 +135,7 @@ module.exports = { ].concat(user.sources), labels: { consul: 'Consul Components', + providers: 'Provider Components', ...user.labels, }, }; diff --git a/ui/packages/consul-ui/app/components/providers/dimension/README.mdx b/ui/packages/consul-ui/app/components/providers/dimension/README.mdx new file mode 100644 index 0000000000..fa2fcb7066 --- /dev/null +++ b/ui/packages/consul-ui/app/components/providers/dimension/README.mdx @@ -0,0 +1,43 @@ +# Providers::Dimension + +A provider component that helps you to make a container fill the remaining space of the viewport. +Usually, you would **use flexbox** to do so but for scenarios where this isn't possible you +can use this component to make it easy to take up the remaining space. + +```hbs + +
+ Fill remaining space +
+
+``` + +By default, this component will take up the remaining viewport space by taking the +top of itself as the top-boundary and the `footer[role="contentinfo"]` as the +bottom-boundary. In terms of Consul-UI this means _take up the entire space but +stop at the footer that holds the consul version info at the bottom of the screen_. + +You can pass a different `bottomBoundary` if need be: + +```hbs preview-template +
+
+
+ Boundary +
+
+
+ +
+ We could use flexbox here instead +
+
+
+
+``` diff --git a/ui/packages/consul-ui/app/components/providers/dimension/index.js b/ui/packages/consul-ui/app/components/providers/dimension/index.js index ebf47545d3..804c76e48f 100644 --- a/ui/packages/consul-ui/app/components/providers/dimension/index.js +++ b/ui/packages/consul-ui/app/components/providers/dimension/index.js @@ -6,7 +6,6 @@ import { ref } from 'ember-ref-bucket'; import { htmlSafe } from '@ember/template'; export default class DimensionsProvider extends Component { - @service dom; @ref('element') element; @tracked height; @@ -25,24 +24,17 @@ export default class DimensionsProvider extends Component { } get bottomBoundary() { - return this.args.bottomBoundary || this.footer; + return document.querySelector(this.args.bottomBoundary) || this.footer; } get footer() { return document.querySelector('footer[role="contentinfo"]'); } - get viewport() { - return this.dom.viewport(); - } - @action measureDimensions(element) { - const { viewport, bottomBoundary } = this; - - const height = - viewport.innerHeight - (element.getBoundingClientRect().top + bottomBoundary.clientHeight); - - this.height = height; + const bb = this.bottomBoundary.getBoundingClientRect(); + const e = element.getBoundingClientRect(); + this.height = bb.top + bb.height - e.top; } @action handleWindowResize() { diff --git a/ui/packages/consul-ui/app/styles/debug.scss b/ui/packages/consul-ui/app/styles/debug.scss index 66cecc7ed3..04e673a5b2 100644 --- a/ui/packages/consul-ui/app/styles/debug.scss +++ b/ui/packages/consul-ui/app/styles/debug.scss @@ -119,7 +119,8 @@ html:not(.with-data-source) .data-source-debug { /* hi */ z-index: 100000; } -html.with-href-to [href^='console://']::before { +html.with-href-to [href^='console://']::before +{ @extend %p3; @extend %debug-box; content: attr(href); @@ -155,6 +156,7 @@ html.with-route-announcer .route-title { margin-bottom: 100px; padding-top: 0 !important; } + li.provider-components a::before, li.consul-components a::before, li.components a::before { @extend %with-logo-glimmer-color-icon, %as-pseudo; @@ -164,6 +166,7 @@ html.with-route-announcer .route-title { li.components.css-component a::before { @extend %with-logo-glimmer-color-icon, %as-pseudo; } + li.provider-components.ember-component a::before, li.consul-components.ember-component a::before, li.components.ember-component a::before { @extend %with-logo-ember-circle-color-icon, %as-pseudo;