Enhancements for better wrapping of Status Area icons

- Add code and CSS for toggling single/multiline display of indicators.
- Add code to detect overflow state of indicators.
This commit is contained in:
Charles Hacskaylo 2024-09-18 15:34:51 -07:00
parent b8a933e332
commit f06b629eaa
3 changed files with 39 additions and 20 deletions

View File

@ -33,7 +33,7 @@
:class="{ :class="{
'l-shell__head--expanded': headExpanded, 'l-shell__head--expanded': headExpanded,
'l-shell__head--minify-indicators': !headExpanded, 'l-shell__head--minify-indicators': !headExpanded,
'l-shell__head--can-wrap': headCanWrap 'l-shell__head--indicators-single-line': !indicatorsMultiline
}" }"
> >
<CreateButton class="l-shell__create-button" /> <CreateButton class="l-shell__create-button" />
@ -41,10 +41,10 @@
<StatusIndicators /> <StatusIndicators />
<button <button
class="l-shell__head__button c-icon-button" class="l-shell__head__button c-icon-button"
:class="headCanWrap ? 'icon-multiline' : 'icon-singleline'" :class="indicatorsMultiline ? 'icon-singleline' : 'icon-multiline'"
:aria-label="`Display as ${headCanWrap ? 'multiple lines' : 'single line'}`" :aria-label="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`"
:title="`Display as ${headCanWrap ? 'multiple lines' : 'single line'}`" :title="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`"
@click="toggleHeadWrapping" @click="toggleIndicatorsMultiline"
></button> ></button>
<button <button
class="l-shell__head__collapse-button c-icon-button" class="l-shell__head__collapse-button c-icon-button"
@ -205,10 +205,10 @@ export default {
data: function () { data: function () {
let storedHeadProps = window.localStorage.getItem('openmct-shell-head'); let storedHeadProps = window.localStorage.getItem('openmct-shell-head');
let headExpanded = true; let headExpanded = true;
let headCanWrap = false; let indicatorsMultiline = false;
if (storedHeadProps) { if (storedHeadProps) {
headExpanded = JSON.parse(storedHeadProps).expanded; headExpanded = JSON.parse(storedHeadProps).expanded;
headCanWrap = JSON.parse(storedHeadProps).wrapping; indicatorsMultiline = JSON.parse(storedHeadProps).multiline;
} }
return { return {
@ -220,7 +220,7 @@ export default {
triggerSync: false, triggerSync: false,
triggerReset: false, triggerReset: false,
headExpanded, headExpanded,
headCanWrap, indicatorsMultiline,
isResizing: false, isResizing: false,
disableClearButton: false disableClearButton: false
}; };
@ -278,13 +278,13 @@ export default {
}) })
); );
}, },
toggleHeadWrapping() { toggleIndicatorsMultiline() {
this.headCanWrap = !this.headCanWrap; this.indicatorsMultiline = !this.indicatorsMultiline;
window.localStorage.setItem( window.localStorage.setItem(
'openmct-shell-head', 'openmct-shell-head',
JSON.stringify({ JSON.stringify({
wrapping: this.headCanWrap multiline: this.indicatorsMultiline
}) })
); );
}, },

View File

@ -259,18 +259,22 @@
} }
&__indicators { &__indicators {
// Style as multiline by default
display: flex;
flex-wrap: wrap; flex-wrap: wrap;
font-size: 11px; font-size: 11px;
min-height: 24px;
justify-content: flex-end; justify-content: flex-end;
.l-shell__head--expanded & { .l-shell__head--indicators-single-line & {
} flex-wrap: nowrap;
justify-content: flex-start; // Overflow detection doesn't work with flex-end.
.l-shell__head--can-wrap & { max-height: 24px;
// Force elements to wrap down when width constrained
background: rgba(deeppink, 0.4);
height: 24px;
overflow: hidden; overflow: hidden;
> *:first-child {
margin-left: auto; // Mimics justify-content: flex-end when in single line mode.
}
} }
} }

View File

@ -17,7 +17,7 @@
at runtime from the About dialog for additional information. at runtime from the About dialog for additional information.
--> -->
<template> <template>
<div class="l-shell__head-section l-shell__indicators"> <div ref="indicators" class="l-shell__head-section l-shell__indicators">
<component <component
:is="indicator.value.vueComponent" :is="indicator.value.vueComponent"
v-for="indicator in sortedIndicators" v-for="indicator in sortedIndicators"
@ -33,7 +33,8 @@ export default {
inject: ['openmct'], inject: ['openmct'],
data() { data() {
return { return {
indicators: this.openmct.indicators.getIndicatorObjectsByPriority().map(shallowRef) indicators: this.openmct.indicators.getIndicatorObjectsByPriority().map(shallowRef),
indicatorsOverflowing: false
}; };
}, },
computed: { computed: {
@ -45,8 +46,13 @@ export default {
return [...this.indicators].sort((a, b) => b.value.priority - a.value.priority); return [...this.indicators].sort((a, b) => b.value.priority - a.value.priority);
} }
}, },
mounted() {
this.checkOverflow();
window.addEventListener('resize', this.checkOverflow);
},
beforeUnmount() { beforeUnmount() {
this.openmct.indicators.off('addIndicator', this.addIndicator); this.openmct.indicators.off('addIndicator', this.addIndicator);
window.removeEventListener('resize', this.checkOverflow);
}, },
created() { created() {
this.openmct.indicators.on('addIndicator', this.addIndicator); this.openmct.indicators.on('addIndicator', this.addIndicator);
@ -54,6 +60,15 @@ export default {
methods: { methods: {
addIndicator(indicator) { addIndicator(indicator) {
this.indicators.push(shallowRef(indicator)); this.indicators.push(shallowRef(indicator));
},
checkOverflow() {
const element = this.$refs.indicators;
const sizes = {
spaceNeeded: element.scrollWidth,
spaceAvail: element.clientWidth
};
this.indicatorsOverflowing = sizes.spaceNeeded > sizes.spaceAvail;
console.log('checkOverflow', this.indicatorsOverflowing, sizes.spaceNeeded, sizes.spaceAvail);
} }
} }
}; };