Enhancements for better wrapping of Status Area icons

- WIP, but is working!
- TODOs:
  - Make sure this is a good way to do things.
  - Cleanup code.
  - Tests.
This commit is contained in:
Charles Hacskaylo 2024-09-18 23:37:57 -07:00 committed by David Tsay
parent f976dbb6a7
commit 7bb625167a
3 changed files with 65 additions and 15 deletions

View File

@ -33,15 +33,20 @@
: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--indicators-single-line': !indicatorsMultiline 'l-shell__head--indicators-single-line': !indicatorsMultiline,
'--indicators-overflowing': indicatorsOverflowing
}" }"
> >
<CreateButton class="l-shell__create-button" /> <CreateButton class="l-shell__create-button" />
<GrandSearch ref="grand-search" /> <GrandSearch ref="grand-search" />
<StatusIndicators /> <StatusIndicators
:listen-for-overflow="!indicatorsMultiline"
:content-updated="headExpanded || indicatorsMultiline"
@indicators-overflowing="indicatorsOverflowUpdate"
/>
<button <button
class="l-shell__head__button c-icon-button" class="l-shell__head__button"
:class="indicatorsMultiline ? 'icon-singleline' : 'icon-multiline'" :class="[indicatorsMultilineCssClass, indicatorsOverflowingCssClass]"
:aria-label="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`" :aria-label="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`"
:title="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`" :title="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`"
@click="toggleIndicatorsMultiline" @click="toggleIndicatorsMultiline"
@ -221,6 +226,7 @@ export default {
triggerReset: false, triggerReset: false,
headExpanded, headExpanded,
indicatorsMultiline, indicatorsMultiline,
indicatorsOverflowing: false,
isResizing: false, isResizing: false,
disableClearButton: false disableClearButton: false
}; };
@ -231,6 +237,12 @@ export default {
}, },
resizingClass() { resizingClass() {
return this.isResizing ? 'l-shell__resizing' : ''; return this.isResizing ? 'l-shell__resizing' : '';
},
indicatorsMultilineCssClass() {
return this.indicatorsMultiline ? 'icon-singleline' : 'icon-multiline';
},
indicatorsOverflowingCssClass() {
return this.indicatorsOverflowing ? 'c-button c-button--major' : 'c-icon-button';
} }
}, },
mounted() { mounted() {
@ -335,6 +347,10 @@ export default {
}, },
setClearButtonDisabled(isDisabled) { setClearButtonDisabled(isDisabled) {
this.disableClearButton = isDisabled; this.disableClearButton = isDisabled;
},
indicatorsOverflowUpdate(isOverflowing) {
console.log('indicatorsOverflowUpdate', isOverflowing);
this.indicatorsOverflowing = isOverflowing;
} }
} }
}; };

View File

@ -276,6 +276,10 @@
margin-left: auto; // Mimics justify-content: flex-end when in single line mode. margin-left: auto; // Mimics justify-content: flex-end when in single line mode.
} }
} }
&.--is-overflowing {
background: rgba(deeppink, 0.1);
}
} }
/******************************* MAIN AREA */ /******************************* MAIN AREA */

View File

@ -29,12 +29,26 @@
<script> <script>
import { shallowRef } from 'vue'; import { shallowRef } from 'vue';
export default { export default {
inject: ['openmct'], inject: ['openmct'],
props: {
contentUpdated: {
type: String,
required: true
},
listenForOverflow: {
type: Boolean,
required: false,
default() {
return false;
}
}
},
emits: ['indicators-overflowing'],
data() { data() {
return { return {
indicators: this.openmct.indicators.getIndicatorObjectsByPriority().map(shallowRef), indicators: this.openmct.indicators.getIndicatorObjectsByPriority().map(shallowRef)
indicatorsOverflowing: false
}; };
}, },
computed: { computed: {
@ -46,13 +60,34 @@ 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);
} }
}, },
watch: {
contentUpdated() {
// console.log('content updated');
// this.checkOverflow();
}
},
mounted() { mounted() {
this.checkOverflow(); if (this.listenForOverflow) {
window.addEventListener('resize', this.checkOverflow); window.addEventListener('load', 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); if (this.listenForOverflow) {
window.removeEventListener('load', this.checkOverflow);
window.removeEventListener('resize', this.checkOverflow);
}
},
updated() {
// console.log('updated');
if (this.listenForOverflow) {
window.addEventListener('resize', this.checkOverflow);
this.checkOverflow();
} else {
window.removeEventListener('resize', this.checkOverflow);
this.checkOverflow();
}
}, },
created() { created() {
this.openmct.indicators.on('addIndicator', this.addIndicator); this.openmct.indicators.on('addIndicator', this.addIndicator);
@ -63,12 +98,7 @@ export default {
}, },
checkOverflow() { checkOverflow() {
const element = this.$refs.indicators; const element = this.$refs.indicators;
const sizes = { this.$emit('indicators-overflowing', element.scrollWidth > element.clientWidth);
spaceNeeded: element.scrollWidth,
spaceAvail: element.clientWidth
};
this.indicatorsOverflowing = sizes.spaceNeeded > sizes.spaceAvail;
console.log('checkOverflow', this.indicatorsOverflowing, sizes.spaceNeeded, sizes.spaceAvail);
} }
} }
}; };